Rename SemIR::Node to SemIR::Inst (#3355)

And generally replace "node" by "inst" in the code and "instruction" in
comments.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
josh11b
2023-11-02 17:58:30 +00:00
committed by GitHub
co-authored by Chandler Carruth
parent 35c2142392
commit 7edfd8e02a
63 changed files with 2136 additions and 2115 deletions
+23 -22
View File
@@ -43,12 +43,12 @@ auto DeclarationNameStack::Pop() -> NameContext {
}
auto DeclarationNameStack::LookupOrAddName(NameContext name_context,
SemIR::NodeId target_id)
-> SemIR::NodeId {
SemIR::InstId target_id)
-> SemIR::InstId {
switch (name_context.state) {
case NameContext::State::Error:
// The name is invalid and a diagnostic has already been emitted.
return SemIR::NodeId::Invalid;
return SemIR::InstId::Invalid;
case NameContext::State::Empty:
CARBON_FATAL() << "Name is missing, not expected to call AddNameToLookup "
@@ -56,7 +56,7 @@ auto DeclarationNameStack::LookupOrAddName(NameContext name_context,
case NameContext::State::Resolved:
case NameContext::State::ResolvedNonScope:
return name_context.resolved_node_id;
return name_context.resolved_inst_id;
case NameContext::State::Unresolved:
if (name_context.target_scope_id == SemIR::NameScopeId::Invalid) {
@@ -73,15 +73,15 @@ auto DeclarationNameStack::LookupOrAddName(NameContext name_context,
<< name_context.unresolved_name_id << " in "
<< name_context.target_scope_id;
}
return SemIR::NodeId::Invalid;
return SemIR::InstId::Invalid;
}
}
auto DeclarationNameStack::AddNameToLookup(NameContext name_context,
SemIR::NodeId target_id) -> void {
auto existing_node_id = LookupOrAddName(name_context, target_id);
if (existing_node_id.is_valid()) {
context_->DiagnoseDuplicateName(name_context.parse_node, existing_node_id);
SemIR::InstId target_id) -> void {
auto existing_inst_id = LookupOrAddName(name_context, target_id);
if (existing_inst_id.is_valid()) {
context_->DiagnoseDuplicateName(name_context.parse_node, existing_inst_id);
}
}
@@ -95,22 +95,23 @@ auto DeclarationNameStack::ApplyNameQualifierTo(NameContext& name_context,
StringId name_id) -> void {
if (CanResolveQualifier(name_context, parse_node)) {
// For identifier nodes, we need to perform a lookup on the identifier.
// This means the input node_id is actually a string ID.
// This means the input instruction name_id is actually a string ID.
//
// TODO: This doesn't perform the right kind of lookup. We will find names
// from enclosing lexical scopes here, in the case where `target_scope_id`
// is invalid.
auto resolved_node_id = context_->LookupName(
auto resolved_inst_id = context_->LookupName(
name_context.parse_node, name_id, name_context.target_scope_id,
/*print_diagnostics=*/false);
if (resolved_node_id == SemIR::NodeId::BuiltinError) {
// Invalid indicates an unresolved node. Store it and return.
if (resolved_inst_id == SemIR::InstId::BuiltinError) {
// Invalid indicates an unresolved instruction. Store it and return.
name_context.state = NameContext::State::Unresolved;
name_context.unresolved_name_id = name_id;
return;
} else {
// Store the resolved node and continue for the target scope update.
name_context.resolved_node_id = resolved_node_id;
// Store the resolved instruction and continue for the target scope
// update.
name_context.resolved_inst_id = resolved_inst_id;
}
UpdateScopeIfNeeded(name_context);
@@ -119,13 +120,13 @@ auto DeclarationNameStack::ApplyNameQualifierTo(NameContext& name_context,
auto DeclarationNameStack::UpdateScopeIfNeeded(NameContext& name_context)
-> void {
// This will only be reached for resolved nodes. We update the target
// This will only be reached for resolved instructions. We update the target
// scope based on the resolved type.
auto resolved_node = context_->nodes().Get(name_context.resolved_node_id);
switch (resolved_node.kind()) {
auto resolved_inst = context_->insts().Get(name_context.resolved_inst_id);
switch (resolved_inst.kind()) {
case SemIR::ClassDeclaration::Kind: {
const auto& class_info = context_->classes().Get(
resolved_node.As<SemIR::ClassDeclaration>().class_id);
resolved_inst.As<SemIR::ClassDeclaration>().class_id);
if (class_info.is_defined()) {
name_context.state = NameContext::State::Resolved;
name_context.target_scope_id = class_info.scope_id;
@@ -137,7 +138,7 @@ auto DeclarationNameStack::UpdateScopeIfNeeded(NameContext& name_context)
case SemIR::Namespace::Kind:
name_context.state = NameContext::State::Resolved;
name_context.target_scope_id =
resolved_node.As<SemIR::Namespace>().name_scope_id;
resolved_inst.As<SemIR::Namespace>().name_scope_id;
break;
default:
name_context.state = NameContext::State::ResolvedNonScope;
@@ -163,8 +164,8 @@ auto DeclarationNameStack::CanResolveQualifier(NameContext& name_context,
case NameContext::State::ResolvedNonScope: {
// Because more qualifiers were found, we diagnose that the earlier
// qualifier didn't resolve to a scoped entity.
if (auto class_decl = context_->nodes()
.Get(name_context.resolved_node_id)
if (auto class_decl = context_->insts()
.Get(name_context.resolved_inst_id)
.TryAs<SemIR::ClassDeclaration>()) {
CARBON_DIAGNOSTIC(QualifiedDeclarationInIncompleteClassScope, Error,
"Cannot declare a member of incomplete class `{0}`.",