Skip to content

Commit fd500e1

Browse files
committed
fix: Visit let-expression components consistently
Previously, the Rhss and Body are a let expression where visited in different orders in different parts of Boogie. They are now visited consistently, always Rhss before Body. Fixes #192
1 parent 124d1ce commit fd500e1

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

Source/Core/AbsyQuant.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1119,11 +1119,16 @@ public override void Emit(TokenTextWriter stream, int contextBindingStrength, bo
11191119
public override void ComputeFreeVariables(Set freeVars) {
11201120
//Contract.Requires(freeVars != null);
11211121

1122+
foreach (var e in Rhss) {
1123+
e.ComputeFreeVariables(freeVars);
1124+
}
11221125
foreach (var v in Dummies) {
11231126
Contract.Assert(v != null);
11241127
Contract.Assert(!freeVars[v]);
11251128
}
1126-
Body.ComputeFreeVariables(freeVars);
1129+
foreach (var v in Dummies) {
1130+
freeVars.AddRange(v.TypedIdent.Type.FreeVariables);
1131+
}
11271132
for (var a = Attributes; a != null; a = a.Next) {
11281133
foreach (var o in a.Params) {
11291134
var e = o as Expr;
@@ -1132,13 +1137,8 @@ public override void ComputeFreeVariables(Set freeVars) {
11321137
}
11331138
}
11341139
}
1135-
foreach (var v in Dummies) {
1136-
freeVars.AddRange(v.TypedIdent.Type.FreeVariables);
1137-
}
1140+
Body.ComputeFreeVariables(freeVars);
11381141
freeVars.RemoveRange(Dummies);
1139-
foreach (var e in Rhss) {
1140-
e.ComputeFreeVariables(freeVars);
1141-
}
11421142
}
11431143
}
11441144
}

Source/Core/MaxHolesLambdaLifter.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ public override Expr VisitLetExpr(LetExpr node) {
131131

132132
replacements.AddRange(bodyTemplate.GetReplacements());
133133
_templates[node] = new TemplateWithBoundVariables(replacements);
134-
}
135-
else {
134+
} else {
136135
var newRhss = from arg in varBodies select ((TemplateNoBoundVariables) _templates[arg]).GetReplacement();
137136
LambdaLiftingTemplate template = new TemplateNoBoundVariables(
138137
new LetExpr(node.tok, node.Dummies, newRhss.ToList(),

Source/Core/StandardVisitor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ public virtual Expr VisitLambdaExpr(LambdaExpr node) {
311311
public virtual Expr VisitLetExpr(LetExpr node) {
312312
Contract.Requires(node != null);
313313
Contract.Ensures(Contract.Result<Expr>() != null);
314-
node.Body = this.VisitExpr(node.Body);
315-
node.Dummies = this.VisitVariableSeq(node.Dummies);
316314
node.Rhss = this.VisitExprSeq(node.Rhss);
315+
node.Dummies = this.VisitVariableSeq(node.Dummies);
316+
node.Body = this.VisitExpr(node.Body);
317317
return node;
318318
}
319319
public virtual Formal VisitFormal(Formal node) {
@@ -878,9 +878,9 @@ public override Expr VisitLambdaExpr(LambdaExpr node) {
878878
return this.VisitBinderExpr(node);
879879
}
880880
public override Expr VisitLetExpr(LetExpr node) {
881-
this.VisitExpr(node.Body);
882-
this.VisitVariableSeq(node.Dummies);
883881
this.VisitExprSeq(node.Rhss);
882+
this.VisitVariableSeq(node.Dummies);
883+
this.VisitExpr(node.Body);
884884
return node;
885885
}
886886
public override Formal VisitFormal(Formal node)

Test/letexpr/git-issue-192.bpl

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %boogie "%s" > "%t"
2+
// RUN: %diff "%s.expect" "%t"
3+
4+
type AAA;
5+
type BBB;
6+
type CCC;
7+
8+
function Apple(AAA, BBB): CCC;
9+
function Banana(int): BBB;
10+
11+
procedure Proc()
12+
{
13+
var m: [AAA]CCC;
14+
m :=
15+
// Once upon a time, the lambda lifting for the following body switched
16+
// the roles of 15 and Banana(700), by traversing the components of let
17+
// expressions in a different order when figuring out holes from when
18+
// replacing the holes with new bound variables of the lambda lifting.
19+
(lambda aaa: AAA ::
20+
(var g := 15;
21+
Apple(aaa, Banana(700))
22+
)
23+
);
24+
}

Test/letexpr/git-issue-192.bpl.expect

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Boogie program verifier finished with 1 verified, 0 errors

0 commit comments

Comments
 (0)