-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
apple/swift-lldb#2058 |
@swift-ci please test source compatibility |
@@ -4915,6 +4908,9 @@ class VarDecl : public AbstractStorageDecl { | |||
Parent = v; | |||
} | |||
|
|||
NamedPattern *getNamingPattern() const { return NamingPattern; } |
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.
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.
Build failed |
Build failed |
apple/swift-lldb#2058 |
61d7236
to
e27f932
Compare
apple/swift-lldb#2058 |
@swift-ci please test source compatibility |
Build failed |
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.
The Sourcery failure doesn't appear to be mine. Gonna rebase and try again. |
e27f932
to
e4bf3a6
Compare
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.
e4bf3a6
to
0082ba5
Compare
@swift-ci please smoke test |
apple/swift-lldb#2058 |
@swift-ci please test source compatibility Debug |
UPASS! ⛵️ |
Because of the cleanup in swiftlang#27648, it is now possible to just grab the right type repr here.
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.