Skip to content

Drastically Simplify VarDecl Validation #27648

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

Merged
merged 4 commits into from
Oct 14, 2019

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Oct 12, 2019

This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl. Instead, replace it with the
notion of a "naming pattern". This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs. This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl. Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 12, 2019

apple/swift-lldb#2058
@swift-ci please test

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 12, 2019

@swift-ci please test source compatibility

@CodaFi CodaFi closed this Oct 12, 2019
@CodaFi CodaFi reopened this Oct 12, 2019
@@ -4915,6 +4908,9 @@ class VarDecl : public AbstractStorageDecl {
Parent = v;
}

NamedPattern *getNamingPattern() const { return NamingPattern; }
Copy link
Contributor Author

@CodaFi CodaFi Oct 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming pattern is a compromise and a cache. We could absolutely requestify this and have it computed by rooting around in the parent pattern (binding) for the NamedPattern that has us/our canonical var as its decl.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 61d72360ca915304874004e58e891003f0272855

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 61d72360ca915304874004e58e891003f0272855

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 12, 2019

apple/swift-lldb#2058
@swift-ci please test

@CodaFi CodaFi force-pushed the unbounded-progress branch from 61d7236 to e27f932 Compare October 13, 2019 18:19
@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 13, 2019

apple/swift-lldb#2058
@swift-ci please test

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 13, 2019

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e27f932bd7f233ffd0a6788709c701e7260f8614

VarDecls inherit their TypeRepr from their enclosing pattern, if any.
To retrieve the TypeRepr attached to a VarDecl or a ParamDecl in
a uniform way, the getTypeReprOrParentPatternTypeRepr API has been
provided.
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
Overload resolution performs a lookup rooted at a pattern binding's
initializer that scoops up the var decl bound by the pattern.  This
forces it to validate the variable while type checking said variable's
initializer.  The old answer to this problem was to skip validation
which returns a temporary ErrorType.  We should patch lookup so it
doesn't consider these variables.
@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 14, 2019

The Sourcery failure doesn't appear to be mine. Gonna rebase and try again.

@CodaFi CodaFi force-pushed the unbounded-progress branch from e27f932 to e4bf3a6 Compare October 14, 2019 19:45
Inline the interface type reset into its callers and make sure they're
also setting the invalid bit - which this was not doing before.
Unfortunately, this is not enough to be able to simplify any part of var
decl validation.
@CodaFi CodaFi force-pushed the unbounded-progress branch from e4bf3a6 to 0082ba5 Compare October 14, 2019 19:46
@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 14, 2019

@swift-ci please smoke test

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 14, 2019

apple/swift-lldb#2058
@swift-ci please smoke test

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 14, 2019

@swift-ci please test source compatibility Debug

@CodaFi
Copy link
Contributor Author

CodaFi commented Oct 14, 2019

UPASS!

⛵️

@CodaFi CodaFi merged commit 3bd45c8 into swiftlang:master Oct 14, 2019
@CodaFi CodaFi deleted the unbounded-progress branch October 14, 2019 23:55
CodaFi added a commit to CodaFi/swift that referenced this pull request Oct 15, 2019
Because of the cleanup in swiftlang#27648, it is now possible to just grab the
right type repr here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants