Skip to content

Commit

Permalink
fix: Visit let-expression components consistently
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RustanLeino committed Feb 13, 2020
1 parent 124d1ce commit fd500e1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
14 changes: 7 additions & 7 deletions Source/Core/AbsyQuant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,16 @@ public override void Emit(TokenTextWriter stream, int contextBindingStrength, bo
public override void ComputeFreeVariables(Set freeVars) {
//Contract.Requires(freeVars != null);

foreach (var e in Rhss) {
e.ComputeFreeVariables(freeVars);
}
foreach (var v in Dummies) {
Contract.Assert(v != null);
Contract.Assert(!freeVars[v]);
}
Body.ComputeFreeVariables(freeVars);
foreach (var v in Dummies) {
freeVars.AddRange(v.TypedIdent.Type.FreeVariables);
}
for (var a = Attributes; a != null; a = a.Next) {
foreach (var o in a.Params) {
var e = o as Expr;
Expand All @@ -1132,13 +1137,8 @@ public override void ComputeFreeVariables(Set freeVars) {
}
}
}
foreach (var v in Dummies) {
freeVars.AddRange(v.TypedIdent.Type.FreeVariables);
}
Body.ComputeFreeVariables(freeVars);
freeVars.RemoveRange(Dummies);
foreach (var e in Rhss) {
e.ComputeFreeVariables(freeVars);
}
}
}
}
3 changes: 1 addition & 2 deletions Source/Core/MaxHolesLambdaLifter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public override Expr VisitLetExpr(LetExpr node) {

replacements.AddRange(bodyTemplate.GetReplacements());
_templates[node] = new TemplateWithBoundVariables(replacements);
}
else {
} else {
var newRhss = from arg in varBodies select ((TemplateNoBoundVariables) _templates[arg]).GetReplacement();
LambdaLiftingTemplate template = new TemplateNoBoundVariables(
new LetExpr(node.tok, node.Dummies, newRhss.ToList(),
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/StandardVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ public virtual Expr VisitLambdaExpr(LambdaExpr node) {
public virtual Expr VisitLetExpr(LetExpr node) {
Contract.Requires(node != null);
Contract.Ensures(Contract.Result<Expr>() != null);
node.Body = this.VisitExpr(node.Body);
node.Dummies = this.VisitVariableSeq(node.Dummies);
node.Rhss = this.VisitExprSeq(node.Rhss);
node.Dummies = this.VisitVariableSeq(node.Dummies);
node.Body = this.VisitExpr(node.Body);
return node;
}
public virtual Formal VisitFormal(Formal node) {
Expand Down Expand Up @@ -878,9 +878,9 @@ public override Expr VisitLambdaExpr(LambdaExpr node) {
return this.VisitBinderExpr(node);
}
public override Expr VisitLetExpr(LetExpr node) {
this.VisitExpr(node.Body);
this.VisitVariableSeq(node.Dummies);
this.VisitExprSeq(node.Rhss);
this.VisitVariableSeq(node.Dummies);
this.VisitExpr(node.Body);
return node;
}
public override Formal VisitFormal(Formal node)
Expand Down
24 changes: 24 additions & 0 deletions Test/letexpr/git-issue-192.bpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %boogie "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

type AAA;
type BBB;
type CCC;

function Apple(AAA, BBB): CCC;
function Banana(int): BBB;

procedure Proc()
{
var m: [AAA]CCC;
m :=
// Once upon a time, the lambda lifting for the following body switched
// the roles of 15 and Banana(700), by traversing the components of let
// expressions in a different order when figuring out holes from when
// replacing the holes with new bound variables of the lambda lifting.
(lambda aaa: AAA ::
(var g := 15;
Apple(aaa, Banana(700))
)
);
}
2 changes: 2 additions & 0 deletions Test/letexpr/git-issue-192.bpl.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Boogie program verifier finished with 1 verified, 0 errors

0 comments on commit fd500e1

Please sign in to comment.