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

Hide statements #5562

Merged
merged 94 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
a9d1b80
Add Boogie as a submodule
keyboardDrummer Jun 12, 2024
7bded0a
Use Boogie submodule
keyboardDrummer Jun 12, 2024
e7be101
Added reveal test
keyboardDrummer Jun 13, 2024
d34a4fa
Move resolve code for revealStmt to RevealStmt class
keyboardDrummer Jun 13, 2024
b7ae5a5
reveal.dfy test passes
keyboardDrummer Jun 13, 2024
f354052
Update reveal test
keyboardDrummer Jun 13, 2024
23f82c6
Progress towards blind functions
keyboardDrummer Jun 15, 2024
dcc4a89
Simplification
keyboardDrummer Jun 15, 2024
5bbc32e
Reveal.dfy passes
keyboardDrummer Jun 15, 2024
10d4a0f
Refactoring for readability
keyboardDrummer Jun 15, 2024
8f5940a
Add hidden function ensure clause test case to reveal.dfy
keyboardDrummer Jun 16, 2024
37f9462
Refactor TrPredicateStmt
keyboardDrummer Jun 16, 2024
608a6ab
Fix test
keyboardDrummer Jun 16, 2024
fca4526
Reveal now had a passing test for combining blind, opaque and reveal
keyboardDrummer Jun 17, 2024
8c0b90d
Update reveal.dfy test
keyboardDrummer Jun 20, 2024
97c4910
Add scratch test for playing around with
keyboardDrummer Jun 24, 2024
653c776
Make functions in Prelude revealed
keyboardDrummer Jun 24, 2024
3d7e01c
Make more generated function always revealed
keyboardDrummer Jun 24, 2024
5a65cb8
Let axioms decide if they can be hidden
keyboardDrummer Jun 27, 2024
af8b397
Update tests
keyboardDrummer Jun 27, 2024
f8bf900
Update test
keyboardDrummer Jun 27, 2024
84021fb
Update tests
keyboardDrummer Jun 27, 2024
eba67ca
Draft
keyboardDrummer Jul 1, 2024
f4da59c
Replace blind with hide statement
keyboardDrummer Jul 1, 2024
ee98116
Some success on revealFunctions.dfy
keyboardDrummer Jul 1, 2024
64f1c3d
revealFunctions.dfy works except for scoping now
keyboardDrummer Jul 1, 2024
28a2483
Scoping for if now works for revealFunctions.dfy
keyboardDrummer Jul 1, 2024
f4e3658
revealFunctions passes
keyboardDrummer Jul 1, 2024
b755a61
Reveal functions passes
keyboardDrummer Jul 2, 2024
0c2f5a0
Finished draft of revealInBlock test
keyboardDrummer Jul 2, 2024
10db663
Fix printing and cloning of hide reveal statements
keyboardDrummer Jul 2, 2024
18fb8fb
revealInBlock test passes
keyboardDrummer Jul 2, 2024
dd9fd67
Fixed revealInExpression test
keyboardDrummer Jul 2, 2024
f5afce8
Refactoring
keyboardDrummer Jul 2, 2024
a6e65d2
Progress in isolating expression wellformedness checks
keyboardDrummer Jul 3, 2024
c46ff52
revealInExpression test now passes
keyboardDrummer Jul 3, 2024
7861efa
Some cleanup
keyboardDrummer Jul 3, 2024
5664a6f
Adapt to Boogie changes and fix tests
keyboardDrummer Jul 3, 2024
64c5b4c
Refactoring and fixes
keyboardDrummer Jul 3, 2024
b5ad048
Remove comment
keyboardDrummer Jul 4, 2024
eca25fb
Merge commit 'origin/master~1' into alwaysOpaque
keyboardDrummer Jul 4, 2024
c60e66f
Merge remote-tracking branch 'origin/master' into alwaysOpaque
keyboardDrummer Jul 4, 2024
c33ffb1
Refactoring
keyboardDrummer Jul 4, 2024
fbe6356
Update documentation
keyboardDrummer Jul 4, 2024
a8670a9
Add release note
keyboardDrummer Jul 4, 2024
a2a6541
Revert "Use Boogie submodule"
keyboardDrummer Jul 4, 2024
b0b6350
Revert "Add Boogie as a submodule"
keyboardDrummer Jul 4, 2024
915659d
Update Boogie version
keyboardDrummer Jul 4, 2024
6c23085
Update test
keyboardDrummer Jul 14, 2024
484a7a1
Fixes
keyboardDrummer Jul 15, 2024
52b2c78
Merge branch 'master' into alwaysOpaque
keyboardDrummer Jul 15, 2024
4cca877
Fix IsReveal check
keyboardDrummer Jul 15, 2024
11abf08
Merge branch 'alwaysOpaque' of github.com:keyboardDrummer/dafny into …
keyboardDrummer Jul 15, 2024
771f877
Add test for if-case and fix scoping code
keyboardDrummer Jul 15, 2024
c07da2a
Add calc statement test
keyboardDrummer Jul 15, 2024
5dabba1
Delete Boogie submodule
keyboardDrummer Jul 15, 2024
7635658
Fix letSuchThatExprInfo scope
keyboardDrummer Jul 15, 2024
c2ebedf
Move added tests
keyboardDrummer Jul 15, 2024
747c14c
Fix test
keyboardDrummer Jul 15, 2024
7c9d19c
Turn off isolation of statements in a statementexpression
keyboardDrummer Jul 15, 2024
36766ca
Fix BindingGuards
keyboardDrummer Jul 15, 2024
beab051
Added Boogie as submodule
keyboardDrummer Jul 15, 2024
e7dd5bc
Use Boogie submodule
keyboardDrummer Jul 15, 2024
f8a797b
Improve tokens for ChangeScope commands
keyboardDrummer Jul 15, 2024
d27b06f
Add mechanism to deal with the scope change of continue and break sta…
keyboardDrummer Jul 15, 2024
268f249
Remove unnecessary scope changes
keyboardDrummer Jul 15, 2024
e0d319a
More ChangeScope fixes for jumps
keyboardDrummer Jul 15, 2024
d284059
Fix source location issue by not emitting push/pops in return positions
keyboardDrummer Jul 16, 2024
3fb842d
Refactoring
keyboardDrummer Jul 16, 2024
f486987
Add explanatory comment
keyboardDrummer Jul 16, 2024
e739e83
Fix breakage of legacy reveal
keyboardDrummer Jul 16, 2024
67bae1c
Fix HideRevealStmt resolution
keyboardDrummer Jul 16, 2024
d541fd4
Test fixes
keyboardDrummer Jul 16, 2024
ffa458f
Fix tests
keyboardDrummer Jul 16, 2024
11ebe08
Change IdGenerator push popping to be more like it was
keyboardDrummer Jul 16, 2024
15db4b6
Add focus test
keyboardDrummer Jul 17, 2024
823bd99
Trigger CI
keyboardDrummer Jul 17, 2024
66ce6aa
Fixes and test fixes
keyboardDrummer Jul 17, 2024
40eb41c
Fix bugs and tests
keyboardDrummer Jul 17, 2024
70da107
Update error message
keyboardDrummer Jul 17, 2024
e90ba39
Enable hiding of constants
keyboardDrummer Jul 17, 2024
1006d19
Fix doc examples
keyboardDrummer Jul 17, 2024
6919832
Fix docs
keyboardDrummer Jul 17, 2024
1fef94f
Merge branch 'alwaysOpaque' of github.com:keyboardDrummer/dafny into …
keyboardDrummer Jul 18, 2024
7bc15cd
Revert "Use Boogie submodule"
keyboardDrummer Jul 18, 2024
b7e006b
Revert "Added Boogie as submodule"
keyboardDrummer Jul 18, 2024
79516d5
Update Boogie
keyboardDrummer Jul 18, 2024
710a90a
Undo change
keyboardDrummer Jul 18, 2024
8cac279
Update Boogie version
keyboardDrummer Jul 18, 2024
ed700c3
Fix expect file
keyboardDrummer Jul 18, 2024
ba265dc
Update error messages
keyboardDrummer Jul 23, 2024
ffb9607
Merge branch 'master' into alwaysOpaque
keyboardDrummer Jul 23, 2024
5cd817e
Fix woopse
keyboardDrummer Jul 23, 2024
9fbe781
Merge branch 'master' into alwaysOpaque
atomb Jul 24, 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
reveal.dfy test passes
  • Loading branch information
keyboardDrummer committed Jun 13, 2024
commit b7ae5a59b87851f2afc2418f7b50ace0a0893566
1 change: 0 additions & 1 deletion Source/DafnyCore/AST/Grammar/ParserNonGeneratedPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ class DeclModifierData {
public bool IsOpaque;
public IToken OpaqueToken;
public IToken FirstToken;

}

private ModuleKindEnum GetModuleKind(DeclModifierData mods) {
Expand Down
6 changes: 5 additions & 1 deletion Source/DafnyCore/AST/Members/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Method : MethodOrFunction, TypeParameter.ParentType,
Concat(Req).Concat(Ens).Concat(Reads.Expressions).Concat(Mod.Expressions);
public override IEnumerable<INode> PreResolveChildren => Children;

public bool IsBlind { get; set; }
public override string WhatKind => "method";
public bool SignatureIsOmitted { get { return SignatureEllipsis != null; } }
public readonly IToken SignatureEllipsis;
Expand Down Expand Up @@ -125,6 +126,7 @@ public class Method : MethodOrFunction, TypeParameter.ParentType,
this.Outs = original.Outs.ConvertAll(p => cloner.CloneFormal(p, false));
}

this.IsBlind = original.IsBlind;
this.Reads = cloner.CloneSpecFrameExpr(original.Reads);
this.Mod = cloner.CloneSpecFrameExpr(original.Mod);
this.Body = cloner.CloneMethodBody(original);
Expand All @@ -142,9 +144,11 @@ public class Method : MethodOrFunction, TypeParameter.ParentType,
[Captured] List<AttributedExpression> ens,
[Captured] Specification<Expression> decreases,
[Captured] BlockStmt body,
Attributes attributes, IToken signatureEllipsis, bool isByMethod = false)
Attributes attributes, IToken signatureEllipsis,
bool isByMethod = false, bool isBlind = false)
: base(rangeToken, name, hasStaticKeyword, isGhost, attributes, signatureEllipsis != null,
typeArgs, ins, req, ens, decreases) {
this.IsBlind = isBlind;
Contract.Requires(rangeToken != null);
Contract.Requires(name != null);
Contract.Requires(cce.NonNullElements(typeArgs));
Expand Down
91 changes: 58 additions & 33 deletions Source/DafnyCore/AST/Statements/Verification/RevealStmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ public class RevealStmt : Statement, ICloneable<RevealStmt>, ICanFormat {
public const string RevealLemmaPrefix = "reveal_";

public readonly List<Expression> Exprs;
[FilledInDuringResolution] public readonly List<AssertLabel> LabeledAsserts = new List<AssertLabel>(); // to indicate that "Expr" denotes a labeled assertion
[FilledInDuringResolution] public readonly List<Statement> ResolvedStatements = new List<Statement>();
[FilledInDuringResolution]
public readonly List<AssertLabel> LabeledAsserts = new(); // to indicate that "Expr" denotes a labeled assertion
[FilledInDuringResolution]
public readonly List<Statement> ResolvedStatements = new();
[FilledInDuringResolution] public bool InBlindContext { get; private set; }
[FilledInDuringResolution] public List<MemberDecl> RevealedMembers = new();


public override IEnumerable<Statement> SubStatements {
get { return ResolvedStatements; }
Expand Down Expand Up @@ -54,51 +59,71 @@ public RevealStmt(RangeToken rangeToken, List<Expression> exprs)
return formatter.SetIndentPrintRevealStmt(indentBefore, OwnedTokens);
}

public void ResolveRevealStmt(PreTypeResolver preTypeResolver, ResolutionContext resolutionContext)
public void Resolve(PreTypeResolver resolver, ResolutionContext resolutionContext)
{
foreach (var expr in Exprs) {
var name = SingleName(expr);
var labeledAssert = name == null ? null : preTypeResolver.DominatingStatementLabels.Find(name) as AssertLabel;
var labeledAssert = name == null ? null : resolver.DominatingStatementLabels.Find(name) as AssertLabel;
if (labeledAssert != null) {
LabeledAsserts.Add(labeledAssert);
} else {
var revealResolutionContext = resolutionContext with { InReveal = true };
if (expr is ApplySuffix applySuffix) {
var methodCallInfo = preTypeResolver.ResolveApplySuffix(applySuffix, revealResolutionContext, true);
if (methodCallInfo == null) {
// error has already been reported
} else if (methodCallInfo.Callee.Member is TwoStateLemma && !revealResolutionContext.IsTwoState) {
preTypeResolver.Reporter.Error(MessageSource.Resolver, methodCallInfo.Tok, "a two-state function can only be revealed in a two-state context");
} else if (methodCallInfo.Callee.AtLabel != null) {
Contract.Assert(methodCallInfo.Callee.Member is TwoStateLemma);
preTypeResolver.Reporter.Error(MessageSource.Resolver, methodCallInfo.Tok, "to reveal a two-state function, do not list any parameters or @-labels");
if (resolutionContext.InBlindMethod) {
InBlindContext = true;
if (expr is NameSegment or ExprDotName) {
if (expr is NameSegment) {
resolver.ResolveNameSegment((NameSegment)expr, true, null, resolutionContext, true);
} else {
resolver.ResolveDotSuffix((ExprDotName)expr, true, null, resolutionContext, true);
}
var callee = (MemberSelectExpr)((ConcreteSyntaxExpression)expr).ResolvedExpression;
if (callee == null) {
// error from resolving child
} else {
RevealedMembers.Add(callee.Member);
}
} else {
var call = new CallStmt(RangeToken, new List<Expression>(), methodCallInfo.Callee, methodCallInfo.ActualParameters);
ResolvedStatements.Add(call);
}
} else if (expr is NameSegment or ExprDotName) {
if (expr is NameSegment) {
preTypeResolver.ResolveNameSegment((NameSegment)expr, true, null, revealResolutionContext, true);
} else {
preTypeResolver.ResolveDotSuffix((ExprDotName)expr, true, null, revealResolutionContext, true);
}
var callee = (MemberSelectExpr)((ConcreteSyntaxExpression)expr).ResolvedExpression;
if (callee == null) {
} else if (callee.Member is Lemma or TwoStateLemma && Attributes.Contains(callee.Member.Attributes, "axiom")) {
//The revealed member is a function
preTypeResolver.ReportError(callee.tok, "to reveal a function ({0}), append parentheses", callee.Member.ToString().Substring(7));
} else {
var call = new CallStmt(RangeToken, new List<Expression>(), callee, new List<ActualBinding>(), expr.tok);
ResolvedStatements.Add(call);
resolver.Reporter.Error(MessageSource.Resolver, Tok, "can't use parenthesis when revealing");
}
} else {
preTypeResolver.ResolveExpression(expr, revealResolutionContext);
var revealResolutionContext = resolutionContext with { InReveal = true };
if (expr is ApplySuffix applySuffix) {
var methodCallInfo = resolver.ResolveApplySuffix(applySuffix, revealResolutionContext, true);
if (methodCallInfo == null) {
// error has already been reported
} else if (methodCallInfo.Callee.Member is TwoStateLemma && !revealResolutionContext.IsTwoState) {
resolver.Reporter.Error(MessageSource.Resolver, methodCallInfo.Tok, "a two-state function can only be revealed in a two-state context");
} else if (methodCallInfo.Callee.AtLabel != null) {
Contract.Assert(methodCallInfo.Callee.Member is TwoStateLemma);
resolver.Reporter.Error(MessageSource.Resolver, methodCallInfo.Tok, "to reveal a two-state function, do not list any parameters or @-labels");
} else {
var call = new CallStmt(RangeToken, new List<Expression>(), methodCallInfo.Callee, methodCallInfo.ActualParameters);
ResolvedStatements.Add(call);
}
} else if (expr is NameSegment or ExprDotName) {
if (expr is NameSegment) {
resolver.ResolveNameSegment((NameSegment)expr, true, null, revealResolutionContext, true);
} else {
resolver.ResolveDotSuffix((ExprDotName)expr, true, null, revealResolutionContext, true);
}
var callee = (MemberSelectExpr)((ConcreteSyntaxExpression)expr).ResolvedExpression;
if (callee == null) {
} else if (callee.Member is Lemma or TwoStateLemma && Attributes.Contains(callee.Member.Attributes, "axiom")) {
//The revealed member is a function
resolver.ReportError(callee.tok, "to reveal a function ({0}), append parentheses", callee.Member.ToString().Substring(7));
} else {
// TODO what is this case about? Revealing a constant?
var call = new CallStmt(RangeToken, new List<Expression>(), callee, new List<ActualBinding>(), expr.tok);
ResolvedStatements.Add(call);
}
} else {
resolver.ResolveExpression(expr, revealResolutionContext);
}
}
}
}

foreach (var a in ResolvedStatements) {
preTypeResolver.ResolveStatement(a, resolutionContext);
resolver.ResolveStatement(a, resolutionContext);
}
}
}
12 changes: 10 additions & 2 deletions Source/DafnyCore/Dafny.atg
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,13 @@ MethodDecl<DeclModifierData dmod, bool allowConstructor, out Method/*!*/ m>
IToken tokenWithTrailingDocString = Token.NoToken;
IToken bodyStart = Token.NoToken;
IToken bodyEnd = Token.NoToken;
bool isBlind = false;
AllowedDeclModifiers allowed = AllowedDeclModifiers.None;
string caption = "";
ExtremePredicate.KType kType = ExtremePredicate.KType.Unspecified;
.)
SYNC
[ "blind" ] (. isBlind = true; .)
( "method" (. isPlainOlMethod = true; caption = "method";
CheckAndSetTokenOnce(ref dmod.FirstToken);
allowed = AllowedDeclModifiers.Ghost | AllowedDeclModifiers.Static; .)
Expand Down Expand Up @@ -1253,7 +1255,10 @@ MethodDecl<DeclModifierData dmod, bool allowConstructor, out Method/*!*/ m>
(. var range = new RangeToken(dmod.FirstToken, t);
if (isConstructor) {
m = new Constructor(range, hasName ? name : new Name(dmod.FirstToken.ToRange(), "_ctor"), dmod.IsGhost, typeArgs, ins,
req, new Specification<FrameExpression>(reads, readsAttrs), new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), (DividedBlockStmt)body, attrs, signatureEllipsis);
req, new Specification<FrameExpression>(reads, readsAttrs),
new Specification<FrameExpression>(mod, modAttrs), ens,
new Specification<Expression>(dec, decAttrs),
(DividedBlockStmt)body, attrs, signatureEllipsis);
} else if (isLeastLemma) {
m = new LeastLemma(range, name, dmod.IsStatic, kType, typeArgs, ins, outs,
req, new Specification<FrameExpression>(reads, readsAttrs), new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
Expand All @@ -1269,7 +1274,10 @@ MethodDecl<DeclModifierData dmod, bool allowConstructor, out Method/*!*/ m>
ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
} else {
m = new Method(range, name, dmod.IsStatic, dmod.IsGhost, typeArgs, ins, outs,
req, new Specification<FrameExpression>(reads, readsAttrs), new Specification<FrameExpression>(mod, modAttrs), ens, new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis);
req, new Specification<FrameExpression>(reads, readsAttrs),
new Specification<FrameExpression>(mod, modAttrs), ens,
new Specification<Expression>(dec, decAttrs), body, attrs, signatureEllipsis,
isBlind: isBlind);
}
m.BodyStartTok = bodyStart;
m.TokenWithTrailingDocString = tokenWithTrailingDocString;
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/DafnyPrelude.bpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function TagFamily(Ty): TyTagFamily;
// ---------------------------------------------------------------
// -- Literals ---------------------------------------------------
// ---------------------------------------------------------------
function {:identity} Lit<T>(x: T): T { x }
revealed function {:identity} Lit<T>(x: T): T { x }
axiom (forall<T> x: T :: { $Box(Lit(x)) } $Box(Lit(x)) == Lit($Box(x)) );

// Specialize Lit to concrete types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public partial class PreTypeResolver : INewOrOldResolver {
} else if (stmt is RevealStmt)
{
var s = (RevealStmt)stmt;
s.ResolveRevealStmt(this, resolutionContext);
s.Resolve(this, resolutionContext);
} else if (stmt is BreakStmt) {
var s = (BreakStmt)stmt;
if (s.TargetLabel != null) {
Expand Down
9 changes: 6 additions & 3 deletions Source/DafnyCore/Resolver/ResolutionContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Microsoft.Dafny;

public record ResolutionContext(ICodeContext CodeContext, bool IsTwoState, bool InOld, bool InReveal,
bool InFunctionPostcondition, bool InFirstPhaseConstructor) {
bool InFunctionPostcondition, bool InFirstPhaseConstructor, bool InBlindMethod) {

// Invariants:
// InOld implies !IsTwoState
Expand All @@ -10,13 +10,14 @@ public record ResolutionContext(ICodeContext CodeContext, bool IsTwoState, bool
public bool IsGhost => CodeContext.IsGhost;

public ResolutionContext(ICodeContext codeContext, bool isTwoState)
: this(codeContext, isTwoState, false, false, false, false) {
: this(codeContext, isTwoState, false, false, false, false, false) {
}

/// <summary>
/// Return a ResolutionContext appropriate for the body of "codeContext".
/// </summary>
public static ResolutionContext FromCodeContext(ICodeContext codeContext) {
var isBlind = codeContext is Method method && method.IsBlind;
bool isTwoState;
if (codeContext is NoContext || codeContext is DatatypeDecl || codeContext is ConstantField) {
isTwoState = false;
Expand All @@ -25,7 +26,9 @@ public ResolutionContext(ICodeContext codeContext, bool isTwoState)
} else {
isTwoState = true;
}
return new ResolutionContext(codeContext, isTwoState);
return new ResolutionContext(codeContext, isTwoState) {
InBlindMethod = isBlind
};
}

public IMethodCodeContext AsMethodCodeContext => CodeContext as IMethodCodeContext;
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Verifier/BoogieGenerator.BoogieFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ enum BuiltinFunction {

private void BplIfIf(Bpl.IToken tk, bool yes, Bpl.Expr guard, BoogieStmtListBuilder builder, Action<BoogieStmtListBuilder> k) {
if (yes) {
var newBuilder = new BoogieStmtListBuilder(builder.tran, options);
var newBuilder = new BoogieStmtListBuilder(builder.tran, options, builder.Context);
k(newBuilder);
builder.Add(new Bpl.IfCmd(tk, guard, newBuilder.Collect(tk), null, null));
} else {
Expand Down
Loading