Change name poisoning implementation to allow better diagnostics (#4764)

Change the implementation to use an explicit `is_poisoned` bit instead
of `InstId::PoisonedName` value.
Zero behavior change.
This would allow to more easily change the API to support accessing the
poisoning declaration so we can have better name poisoning diagnosis.
#4622
This commit is contained in:
Boaz Brickner
2025-01-08 08:36:14 +00:00
committed by GitHub
parent 246ec785df
commit 74395ce693
18 changed files with 127 additions and 111 deletions
+8 -8
View File
@@ -123,11 +123,6 @@ static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id,
return;
}
if (prev_id.is_poisoned()) {
context.DiagnosePoisonedName(function_info.latest_decl_id());
return;
}
auto prev_function_id = SemIR::FunctionId::Invalid;
auto prev_import_ir_id = SemIR::ImportIRId::Invalid;
CARBON_KIND_SWITCH(context.insts().Get(prev_id)) {
@@ -253,8 +248,12 @@ static auto BuildFunctionDecl(Context& context,
function_info.definition_id = decl_id;
}
TryMergeRedecl(context, node_id, name_context.prev_inst_id(), function_decl,
function_info, is_definition);
if (name_context.state == DeclNameStack::NameContext::State::Poisoned) {
context.DiagnosePoisonedName(function_info.latest_decl_id());
} else {
TryMergeRedecl(context, node_id, name_context.prev_inst_id(), function_decl,
function_info, is_definition);
}
// Create a new function if this isn't a valid redeclaration.
if (!function_decl.function_id.is_valid()) {
@@ -285,7 +284,8 @@ static auto BuildFunctionDecl(Context& context,
// Check if we need to add this to name lookup, now that the function decl is
// done.
if (!name_context.prev_inst_id().is_valid()) {
if (name_context.state != DeclNameStack::NameContext::State::Poisoned &&
!name_context.prev_inst_id().is_valid()) {
// At interface scope, a function declaration introduces an associated
// function.
auto lookup_result_id = decl_id;