-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CSGen] Turn invalid decls into holes #34584
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
Upon attempt to generate constraints for invalid declaration reference let's turn that into a hole and record this new fix to diagnose it once solution has been reached.
If AST node is a reference to an invalid declaration let's diagnose it as such unless some errors have been emitted (invalid declaration itself should have a diagnostic describing a reason why it's invalid).
Instead of failing constraint generation upon encountering an invalid declaration, let's turn that declaration into a potential hole and keep going. Doing so enables the solver to reach a solution and diagnose any other issue with expression.
@nathawes I believe that this is going to help code completion, maybe we have a few test-cases we could add to showcase that? |
@swift-ci please test |
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.
Looks great! Just one question below
// If no errors have been emitted yet, let's emit one | ||
// about reference to an invalid declaration. | ||
|
||
emitDiagnostic(diag::reference_to_invalid_decl, decl->getName()); |
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.
When would the solver actually emit this error?
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.
In cases when actual problem with declaration hasn't been diagnosed due to a bug (hopefully never).
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.
I was thinking about adding bit about asking to report it just like we do with actual fallback diagnostic.
@@ -1227,9 +1227,11 @@ namespace { | |||
if (knownType) { |
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.
Just above this, within the CS.getVarType(VD)
call it's getting the type of VD and replacing any ErrorTypes it contains with holes when CS.isForCodeCompletion is true. Does this change make that logic redundant?
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.
I think for code completion we'd want to preserve as much structure as possible so replacing everything with a single hole might not be the best way... I was thinking more of a second case where E->getDecl()->isInvalid()
is true.
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.
If it is, could we remove it and make the below behave the same way, preserving any wrapping types? (e.g. [ErrorType]
becomes [<hole>]
rather than just <hole>
?
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.
Didn't see your reply before I sent that, sorry.
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.
I guess I could try to unify logic here to preserve some more structure for diagnostics, I'll give it a try!
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.
I looked into this some more and it looks like for solver and diagnostics in particular it make more sense to keep invalid declarations represented as type variables so they could assume any time from context instead otherwise we'd risk diagnosing issues which are effectively already diagnosed while validating declarations...
Instead of failing constraint generation upon encountering
an invalid declaration, let's turn that declaration into a
potential hole and keep going. Doing so enables the solver
to reach a solution and diagnose any other issue with
expression.
Resolves: rdar://70880670