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

Support multi-binding var expressions in Lean backend #983

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 12 additions & 8 deletions Source/Provers/LeanAuto/LeanAutoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,21 @@ public override Expr VisitLambdaExpr(LambdaExpr node)

public override Expr VisitLetExpr(LetExpr node)
{
if (node.Dummies.Count > 1) {
if (node.Dummies.Count != node.Rhss.Count) {
throw new LeanConversionException(node.tok,
"Unsupported: LetExpr with more than one binder");
"Unsupported: LetExpr with differing LHS and RHS counts.");
}

var bindings = node.Dummies.Zip(node.Rhss);
foreach (var (x, e) in bindings) {
WriteText("(let ");
Visit(x.TypedIdent);
WriteText(" := ");
Visit(e);
WriteText("; ");
}
WriteText("(let");
node.Dummies.ForEach(x => Visit(x.TypedIdent));
WriteText(" := ");
node.Rhss.ForEach(e => Visit(e));
WriteText("; ");
Visit(node.Body);
WriteText(")");
bindings.ForEach(b => WriteText(")"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO .ForEach is an anti-pattern, since the IDE and debugger support is worse than when using the language-construct foreach

return node;
}

Expand Down
2 changes: 1 addition & 1 deletion Test/lean-auto/lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package «test» {
}

require auto from git
"https://github.com/leanprover-community/lean-auto"@"0831a6eff8cbb456e90c616bd2f4db51aefea3d0"
"https://github.com/leanprover-community/lean-auto"@"60e546ca7a9d40d508e58847a9d0630406835178"

@[default_target]
lean_lib «ToBuild» {
Expand Down
2 changes: 1 addition & 1 deletion Test/lean-auto/lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.9.0
leanprover/lean4:v4.11.0
10 changes: 10 additions & 0 deletions Test/lean-auto/multi-let.bpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %parallel-boogie "%s" > "%t"
procedure P(x: int, y: int) {
var z: int;
var w: int;

z := (var a, b := x+1, y+1; a);
w := (var a, b := x+1, y+1; b);
assert (z - 1) == x;
assert (w - 1) == y;
}
Loading