-
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
When looking up Core
, pass is_being_declared
as true
#4903
Conversation
@@ -369,6 +369,16 @@ fn F() { | |||
} | |||
} | |||
|
|||
// --- fail_dont_implicitly_poison_core.carbon | |||
|
|||
// CHECK:STDERR: fail_dont_implicitly_poison_core.carbon:[[@LINE+4]]:9: error: `Core.Bool` implicitly referenced here, but package `Core` not found [CoreNotFound] |
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 find this error to be pretty confusing. I would easily try to fix it by trying to understand why Core is not found - is my installation messed up? Where is Core? But of course the answer is I named something Core later in the file.
That said, I think the way we want to resolve this is via https://github.com/carbon-language/carbon-lang/pull/4864/files, which is to make Core a keyword. So the class Core
would not in fact make a class called Core, it would be an invalid use of the Core keyword. Then we should not even have an error here, right?
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.
AFAIU, actually, the reason Core
is not found is because this is a no_prelude
test so Core
is not loaded.
It's not found similar to other no_prelude tests.
This test is different from other tests that trigger this error because it shows that this doesn't cause Core
to be poisoned, unlike #4900.
If Core
is a keyword, we would still have this error.
We might have another error saying that class Core
cannot be defined because Core
is a keyword.
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.
Oh okay, thanks. I misunderstood the relationship to #4900.
The failure looks good then, but worrying about poisoning Core specifically is a transient concern, since we won't be able to write class Core
once we make it a keyword. At that point would we just remove this test? Do you think it's worth adding still as-is?
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.
Changed to class r#Core
.
toolchain/check/context.cpp
Outdated
@@ -703,7 +703,7 @@ static auto GetCorePackage(Context& context, SemIR::LocId loc_id, | |||
// Look up `package.Core`. | |||
auto core_scope_result = context.LookupNameInExactScope( | |||
loc_id, core_name_id, SemIR::NameScopeId::Package, | |||
context.name_scopes().Get(SemIR::NameScopeId::Package)); | |||
context.name_scopes().Get(SemIR::NameScopeId::Package), 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.
I do think this is the right change to make - not sure how the keyword impl shakes out but we don't want to poison things.
context.name_scopes().Get(SemIR::NameScopeId::Package), true); | |
context.name_scopes().Get(SemIR::NameScopeId::Package), /*is_being_declared=*/true); |
But I am not sure how to test this in a way that would survive the keyword change, and welcome thoughts on that.
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.
Done (and changed to r#Core
).
// CHECK:STDERR: | ||
fn F(x: bool); | ||
|
||
class Core {} |
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.
class Core {} | |
class r#Core {} |
Would this test the same thing now - and after the keyword change?
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 believe so, done.
There's an open proposal to make |
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.
Perhaps we should stop using name lookup to find the Core
package. We could instead track the Core
package specially on the SemIR::File
.
This makes sense though I assume there might be complexity cost for special casing |
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.
LGTM
I think other changes made this change different, so I'm moving this to draft. |
…ere's no need to try and poison `Core`. This doesn't change tests since `Core` isn't being poisoned anyways. Part of carbon-language#4622.
Core
Core
, pass is_being_declared
as true
Sorry for the force push, I had to redo this change given recent changes. |
@bricknerb Given #4884, isn't this change a no-op? I ask because also, isn't setting "is_being_declared" when we're doing a non-declaring name lookup a little confusing for future readers? |
Yes!
The name |
I think that |
BTW, LookupNameInDecl sets |
Hm yeah, when I reviewed earlier it was just a test showing that using Core implicitly did not prevent |
Sure, in |
SG, closing. |
There's no need to try and poison
Core
.This doesn't change tests since
Core
isn't being poisoned anyways.Part of #4622.