Skip to content
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

Perform member lookup on FacetAccessType #5058

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Mar 3, 2025

The name scope lookup and member name lookup both need to handle the case where the base inst is a FacetAccessType. Then we move from the FacetAccessType to the FacetType which is the type of the instruction inside the FacetAccessType.

We do name lookup on FacetType already, so "unwrapping" the FacetAccessType to the FacetType just makes use of that path. Similarly we do member access on FacetType already, so we can reuse that codepath with the FacetType found in the FacetAccessType.

The name scope lookup and member name lookup both need to handle the
case where the base inst is a FacetAccessType. Then we move from the
FacetAccessType to the FacetType which is the type of the instruction
inside the FacetAccessType.

We do name lookup on FacetType already, so "unwrapping" the
FacetAccessType to the FacetType just makes use of that path.
Similarly we do member access on FacetType already, so we can reuse that
codepath with the FacetType found in the FacetAccessType.
@github-actions github-actions bot requested a review from josh11b March 3, 2025 19:40
Comment on lines 506 to 510
if (auto facet_type = context.insts().TryGetAs<SemIR::BindSymbolicName>(
context.constant_values().GetInstId(base_type_const_id))) {
llvm::errs() << "hi\n";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm expecting this wasn't meant to be left in the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh argh no, this was giving me a place to breakpoint. Removing

@@ -234,6 +234,19 @@ auto AppendLookupScopesForConstant(Context& context, SemIR::LocId loc_id,
-> bool {
auto base_id = context.constant_values().GetInstId(base_const_id);
auto base = context.insts().Get(base_id);

if (auto base_as_facet_access_type = base.TryAs<SemIR::FacetAccessType>()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be this PR, but this is starting to look like a common operation (#5060 should possibly also do this) that I wonder if it could be moved into its own function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with moving it to another function is that in both cases we are also overwriting/replacing a few other derived variables, like here the base_const_id which also requires changing base_id and base, and in the other case base_id which requires changing base_type_id. In one case the resulting inst is directly from the FacetAccessType and in the other its from the constant value of that inst (because we needed a constant value first).

Maybe we could unconditionally get the constant value and return that inst and its type as a pair or something? I'm not sure - let's leave it out of this PR at least

@danakj danakj enabled auto-merge March 3, 2025 20:13
@danakj danakj added this pull request to the merge queue Mar 3, 2025
Merged via the queue into carbon-language:trunk with commit 2d1bfca Mar 3, 2025
8 checks passed
@danakj danakj deleted the access-facetaccesstype branch March 3, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants