-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
generate symchoice for ambiguous types in templates & generics + handle types in symchoices #23997
Merged
Conversation
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
Araq
reviewed
Aug 21, 2024
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
narimiran
pushed a commit
that referenced
this pull request
Sep 16, 2024
…le types in symchoices (#23997) fixes #23898, supersedes #23966 and #23990 Since #20631 ambiguous type symbols in templates are rejected outright, now we generate a symchoice for type nodes if they're ambiguous, a generalization of what was done in #22375. This is done for generics as well. Symchoices also handle type symbols better now, ensuring their type is a `typedesc` type; this probably isn't necessary for everything to work but it makes the logic more robust. Similar to #23989, we have to prepare for the fact that ambiguous type symbols behave differently than normal type symbols and either error normally or relegate to other routine symbols if the symbol is being called. Generating a symchoice emulates this behavior, `semExpr` will find the type symbol first, but since the symchoice has other symbols, it will count as an ambiguous type symbol. I know it seems spammy to carry around an ambiguity flag everywhere, but in the future when we have something like #23104 we could just always generate a symchoice, and the symchoice itself would carry the info of whether the first symbol was ambiguous. But this could harm compiler performance/memory use, it might be better to generate it only when we have to, which in the case of type symbols is only when they're ambiguous. (cherry picked from commit 09dcff7)
metagn
added a commit
to metagn/Nim
that referenced
this pull request
Sep 26, 2024
Araq
pushed a commit
that referenced
this pull request
Sep 27, 2024
…24180) fixes #19866 given #23997 When searching for a module-qualified symbol, `qualifiedLookUp` tries to obtain the raw identifier from the RHS of the dot field. However it only does this when the RHS is either an `nkIdent` or an `nkAccQuoted` node, not when the node is a resolved symbol or a symchoice, such as in templates and generics when the module symbol can't be resolved yet. Since the LHS is a module symbol when the compiler checks for this, any resolved symbol information doesn't matter, since it has to be a member of the module. So we now obtain the identifier from these nodes as well as the unresolved identifier nodes. The test is a bit niche and possibly not officially supported, but this is likely a more general problem and I just couldn't think of another test that would be more "proper". It's better than the error message `'a' has no type` at least.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fixes #23898, supersedes #23966 and #23990
Since #20631 ambiguous type symbols in templates are rejected outright, now we generate a symchoice for type nodes if they're ambiguous, a generalization of what was done in #22375. This is done for generics as well. Symchoices also handle type symbols better now, ensuring their type is a
typedesc
type; this probably isn't necessary for everything to work but it makes the logic more robust.Similar to #23989, we have to prepare for the fact that ambiguous type symbols behave differently than normal type symbols and either error normally or relegate to other routine symbols if the symbol is being called. Generating a symchoice emulates this behavior,
semExpr
will find the type symbol first, but since the symchoice has other symbols, it will count as an ambiguous type symbol.I know it seems spammy to carry around an ambiguity flag everywhere, but in the future when we have something like #23104 we could just always generate a symchoice, and the symchoice itself would carry the info of whether the first symbol was ambiguous. But this could harm compiler performance/memory use, it might be better to generate it only when we have to, which in the case of type symbols is only when they're ambiguous.