-
Notifications
You must be signed in to change notification settings - Fork 261
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
refactor: Clean up resolution passes 0 and 1 #3284
Merged
RustanLeino
merged 60 commits into
dafny-lang:master
from
RustanLeino:check-type-inference
Dec 29, 2022
Merged
Changes from 56 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
9aa45b9
Introduce IASTVisitorContext
RustanLeino e6d6bbe
Introduce ASTVisitor
RustanLeino f513f96
Introduce CallGraphASTVisitor
RustanLeino 00f1ed8
Use IASTVisitorContext instead of ICodeContext as CallGraphBuilderCon…
RustanLeino 363b50d
Move work from VisitFunction to VisitFunctionProper
RustanLeino 5c01d60
Move work from VisitMethod to VisitMethodProper
RustanLeino 6b7f96e
Change CallGraphBuilder visitor into a subclass of ASTVisitor
RustanLeino 10069f5
Remove code that moved into ASTVisitor
RustanLeino b500fa2
Move visitor methods from CallGraphBuilder to CallGraphASTVisitor to
RustanLeino 4598fd9
Generalize context parameter for ASTVisitor
RustanLeino 1a082e9
Move visitation of user-provided types, subexpressions, and substatem…
RustanLeino 74b96fc
Virtualize declaration/member visitation as well
RustanLeino 35c70d7
Merge branch 'master' into AstVisitor
RustanLeino 33bb66c
Move ASTVisitor and IASTVisitorContext into a separate file
RustanLeino 10c2f32
Merge branch 'master' into AstVisitor
RustanLeino 44dabc0
Visit StmtExpr’s substatements before its subexpressions
RustanLeino 854ee25
Move type-determined checks a little later
RustanLeino 8111b99
Improved names of identifiers
RustanLeino cc7caf5
Collect code into new ResolveNamesAndInferTypes method
RustanLeino 4edf858
Improve code organization
RustanLeino a8a5766
Resolve attributes last
RustanLeino b179549
Combined some post-name-resolution visitation checks
RustanLeino a2b7d51
fix: Disallow “this” in non-instance attributes
RustanLeino af01ea3
Group similar checks into the same visitation pass
RustanLeino c79e628
Do CheckTypeInference together
RustanLeino 5dd1182
Merge branch 'master' into check-type-inference
RustanLeino 26baac4
Separate type-inference checking, bounds discovery, and ghost checking
RustanLeino e48f7ab
Adjust lines in test file
RustanLeino 7638787
Split test into two modules
RustanLeino 56fd78a
Adjust test to show both errors
RustanLeino cd6055e
Improve comments
RustanLeino ea2f677
Splits tests to get errors from what is now different passes
RustanLeino 8647a91
Check type inference of the beginning of prefix lemmas earlier
RustanLeino 2b41297
Update expected test output
RustanLeino 0e5e4d3
Check CheckTypeInference… to only take IASTVisitorContext, not ICodeC…
RustanLeino df5a707
Improve CheckTypeInference for const
RustanLeino 3924295
Improve code
RustanLeino 86a3369
Improve organization of CheckTypeInference visitor
RustanLeino 852f7fe
fix: Infer (==) for non-null iterator type
RustanLeino e0ec038
To reduce special cases, also include NonNullTypeDecl in cyclicity ch…
RustanLeino fead483
refactor: Use AST Visitor instead of BottomUp visitor
RustanLeino 5f678a9
Make resolution/checking of attributes consistent
RustanLeino d2aafd0
Make recording of warnShadowing attribute consistent
RustanLeino 805f70d
Better document the pre/postcondition of ResolveParameterDefaultValues
RustanLeino fe502c3
fix: Set scope correctly for resolving attributes of top-level declar…
RustanLeino 87fb940
fix: Indent member block of newtypes
RustanLeino 7dae2ae
refactor: Move “(==) unnecessary” check to later pass
RustanLeino 477b418
Add post-visitor (bottom up) to ASTVisitor
RustanLeino c906a0d
Change CheckTypeInference (back) to be a bottom-up traversal
RustanLeino 85c947d
Improve code
RustanLeino d413947
Merge branch 'master' into check-type-inference
RustanLeino 413c75b
Move some pass-0 code from Resolver.cs to NameResolutionAndTypeInfere…
RustanLeino 00db663
Move default-parameter substitution to pass 0 from pass 1
RustanLeino 4a66545
Add user-visible release notes
RustanLeino 0e62b8c
Rename CheckTypeInference_Visitor.cs TypeInferenceChecker.cs
RustanLeino 2801491
Fix whitespace
RustanLeino cd81c32
Respond to review comments
RustanLeino 2c7b341
Split Resolve…OneDeclaration and Resolve..MemberBodies into two metho…
RustanLeino 0de1991
Report type-parameter errors earlier
RustanLeino 570abb9
Merge branch 'master' into check-type-inference
RustanLeino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ protected virtual void VisitOneDeclaration(TopLevelDecl decl) { | |
} | ||
|
||
if (decl is TopLevelDeclWithMembers cl) { | ||
cl.Members.Iter(member => VisitMember(cl, member)); | ||
cl.Members.Iter(VisitMember); | ||
} | ||
} | ||
|
||
|
@@ -89,19 +89,9 @@ private void VisitIterator(IteratorDecl iteratorDecl) { | |
} | ||
} | ||
|
||
protected virtual void VisitMember(TopLevelDeclWithMembers cl, MemberDecl member) { | ||
if (member is ConstantField constantField) { | ||
var context = GetContext(constantField, false); | ||
VisitAttributes(constantField, constantField.EnclosingModule); | ||
VisitUserProvidedType(constantField.Type, context); | ||
if (constantField.Rhs != null) { | ||
VisitExpression(constantField.Rhs, context); | ||
} | ||
|
||
} else if (member is Field field) { | ||
var context = GetContext(new NoContext(cl.EnclosingModuleDefinition), false); | ||
VisitAttributes(field, cl.EnclosingModuleDefinition); | ||
VisitUserProvidedType(field.Type, context); | ||
public void VisitMember(MemberDecl member) { | ||
if (member is Field field) { | ||
VisitField(field); | ||
|
||
} else if (member is Function function) { | ||
VisitFunction(function); | ||
|
@@ -129,6 +119,18 @@ protected virtual void VisitMember(TopLevelDeclWithMembers cl, MemberDecl member | |
} | ||
} | ||
|
||
public virtual void VisitField(Field field) { | ||
var enclosingModule = field.EnclosingClass.EnclosingModuleDefinition; | ||
VisitAttributes(field, enclosingModule); | ||
|
||
var context = GetContext(field as IASTVisitorContext ?? new NoContext(enclosingModule), false); | ||
VisitUserProvidedType(field.Type, context); | ||
|
||
if (field is ConstantField { Rhs: { } rhs }) { | ||
VisitExpression(rhs, context); | ||
} | ||
} | ||
|
||
public virtual void VisitFunction(Function function) { | ||
var context = GetContext(function, false); | ||
|
||
|
@@ -260,18 +262,26 @@ protected virtual void VisitExpression(Expression expr, VisitorContext context) | |
|
||
// Visit subexpressions | ||
expr.SubExpressions.Iter(ee => VisitExpression(ee, context)); | ||
|
||
// Finish by calling the post-visitor method | ||
PostVisitOneExpression(expr, context); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Visits the given expression. | ||
/// Returns "true" to request that the caller keeps visiting all user-provided types, subexpressions, and substatements of "expr", and | ||
/// returns "false" to tell the caller not to. | ||
/// Returns "true" to request that the caller | ||
/// - keeps visiting all user-provided types, subexpressions, and substatements of "expr", and | ||
/// - then calls PostVisitOneExpression. | ||
/// Returns "false" to tell the caller not to do those things. | ||
/// </summary> | ||
protected virtual bool VisitOneExpression(Expression expr, VisitorContext context) { | ||
return true; | ||
} | ||
|
||
protected virtual void PostVisitOneExpression(Expression expr, VisitorContext context) { | ||
} | ||
|
||
protected virtual void VisitStatement(Statement stmt, VisitorContext context) { | ||
if (VisitOneStatement(stmt, context)) { | ||
// Visit user-provided types | ||
|
@@ -317,17 +327,25 @@ protected virtual void VisitStatement(Statement stmt, VisitorContext context) { | |
|
||
// Visit substatements | ||
stmt.SubStatements.Iter(ss => VisitStatement(ss, context)); | ||
|
||
// Finish by calling the post-visitor method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment seems redundant given the name |
||
PostVisitOneStatement(stmt, context); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Visits the given statement. | ||
/// Returns "true" to request that the caller keeps visiting all user-provided types, subexpressions, and substatements of "stmt", and | ||
/// returns "false" to tell the caller not to. | ||
/// Returns "true" to request that the caller | ||
/// - keeps visiting all user-provided types, subexpressions, and substatements of "stmt", and | ||
/// - then calls PostVisitOneStatement. | ||
/// Returns "false" to tell the caller not to do those things. | ||
/// </summary> | ||
protected virtual bool VisitOneStatement(Statement stmt, VisitorContext context) { | ||
return true; | ||
} | ||
|
||
protected virtual void PostVisitOneStatement(Statement stmt, VisitorContext context) { | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,33 +230,30 @@ private bool CheckIsCompilable(Expression expr, ICodeContext codeContext) { | |
return isCompilable; | ||
} else if (expr is LambdaExpr lambdaExpr) { | ||
return CheckIsCompilable(lambdaExpr.Body, codeContext); | ||
} else if (expr is ComprehensionExpr comprehensionExpr) { | ||
var uncompilableBoundVars = comprehensionExpr.UncompilableBoundVars(); | ||
} else if (expr is ComprehensionExpr) { | ||
var e = (ComprehensionExpr)expr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the advantage of the pattern else if (expr is ComprehensionExpr) {
var e = (ComprehensionExpr)expr; over if (expr is ComprehensionExpr comprehensionExpr) ? |
||
var uncompilableBoundVars = e.UncompilableBoundVars(); | ||
if (uncompilableBoundVars.Count != 0) { | ||
if (ReportErrors == false) { | ||
return false; | ||
} | ||
|
||
string what; | ||
if (comprehensionExpr is SetComprehension comprehension) { | ||
if (e is SetComprehension comprehension) { | ||
what = comprehension.Finite ? "set comprehensions" : "iset comprehensions"; | ||
} else if (comprehensionExpr is MapComprehension mapComprehension) { | ||
} else if (e is MapComprehension mapComprehension) { | ||
what = mapComprehension.Finite ? "map comprehensions" : "imap comprehensions"; | ||
} else { | ||
Contract.Assume(comprehensionExpr is QuantifierExpr); // otherwise, unexpected ComprehensionExpr (since LambdaExpr is handled separately above) | ||
Contract.Assert(((QuantifierExpr)comprehensionExpr).SplitQuantifier == null); // No split quantifiers during resolution | ||
Contract.Assume(e is QuantifierExpr); // otherwise, unexpected ComprehensionExpr (since LambdaExpr is handled separately above) | ||
Contract.Assert(((QuantifierExpr)e).SplitQuantifier == null); // No split quantifiers during resolution | ||
what = "quantifiers"; | ||
} | ||
foreach (var bv in uncompilableBoundVars) { | ||
reporter.Error(MessageSource.Resolver, comprehensionExpr, "{0} in non-ghost contexts must be compilable, but Dafny's heuristics can't figure out how to produce or compile a bounded set of values for '{1}'", what, bv.Name); | ||
reporter?.Error(MessageSource.Resolver, e, "{0} in non-ghost contexts must be compilable, but Dafny's heuristics can't figure out how to produce or compile a bounded set of values for '{1}'", what, bv.Name); | ||
isCompilable = false; | ||
} | ||
return false; | ||
} | ||
// don't recurse down any attributes | ||
if (comprehensionExpr.Range != null) { | ||
isCompilable = CheckIsCompilable(comprehensionExpr.Range, codeContext) && isCompilable; | ||
if (e.Range != null) { | ||
isCompilable = CheckIsCompilable(e.Range, codeContext) && isCompilable; | ||
} | ||
isCompilable = CheckIsCompilable(comprehensionExpr.Term, codeContext) && isCompilable; | ||
isCompilable = CheckIsCompilable(e.Term, codeContext) && isCompilable; | ||
return isCompilable; | ||
|
||
} else if (expr is ChainingExpression chainingExpression) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems redundant given the name
PostVisitOneExpression