From 524a6337f4d5570156ea284681f7aa7c0c2a948f Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Wed, 19 Feb 2025 11:46:23 -0800 Subject: [PATCH] Improve decl_name_stack comments (#4977) Trying to make it clearer what these correspond to. Had suggested a small edit on https://github.com/carbon-language/carbon-lang/pull/4902/files#r1960682518, but since that was missed, suggesting an incrementally larger edit since `name_id` and `loc_id` are now more tied. --- toolchain/check/decl_name_stack.cpp | 4 +--- toolchain/check/decl_name_stack.h | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/toolchain/check/decl_name_stack.cpp b/toolchain/check/decl_name_stack.cpp index ac1d299fc917..9045065f46a9 100644 --- a/toolchain/check/decl_name_stack.cpp +++ b/toolchain/check/decl_name_stack.cpp @@ -255,10 +255,8 @@ auto DeclNameStack::ApplyNameQualifier(const NameComponent& name) -> void { auto DeclNameStack::ApplyAndLookupName(NameContext& name_context, SemIR::LocId loc_id, SemIR::NameId name_id) -> void { - // The location of the name is the location of the last name token we've - // processed so far. + // Update the final name component. name_context.loc_id = loc_id; - name_context.name_id = name_id; // Don't perform any more lookups after we hit an error. We still track the diff --git a/toolchain/check/decl_name_stack.h b/toolchain/check/decl_name_stack.h index 74b60811e430..a7988d714414 100644 --- a/toolchain/check/decl_name_stack.h +++ b/toolchain/check/decl_name_stack.h @@ -145,9 +145,12 @@ class DeclNameStack { // should be used. SemIR::NameScopeId parent_scope_id; - // The last location ID used. + // The location of the final name component. SemIR::LocId loc_id = SemIR::LocId::None; + // The name of the final name component. + SemIR::NameId name_id = SemIR::NameId::None; + union { // The ID of a resolved qualifier, including both identifiers and // expressions. `None` indicates resolution failed. @@ -157,9 +160,6 @@ class DeclNameStack { // the poisoning location. SemIR::LocId poisoning_loc_id = SemIR::LocId::None; }; - - // The ID of an identifier. - SemIR::NameId name_id = SemIR::NameId::None; }; // Information about a declaration name that has been temporarily removed from