Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not flatten matches for C# #5509

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
97d81e2
Add patterns/codeSize test
keyboardDrummer May 29, 2024
e77441a
Update codeSize test
keyboardDrummer May 29, 2024
547317f
Split off statement part from SPCG
keyboardDrummer May 29, 2024
55b4cde
Draft of nested match compiler
keyboardDrummer May 30, 2024
b4bc5cf
Save
keyboardDrummer May 30, 2024
f10aa78
Generated code looks good upon visual inspection
keyboardDrummer May 30, 2024
ee9ae6f
Generated code compiles and runs
keyboardDrummer May 30, 2024
069dddb
Move NestedMatch generation to just C#
keyboardDrummer May 30, 2024
da513a0
Attempt at implementation for expressions
keyboardDrummer May 30, 2024
88536c8
Ran formatter
keyboardDrummer May 30, 2024
f13be6e
Fixes
keyboardDrummer May 30, 2024
a61d607
Update C# code generator zo it also uses custom generation for nested…
keyboardDrummer May 30, 2024
846ad62
Regen GeneratedFromDafny code
keyboardDrummer May 30, 2024
85c1b20
Revert "Regen GeneratedFromDafny code"
keyboardDrummer May 30, 2024
3660a37
Fix gen
keyboardDrummer May 30, 2024
26000a5
Fixes for generics
keyboardDrummer May 30, 2024
2805584
Update generated files
keyboardDrummer May 30, 2024
09f39f8
Merge branch 'master' into noFlattenForCSharp
keyboardDrummer May 30, 2024
82a5d71
Fix bug related to disjoint patterns
keyboardDrummer May 31, 2024
c32be6f
Merge branch 'noFlattenForCSharp' of github.com:keyboardDrummer/dafny…
keyboardDrummer May 31, 2024
861cee7
Merge remote-tracking branch 'origin/master' into noFlattenForCSharp
keyboardDrummer May 31, 2024
1e25d7b
Fix literal pattern bug
keyboardDrummer May 31, 2024
6791e43
Remove DatatypeWrapperEraser.IsErasableDatatypeWrapper check
keyboardDrummer May 31, 2024
eedcf47
Ran formatter
keyboardDrummer May 31, 2024
6f981ab
Fix bug in disjunctive assignments
keyboardDrummer May 31, 2024
0bd8c0d
Merge branch 'master' into noFlattenForCSharp
keyboardDrummer May 31, 2024
903f2bf
Trigger CI
keyboardDrummer May 31, 2024
5d9dc07
Merge branch 'noFlattenForCSharp' of github.com:keyboardDrummer/dafny…
keyboardDrummer May 31, 2024
9477c6f
Fixes
keyboardDrummer Jun 1, 2024
b919fa8
Refactoring
keyboardDrummer Jun 1, 2024
c6de95b
Add force integration tests code
keyboardDrummer Jun 3, 2024
0672492
Merge branch 'master' into noFlattenForCSharp
keyboardDrummer Jun 4, 2024
3c86dd7
Convert if else chains to switch
keyboardDrummer Jun 4, 2024
e45420a
Merge commit 'a748799eef1d7~1' into noFlattenForCSharp
keyboardDrummer Jun 5, 2024
b8de307
Merge commit 'a748799eef1d7' into noFlattenForCSharp
keyboardDrummer Jun 5, 2024
f97bf09
Merge remote-tracking branch 'origin/master' into noFlattenForCSharp
keyboardDrummer Jun 5, 2024
75bb47e
Ran formatter
keyboardDrummer Jun 5, 2024
e1bb707
Refactoring
keyboardDrummer Jun 5, 2024
dbcb4a4
Further refactoring
keyboardDrummer Jun 5, 2024
420a13b
Further refactoring
keyboardDrummer Jun 5, 2024
8950908
Generate from Dafny
keyboardDrummer Jun 5, 2024
41b0de2
Remove codeSize test
keyboardDrummer Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug in disjunctive assignments
  • Loading branch information
keyboardDrummer committed May 31, 2024
commit 6f981ab62c7889039d4c9f8124e8115f3e67f8fa
12 changes: 6 additions & 6 deletions Source/DafnyCore/Backends/CSharp/CsharpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3675,9 +3675,14 @@ private ConcreteSyntaxTree EmitNestedMatchCaseConditions(string sourceName,
}

} else if (pattern is DisjunctivePattern disjunctivePattern) {
string disjunctiveMatch = ProtectedFreshId("disjunctiveMatch");
DeclareLocalVar(disjunctiveMatch, Type.Bool, disjunctivePattern.Tok, Expression.CreateBoolLiteral(disjunctivePattern.Tok, false), false, writer);
foreach (var alternative in disjunctivePattern.Alternatives) {
writer = EmitNestedMatchCaseConditions(sourceName, sourceType, alternative, writer, lastCase);
var alternativeWriter = EmitNestedMatchCaseConditions(sourceName, sourceType, alternative, writer, lastCase);
EmitAssignment(disjunctiveMatch, Type.Bool, True, Type.Bool, alternativeWriter);
}
writer = EmitIf(out var guardWriter, false, writer);
guardWriter.Write(disjunctiveMatch);
} else {
throw new Exception();
}
Expand All @@ -3690,11 +3695,6 @@ private ConcreteSyntaxTree EmitNestedMatchStmtCaseConstructor(string sourceName,
ConcreteSyntaxTree result, bool lastCase) {
var ctor = idPattern.Ctor;

// if (DatatypeWrapperEraser.IsErasableDatatypeWrapper(Options, ctor.EnclosingDatatype, out _)) {
// result = EmitNestedMatchCaseConditions(sourceName, sourceType, idPattern.Arguments[0], result, lastCase);
// return result;
// }

if (!lastCase && ctor.EnclosingDatatype.Ctors.Count != 1) {
result = EmitIf(out var guardWriter, false, result);
EmitConstructorCheck(sourceName, ctor, guardWriter);
Expand Down
102 changes: 68 additions & 34 deletions Source/DafnyCore/GeneratedFromDafny/DCOMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,16 +1865,26 @@ public void GenStmt(DAST._IStatement stmt, Std.Wrappers._IOption<Dafny.ISequence
}
}
if (unmatched59) {
bool disjunctiveMatch9 = false;
if (_source59.is_MapBuilderAdd) {
if (_source59.is_SetBuilderAdd) {
unmatched59 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("add");
}
disjunctiveMatch9 = true;
}
if (_source59.is_SetBuilderAdd) {
disjunctiveMatch9 = true;
}
if (disjunctiveMatch9) {
unmatched59 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("add");
}
}
if (unmatched59) {
unmatched59 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("build");
bool disjunctiveMatch10 = false;
disjunctiveMatch10 = true;
disjunctiveMatch10 = true;
if (disjunctiveMatch10) {
unmatched59 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("build");
}
}
throw new System.Exception("unexpected control point");
}))(_1280_name);
Expand Down Expand Up @@ -2285,29 +2295,43 @@ public void GenExprBinary(DAST._IExpression e, Std.Wrappers._IOption<Dafny.ISequ
_1333_becomesLeftCallsRight = ((System.Func<DAST._IBinOp, bool>)((_source64) => {
bool unmatched64 = true;
if (unmatched64) {
bool disjunctiveMatch11 = false;
if (_source64.is_SetMerge) {
if (_source64.is_SetSubtraction) {
if (_source64.is_SetIntersection) {
if (_source64.is_SetDisjoint) {
if (_source64.is_MapMerge) {
if (_source64.is_MapSubtraction) {
if (_source64.is_MultisetMerge) {
if (_source64.is_MultisetSubtraction) {
if (_source64.is_MultisetIntersection) {
if (_source64.is_MultisetDisjoint) {
if (_source64.is_Concat) {
unmatched64 = false;
return true;
}
}
}
}
}
}
}
}
}
}
disjunctiveMatch11 = true;
}
if (_source64.is_SetSubtraction) {
disjunctiveMatch11 = true;
}
if (_source64.is_SetIntersection) {
disjunctiveMatch11 = true;
}
if (_source64.is_SetDisjoint) {
disjunctiveMatch11 = true;
}
if (_source64.is_MapMerge) {
disjunctiveMatch11 = true;
}
if (_source64.is_MapSubtraction) {
disjunctiveMatch11 = true;
}
if (_source64.is_MultisetMerge) {
disjunctiveMatch11 = true;
}
if (_source64.is_MultisetSubtraction) {
disjunctiveMatch11 = true;
}
if (_source64.is_MultisetIntersection) {
disjunctiveMatch11 = true;
}
if (_source64.is_MultisetDisjoint) {
disjunctiveMatch11 = true;
}
if (_source64.is_Concat) {
disjunctiveMatch11 = true;
}
if (disjunctiveMatch11) {
unmatched64 = false;
return true;
}
}
if (unmatched64) {
Expand Down Expand Up @@ -4516,16 +4540,26 @@ public void GenExpr(DAST._IExpression e, Std.Wrappers._IOption<Dafny.ISequence<D
}
}
if (unmatched75) {
bool disjunctiveMatch12 = false;
if (_source75.is_MapBuilderAdd) {
if (_source75.is_SetBuilderAdd) {
unmatched75 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("add");
}
disjunctiveMatch12 = true;
}
if (_source75.is_SetBuilderAdd) {
disjunctiveMatch12 = true;
}
if (disjunctiveMatch12) {
unmatched75 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("add");
}
}
if (unmatched75) {
unmatched75 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("build");
bool disjunctiveMatch13 = false;
disjunctiveMatch13 = true;
disjunctiveMatch13 = true;
if (disjunctiveMatch13) {
unmatched75 = false;
return Dafny.Sequence<Dafny.Rune>.UnicodeFromString("build");
}
}
throw new System.Exception("unexpected control point");
}))(_1686_name);
Expand Down
Loading
Loading