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

[NFC] In DeclNameStack::AddName(), use NameScope::AddRequired() instead of duplicating its logic #4610

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions toolchain/check/decl_name_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,9 @@ auto DeclNameStack::AddName(NameContext name_context, SemIR::InstId target_id,
context_->AddExport(target_id);
}

auto add_scope = [&] {
int index = name_scope.names.size();
name_scope.names.push_back(
{.name_id = name_context.unresolved_name_id,
.inst_id = target_id,
.access_kind = access_kind});
return index;
};
auto result = name_scope.name_map.Insert(
name_context.unresolved_name_id, add_scope);
CARBON_CHECK(
result.is_inserted(),
"Duplicate names should have been resolved previously: {0} in {1}",
Copy link
Contributor

@danakj danakj Dec 2, 2024

Choose a reason for hiding this comment

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

I was going to approve, but I see the diagnostic is changed.
The diagnostic on duplicate entry before:
"Duplicate names should have been resolved previously: {unresolved_name_id} in {parent_scope_id}"
The diagnostic on duplicate now:
"Failed to add required name: {unresolved_name_id}"

Maybe that's fine, or maybe we should pass in the parent scope id, not sure so I'll let someone else review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this is a crash diagnostic, so not expected to occur unless there's a bug in the compiler logic.

name_context.unresolved_name_id, name_context.parent_scope_id);
name_scope.AddRequired({.name_id = name_context.unresolved_name_id,
.inst_id = target_id,
.access_kind = access_kind});
}
break;

Expand Down
Loading