-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Lookup using private discriminators should still find public things. #4238
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
Lookup using private discriminators should still find public things. #4238
Conversation
Private and fileprivate declarations have a special "private discriminator" to keep them from colliding with declarations with the same signature in another file. The debugger uses this to prefer declarations in the file you're currently stopped in when running the expression parser. Unfortunately, the current logic didn't just prefer declarations in the current file---it /only/ took declarations in the current file, as long as there weren't zero. The fixed version will include any declarations in the current file plus any declarations with 'internal' or broader access. (Really we shouldn't do this at the lookup level at all; it should just be a tie-breaker in solution ranking in the constraint solver. But that would be a more intrusive change.) rdar://problem/27015195
Note that the compiler itself does not perform lookup using private discriminators, and direct lookup using a discriminator still only finds things with a matching discriminator. @jimingham or @scallanan, can you review this, both that it's the desired semantics and that the implementation looks correct? (CI is busted right now, so I'll start tests later.) |
@swift-ci Please test |
I understand the distinction that's being made in your patch, but I don't understand the iterator dance that's taking place. It looks like this code
returns out with nothing if nothing answered "Matches;" weren't we trying to make it so we'd return out with something when something answers "NoDiscriminator?" |
Ah, the first loop says "if there's nothing in the lookup results that comes from this file specifically, leave them alone [even if they contain private results from other files]". The second loop says "given that some decls are from this file specifically, remove any decls that are specifically from another file [but leave |
I made a little example with one module with two files, one having a fileprivate == and another having a private ==, and then another module that uses the first with another ==, all for the same type, and it looks like lldb expressions all get the right operators in the appropriate contexts. Plus you can use other unrelated "==" operators like for Ints and Strings. I have to poke around some more to make sure I understand what I'm seeing for sure, but it looks like this is indeed doing the right thing for lldb. |
That's what I was trying to get at with the |
@swift-ci Please test Linux platform |
…wiftlang#4238) Private and fileprivate declarations have a special "private discriminator" to keep them from colliding with declarations with the same signature in another file. The debugger uses this to prefer declarations in the file you're currently stopped in when running the expression parser. Unfortunately, the current logic didn't just prefer declarations in the current file---it /only/ took declarations in the current file, as long as there weren't zero. The fixed version will include any declarations in the current file plus any declarations with 'internal' or broader access. (Really we shouldn't do this at the lookup level at all; it should just be a tie-breaker in solution ranking in the constraint solver. But that would be a more intrusive change.) rdar://problem/27015195 (cherry picked from commit cd7c802)
private
andfileprivate
declarations have a special "private discriminator" to keep them from colliding with declarations with the same signature in another file. The debugger uses this to prefer declarations in the file you're currently stopped in when running the expression parser. Unfortunately, the current logic didn't just prefer declarations in the current file---it only took declarations in the current file, as long as there weren't zero. The fixed version will include any declarations in the current file plus any declarations withinternal
or broader access.(Really we shouldn't do this at the lookup level at all; it should just be a tie-breaker in solution ranking in the constraint solver. But that would be a more intrusive change.)
rdar://problem/27015195
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.