From bd3dedcc023edb51d2a03619061bb03463821534 Mon Sep 17 00:00:00 2001 From: leino Date: Mon, 21 Sep 2015 21:25:55 -0700 Subject: Removed unused code (old code from previous ghost-statement handling) --- Source/Dafny/DafnyAst.cs | 16 --- Source/Dafny/Resolver.cs | 282 ++++++----------------------------------------- 2 files changed, 31 insertions(+), 267 deletions(-) (limited to 'Source') diff --git a/Source/Dafny/DafnyAst.cs b/Source/Dafny/DafnyAst.cs index 83db732e..2a98d5c2 100644 --- a/Source/Dafny/DafnyAst.cs +++ b/Source/Dafny/DafnyAst.cs @@ -3461,23 +3461,7 @@ namespace Microsoft.Dafny { Contract.Invariant(EndTok != null); } -#if OLD_GHOST_HANDLING public bool IsGhost; // filled in by resolution -#else - public static bool ReadyToDealWithGhostField = true; - private bool izzaGhost; - public bool IsGhost { - get { - Contract.Requires(ReadyToDealWithGhostField); - return izzaGhost; - } - set { - Contract.Requires(ReadyToDealWithGhostField); - izzaGhost = value; - } - } - public bool C_IsGhost; // new ghost computation -#endif public Statement(IToken tok, IToken endTok, Attributes attrs) { Contract.Requires(tok != null); diff --git a/Source/Dafny/Resolver.cs b/Source/Dafny/Resolver.cs index 87379478..d82d7d1f 100644 --- a/Source/Dafny/Resolver.cs +++ b/Source/Dafny/Resolver.cs @@ -1533,7 +1533,7 @@ namespace Microsoft.Dafny } } foreach (AssignSuchThatStmt s in needBoundsDiscovery_AssignSuchThatStmt) { - Contract.Assert(!s.C_IsGhost); + Contract.Assert(!s.IsGhost); var varLhss = new List(); foreach (var lhs in s.Lhss) { var ide = (IdentifierExpr)lhs.Resolved; // successful resolution above implies all LHS's are IdentifierExpr's @@ -3060,7 +3060,7 @@ namespace Microsoft.Dafny Contract.Assume(!codeContext.IsGhost || mustBeErasable); // (this is really a precondition) codeContext.IsGhost ==> mustBeErasable if (stmt is PredicateStmt) { - stmt.C_IsGhost = true; + stmt.IsGhost = true; } else if (stmt is PrintStmt) { var s = (PrintStmt)stmt; @@ -3073,7 +3073,7 @@ namespace Microsoft.Dafny } else if (stmt is BreakStmt) { var s = (BreakStmt)stmt; if (mustBeErasable) { - if (!s.TargetStmt.C_IsGhost && !resolver.inSpecOnlyContext[s.TargetStmt]) { // TODO: inSpecOnlyContext should probably move from Resolver to GhostInterest_Visitor + if (!s.TargetStmt.IsGhost && !resolver.inSpecOnlyContext[s.TargetStmt]) { // TODO: inSpecOnlyContext should probably move from Resolver to GhostInterest_Visitor var targetIsLoop = s.TargetStmt is WhileStmt || s.TargetStmt is AlternativeLoopStmt; Error(stmt, "ghost-context break statement is not allowed to break out of non-ghost " + (targetIsLoop ? "loop" : "structure")); } @@ -3091,7 +3091,7 @@ namespace Microsoft.Dafny } else if (stmt is AssignSuchThatStmt) { var s = (AssignSuchThatStmt)stmt; - s.C_IsGhost = mustBeErasable || s.AssumeToken != null || s.Lhss.Any(AssignStmt.LhsIsToGhost); + s.IsGhost = mustBeErasable || s.AssumeToken != null || s.Lhss.Any(AssignStmt.LhsIsToGhost); if (mustBeErasable && !codeContext.IsGhost) { foreach (var lhs in s.Lhss) { var gk = AssignStmt.LhsIsToGhost_Which(lhs); @@ -3107,14 +3107,14 @@ namespace Microsoft.Dafny } } } - if (!s.C_IsGhost) { + if (!s.IsGhost) { resolver.needBoundsDiscovery_AssignSuchThatStmt.Add(s); } } else if (stmt is UpdateStmt) { var s = (UpdateStmt)stmt; s.ResolvedStatements.Iter(ss => Visit(ss, mustBeErasable)); - s.C_IsGhost = s.ResolvedStatements.All(ss => ss.C_IsGhost); + s.IsGhost = s.ResolvedStatements.All(ss => ss.IsGhost); } else if (stmt is VarDeclStmt) { var s = (VarDeclStmt)stmt; @@ -3131,7 +3131,7 @@ namespace Microsoft.Dafny } } } - s.C_IsGhost = (s.Update == null || s.Update.C_IsGhost) && s.Locals.All(v => v.IsGhost); + s.IsGhost = (s.Update == null || s.Update.IsGhost) && s.Locals.All(v => v.IsGhost); if (s.Update != null) { Visit(s.Update, mustBeErasable); } @@ -3141,7 +3141,7 @@ namespace Microsoft.Dafny var lhs = s.Lhs.Resolved; var gk = AssignStmt.LhsIsToGhost_Which(lhs); if (gk == AssignStmt.NonGhostKind.IsGhost) { - s.C_IsGhost = true; + s.IsGhost = true; } else if (gk == AssignStmt.NonGhostKind.Variable && codeContext.IsGhost) { // cool } else if (mustBeErasable) { @@ -3170,10 +3170,10 @@ namespace Microsoft.Dafny var s = (CallStmt)stmt; var callee = s.Method; Contract.Assert(callee != null); // follows from the invariant of CallStmt - s.C_IsGhost = callee.IsGhost; + s.IsGhost = callee.IsGhost; // check in-parameters if (mustBeErasable) { - if (!s.C_IsGhost) { + if (!s.IsGhost) { Error(s, "only ghost methods can be called from this context"); } } else { @@ -3221,59 +3221,59 @@ namespace Microsoft.Dafny } else if (stmt is BlockStmt) { var s = (BlockStmt)stmt; s.Body.Iter(ss => Visit(ss, mustBeErasable)); - s.C_IsGhost = s.Body.All(ss => ss.C_IsGhost); // mark the block statement as ghost if all its substatements are ghost + s.IsGhost = s.Body.All(ss => ss.IsGhost); // mark the block statement as ghost if all its substatements are ghost } else if (stmt is IfStmt) { var s = (IfStmt)stmt; - s.C_IsGhost = mustBeErasable || (s.Guard != null && resolver.UsesSpecFeatures(s.Guard)); - Visit(s.Thn, s.C_IsGhost); + s.IsGhost = mustBeErasable || (s.Guard != null && resolver.UsesSpecFeatures(s.Guard)); + Visit(s.Thn, s.IsGhost); if (s.Els != null) { - Visit(s.Els, s.C_IsGhost); + Visit(s.Els, s.IsGhost); } // if both branches were all ghost, then we can mark the enclosing statement as ghost as well - s.C_IsGhost = s.C_IsGhost || (s.Thn.C_IsGhost && (s.Els == null || s.Els.C_IsGhost)); + s.IsGhost = s.IsGhost || (s.Thn.IsGhost && (s.Els == null || s.Els.IsGhost)); } else if (stmt is AlternativeStmt) { var s = (AlternativeStmt)stmt; - s.C_IsGhost = mustBeErasable || s.Alternatives.Exists(alt => resolver.UsesSpecFeatures(alt.Guard)); - s.Alternatives.Iter(alt => alt.Body.Iter(ss => Visit(ss, s.C_IsGhost))); - s.C_IsGhost = s.C_IsGhost || s.Alternatives.All(alt => alt.Body.All(ss => ss.C_IsGhost)); + s.IsGhost = mustBeErasable || s.Alternatives.Exists(alt => resolver.UsesSpecFeatures(alt.Guard)); + s.Alternatives.Iter(alt => alt.Body.Iter(ss => Visit(ss, s.IsGhost))); + s.IsGhost = s.IsGhost || s.Alternatives.All(alt => alt.Body.All(ss => ss.IsGhost)); } else if (stmt is WhileStmt) { var s = (WhileStmt)stmt; - s.C_IsGhost = mustBeErasable || (s.Guard != null && resolver.UsesSpecFeatures(s.Guard)); - if (s.C_IsGhost && s.Decreases.Expressions.Exists(e => e is WildcardExpr)) { + s.IsGhost = mustBeErasable || (s.Guard != null && resolver.UsesSpecFeatures(s.Guard)); + if (s.IsGhost && s.Decreases.Expressions.Exists(e => e is WildcardExpr)) { Error(s, "'decreases *' is not allowed on ghost loops"); } if (s.Body != null) { - Visit(s.Body, s.C_IsGhost); + Visit(s.Body, s.IsGhost); } - s.C_IsGhost = s.C_IsGhost || s.Body == null || (!s.Decreases.Expressions.Exists(e => e is WildcardExpr) && s.Body.C_IsGhost); + s.IsGhost = s.IsGhost || s.Body == null || (!s.Decreases.Expressions.Exists(e => e is WildcardExpr) && s.Body.IsGhost); } else if (stmt is AlternativeLoopStmt) { var s = (AlternativeLoopStmt)stmt; - s.C_IsGhost = mustBeErasable || s.Alternatives.Exists(alt => resolver.UsesSpecFeatures(alt.Guard)); - s.Alternatives.Iter(alt => alt.Body.Iter(ss => Visit(ss, s.C_IsGhost))); - s.C_IsGhost = s.C_IsGhost || (!s.Decreases.Expressions.Exists(e => e is WildcardExpr) && s.Alternatives.All(alt => alt.Body.All(ss => ss.C_IsGhost))); + s.IsGhost = mustBeErasable || s.Alternatives.Exists(alt => resolver.UsesSpecFeatures(alt.Guard)); + s.Alternatives.Iter(alt => alt.Body.Iter(ss => Visit(ss, s.IsGhost))); + s.IsGhost = s.IsGhost || (!s.Decreases.Expressions.Exists(e => e is WildcardExpr) && s.Alternatives.All(alt => alt.Body.All(ss => ss.IsGhost))); } else if (stmt is ForallStmt) { var s = (ForallStmt)stmt; - s.C_IsGhost = mustBeErasable || s.Kind != ForallStmt.ParBodyKind.Assign || resolver.UsesSpecFeatures(s.Range); + s.IsGhost = mustBeErasable || s.Kind != ForallStmt.ParBodyKind.Assign || resolver.UsesSpecFeatures(s.Range); if (s.Body != null) { - Visit(s.Body, s.C_IsGhost); + Visit(s.Body, s.IsGhost); } - s.C_IsGhost = s.C_IsGhost || s.Body == null || s.Body.C_IsGhost; + s.IsGhost = s.IsGhost || s.Body == null || s.Body.IsGhost; } else if (stmt is ModifyStmt) { var s = (ModifyStmt)stmt; if (s.Body != null) { Visit(s.Body, mustBeErasable); } - s.C_IsGhost = mustBeErasable; + s.IsGhost = mustBeErasable; } else if (stmt is CalcStmt) { var s = (CalcStmt)stmt; - s.C_IsGhost = true; + s.IsGhost = true; foreach (var h in s.Hints) { Visit(h, true); } @@ -3282,7 +3282,7 @@ namespace Microsoft.Dafny var s = (MatchStmt)stmt; var mbe = mustBeErasable || resolver.UsesSpecFeatures(s.Source); s.Cases.Iter(kase => kase.Body.Iter(ss => Visit(ss, mbe))); - s.C_IsGhost = mbe || s.Cases.All(kase => kase.Body.All(ss => ss.C_IsGhost)); + s.IsGhost = mbe || s.Cases.All(kase => kase.Body.All(ss => ss.IsGhost)); } else if (stmt is SkeletonStatement) { var s = (SkeletonStatement)stmt; @@ -3293,7 +3293,6 @@ namespace Microsoft.Dafny } else { Contract.Assert(false); throw new cce.UnreachableException(); } - stmt.IsGhost = stmt.C_IsGhost; // DEBUG } } #endregion @@ -4119,10 +4118,6 @@ namespace Microsoft.Dafny void ResolveMethod(Method m) { Contract.Requires(m != null); -#if !OLD_GH - var oldx = Statement.ReadyToDealWithGhostField; - Statement.ReadyToDealWithGhostField = false; -#endif try { currentMethod = m; @@ -4192,7 +4187,6 @@ namespace Microsoft.Dafny ResolveBlockStatement(m.Body, m.IsGhost, m); SolveAllTypeConstraints(); if (reporter.Count(ErrorLevel.Error) == prevErrorCount) { - Statement.ReadyToDealWithGhostField = true; ComputeGhostInterest(m.Body, m); } } @@ -4206,9 +4200,6 @@ namespace Microsoft.Dafny finally { currentMethod = null; -#if !OLD_GH - Statement.ReadyToDealWithGhostField = oldx; -#endif } } @@ -5165,9 +5156,6 @@ namespace Microsoft.Dafny } if (stmt is PredicateStmt) { PredicateStmt s = (PredicateStmt)stmt; -#if OLD_GH - s.IsGhost = true; -#endif ResolveExpression(s.Expr, new ResolveOpts(codeContext, true, true)); Contract.Assert(s.Expr.Type != null); // follows from postcondition of ResolveExpression ConstrainTypes(s.Expr.Type, Type.Bool, s.Expr, "condition is expected to be of type {0}, but is {1}", Type.Bool, s.Expr.Type); @@ -5176,12 +5164,6 @@ namespace Microsoft.Dafny var s = (PrintStmt)stmt; var opts = new ResolveOpts(codeContext, false, specContextOnly); s.Args.Iter(e => ResolveExpression(e, opts)); -#if OLD_GHOST_HANDLING - ResolveAttributeArgs(s.Args, new ResolveOpts(codeContext, false, specContextOnly)); - if (specContextOnly) { - reporter.Error(MessageSource.Resolver, stmt, "print statement is not allowed in this context (because this is a ghost method or because the statement is guarded by a specification-only expression)"); - } -#endif } else if (stmt is BreakStmt) { var s = (BreakStmt)stmt; @@ -5191,12 +5173,6 @@ namespace Microsoft.Dafny reporter.Error(MessageSource.Resolver, s, "break label is undefined or not in scope: {0}", s.TargetLabel); } else { s.TargetStmt = target; -#if OLD_GHOST_HANDLING - bool targetIsLoop = target is WhileStmt || target is AlternativeLoopStmt; - if (specContextOnly && !s.TargetStmt.IsGhost && !inSpecOnlyContext[s.TargetStmt]) { - reporter.Error(MessageSource.Resolver, stmt, "ghost-context break statement is not allowed to break out of non-ghost " + (targetIsLoop ? "loop" : "structure")); - } -#endif } } else { if (loopStack.Count < s.BreakCount) { @@ -5208,11 +5184,6 @@ namespace Microsoft.Dafny target.Labels = new LList