Skip to content

Commit

Permalink
Rename BindNameInfo to EntityName (#4090)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffromer authored Jul 19, 2024
1 parent 4c6dc2e commit 3266098
Show file tree
Hide file tree
Showing 30 changed files with 135 additions and 125 deletions.
4 changes: 2 additions & 2 deletions toolchain/check/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ static auto LookupInImportIRScopes(Context& context, SemIRLoc loc,
import_ir.sem_ir, import_scope_entry.inst_id);
} else {
// Add the first result found.
auto bind_name_id = context.bind_names().Add(
auto entity_name_id = context.entity_names().Add(
{.name_id = name_id,
.parent_scope_id = scope_id,
.bind_index = SemIR::CompileTimeBindIndex::Invalid});
result_id = AddImportRef(
context,
{.ir_id = import_ir_id, .inst_id = import_scope_entry.inst_id},
bind_name_id);
entity_name_id);
LoadImportRef(context, result_id);
}
}
Expand Down
4 changes: 3 additions & 1 deletion toolchain/check/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ class Context {
auto string_literal_values() -> CanonicalValueStore<StringLiteralValueId>& {
return sem_ir().string_literal_values();
}
auto bind_names() -> SemIR::BindNameStore& { return sem_ir().bind_names(); }
auto entity_names() -> SemIR::EntityNameStore& {
return sem_ir().entity_names();
}
auto functions() -> ValueStore<SemIR::FunctionId>& {
return sem_ir().functions();
}
Expand Down
11 changes: 7 additions & 4 deletions toolchain/check/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ struct EvalContext {

auto ints() -> CanonicalValueStore<IntId>& { return sem_ir().ints(); }
auto floats() -> FloatValueStore& { return sem_ir().floats(); }
auto bind_names() -> SemIR::BindNameStore& { return sem_ir().bind_names(); }
auto entity_names() -> SemIR::EntityNameStore& {
return sem_ir().entity_names();
}
auto functions() -> const ValueStore<SemIR::FunctionId>& {
return sem_ir().functions();
}
Expand Down Expand Up @@ -1322,7 +1324,8 @@ auto TryEvalInstInContext(EvalContext& eval_context, SemIR::InstId inst_id,
break;

case CARBON_KIND(SemIR::BindSymbolicName bind): {
const auto& bind_name = eval_context.bind_names().Get(bind.bind_name_id);
const auto& bind_name =
eval_context.entity_names().Get(bind.entity_name_id);

// If we know which instance we're evaluating within and this is an
// argument of that instance, its constant value is the corresponding
Expand All @@ -1346,8 +1349,8 @@ auto TryEvalInstInContext(EvalContext& eval_context, SemIR::InstId inst_id,

// The constant form of a symbolic binding is an idealized form of the
// original, with no equivalent value.
bind.bind_name_id =
eval_context.bind_names().MakeCanonical(bind.bind_name_id);
bind.entity_name_id =
eval_context.entity_names().MakeCanonical(bind.entity_name_id);
bind.value_id = SemIR::InstId::Invalid;
return MakeConstantResult(eval_context.context, bind, Phase::Symbolic);
}
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/handle_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ auto HandleParseNode(Context& context, Parse::AliasId /*node_id*/) -> bool {
context.decl_introducer_state_stack().Pop<Lex::TokenKind::Alias>();
LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Access);

auto bind_name_id = context.bind_names().Add(
auto entity_name_id = context.entity_names().Add(
{.name_id = name_context.name_id_for_new_inst(),
.parent_scope_id = name_context.parent_scope_id_for_new_inst(),
.bind_index = SemIR::CompileTimeBindIndex::Invalid});
Expand All @@ -61,7 +61,7 @@ auto HandleParseNode(Context& context, Parse::AliasId /*node_id*/) -> bool {
}
auto alias_id = context.AddInst<SemIR::BindAlias>(
name_context.loc_id, {.type_id = alias_type_id,
.bind_name_id = bind_name_id,
.entity_name_id = entity_name_id,
.value_id = alias_value_id});

// Add the name of the binding to the current scope.
Expand Down
14 changes: 7 additions & 7 deletions toolchain/check/handle_binding_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
SemIR::InstId value_id) -> SemIR::LocIdAndInst {
// TODO: Eventually the name will need to support associations with other
// scopes, but right now we don't support qualified names here.
auto bind_name_id = context.bind_names().Add(
auto entity_name_id = context.entity_names().Add(
{.name_id = name_id,
.parent_scope_id = context.scope_stack().PeekNameScopeId(),
// TODO: Don't allocate a compile-time binding index for an associated
Expand All @@ -49,13 +49,13 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
// TODO: Create a `BindTemplateName` instead inside a `template` pattern.
return SemIR::LocIdAndInst(
name_node, SemIR::BindSymbolicName{.type_id = type_id,
.bind_name_id = bind_name_id,
.entity_name_id = entity_name_id,
.value_id = value_id});
} else {
return SemIR::LocIdAndInst(name_node,
SemIR::BindName{.type_id = type_id,
.bind_name_id = bind_name_id,
.value_id = value_id});
return SemIR::LocIdAndInst(
name_node, SemIR::BindName{.type_id = type_id,
.entity_name_id = entity_name_id,
.value_id = value_id});
}
};

Expand Down Expand Up @@ -206,7 +206,7 @@ auto HandleParseNode(Context& context, Parse::AddrId node_id) -> bool {
if (auto self_param =
context.insts().TryGetAs<SemIR::AnyBindName>(self_param_id);
self_param &&
context.bind_names().Get(self_param->bind_name_id).name_id ==
context.entity_names().Get(self_param->entity_name_id).name_id ==
SemIR::NameId::SelfValue) {
// TODO: The type of an `addr_pattern` should probably be the non-pointer
// type, because that's the type that the pattern matches.
Expand Down
8 changes: 4 additions & 4 deletions toolchain/check/handle_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ auto HandleParseNode(Context& context, Parse::ExportDeclId node_id) -> bool {

auto export_id = context.AddInst<SemIR::ExportDecl>(
node_id, {.type_id = import_ref->type_id,
.bind_name_id = import_ref->bind_name_id,
.entity_name_id = import_ref->entity_name_id,
.value_id = inst_id});
context.AddExport(export_id);

// Replace the ImportRef in name lookup, both for the above duplicate
// diagnostic and so that cross-package imports can find it easily.
auto bind_name = context.bind_names().Get(import_ref->bind_name_id);
auto& parent_scope = context.name_scopes().Get(bind_name.parent_scope_id);
auto lookup = parent_scope.name_map.Lookup(bind_name.name_id);
auto entity_name = context.entity_names().Get(import_ref->entity_name_id);
auto& parent_scope = context.name_scopes().Get(entity_name.parent_scope_id);
auto lookup = parent_scope.name_map.Lookup(entity_name.name_id);
auto& scope_inst_id = parent_scope.names[lookup.value()].inst_id;
CARBON_CHECK(scope_inst_id == inst_id);
scope_inst_id = export_id;
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/handle_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ auto HandleParseNode(Context& context,
// We model `Self` as a symbolic binding whose type is the interface.
// Because there is no equivalent non-symbolic value, we use `Invalid` as
// the `value_id` on the `BindSymbolicName`.
auto bind_name_id = context.bind_names().Add(
auto entity_name_id = context.entity_names().Add(
{.name_id = SemIR::NameId::SelfType,
.parent_scope_id = interface_info.scope_id,
.bind_index = context.scope_stack().AddCompileTimeBinding()});
interface_info.self_param_id = context.AddInst<SemIR::BindSymbolicName>(
SemIR::LocId::Invalid, {.type_id = self_type_id,
.bind_name_id = bind_name_id,
.entity_name_id = entity_name_id,
.value_id = SemIR::InstId::Invalid});
context.scope_stack().PushCompileTimeBinding(interface_info.self_param_id);
context.name_scopes().AddRequiredName(interface_info.scope_id,
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/handle_let_and_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static auto BuildAssociatedConstantDecl(Context& context,
// Replace the tentative BindName instruction with the associated constant
// declaration.
auto name_id =
context.bind_names().Get(binding_pattern->bind_name_id).name_id;
context.entity_names().Get(binding_pattern->entity_name_id).name_id;
context.ReplaceLocIdAndInstBeforeConstantUse(
pattern_id,
SemIR::LocIdAndInst(node_id, SemIR::AssociatedConstantDecl{
Expand All @@ -107,7 +107,7 @@ static auto HandleNameBinding(Context& context, SemIR::InstId pattern_id,
// the variable.
auto name_context = context.decl_name_stack().MakeUnqualifiedName(
context.insts().GetLocId(pattern_id),
context.bind_names().Get(bind_name->bind_name_id).name_id);
context.entity_names().Get(bind_name->entity_name_id).name_id);
context.decl_name_stack().AddNameOrDiagnoseDuplicate(
name_context, pattern_id, access_kind);
return bind_name->value_id;
Expand Down
3 changes: 2 additions & 1 deletion toolchain/check/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ static auto BuildInterfaceWitness(
auto self_bind =
context.insts().GetAs<SemIR::BindSymbolicName>(interface.self_param_id);
Substitution substitutions[1] = {
{.bind_id = context.bind_names().Get(self_bind.bind_name_id).bind_index,
{.bind_id =
context.entity_names().Get(self_bind.entity_name_id).bind_index,
.replacement_id = context.types().GetConstantId(impl.self_id)}};

for (auto decl_id : assoc_entities) {
Expand Down
18 changes: 9 additions & 9 deletions toolchain/check/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ static auto GetImportName(const SemIR::File& import_sem_ir,
case SemIR::BindSymbolicName::Kind:
case SemIR::ExportDecl::Kind: {
auto bind_inst = import_inst.As<SemIR::AnyBindNameOrExportDecl>();
const auto& bind_name =
import_sem_ir.bind_names().Get(bind_inst.bind_name_id);
return {bind_name.name_id, bind_name.parent_scope_id};
const auto& entity_name =
import_sem_ir.entity_names().Get(bind_inst.entity_name_id);
return {entity_name.name_id, entity_name.parent_scope_id};
}

case CARBON_KIND(SemIR::ClassDecl class_decl): {
Expand Down Expand Up @@ -156,7 +156,7 @@ static auto CopySingleNameScopeFromImportIR(
SemIR::NameId name_id) -> SemIR::NameScopeId {
// Produce the namespace for the entry.
auto make_import_id = [&]() {
auto bind_name_id = context.bind_names().Add(
auto entity_name_id = context.entity_names().Add(
{.name_id = name_id,
.parent_scope_id = parent_scope_id,
.bind_index = SemIR::CompileTimeBindIndex::Invalid});
Expand All @@ -165,7 +165,7 @@ static auto CopySingleNameScopeFromImportIR(
return context.AddInst<SemIR::ImportRefLoaded>(
import_ir_inst_id, {.type_id = namespace_type_id,
.import_ir_inst_id = import_ir_inst_id,
.bind_name_id = bind_name_id});
.entity_name_id = entity_name_id});
};
auto [namespace_scope_id, namespace_const_id, _] =
AddNamespace(context, namespace_type_id, name_id, parent_scope_id,
Expand Down Expand Up @@ -239,7 +239,7 @@ static auto AddImportRefOrMerge(Context& context, SemIR::ImportIRId ir_id,
// Leave a placeholder that the inst comes from the other IR.
auto& parent_scope = context.name_scopes().Get(parent_scope_id);
auto insert = parent_scope.name_map.Insert(name_id, [&] {
auto bind_name_id = context.bind_names().Add(
auto entity_name_id = context.entity_names().Add(
{.name_id = name_id,
.parent_scope_id = parent_scope_id,
.bind_index = SemIR::CompileTimeBindIndex::Invalid});
Expand All @@ -248,7 +248,7 @@ static auto AddImportRefOrMerge(Context& context, SemIR::ImportIRId ir_id,
{.name_id = name_id,
.inst_id =
AddImportRef(context, {.ir_id = ir_id, .inst_id = import_inst_id},
bind_name_id),
entity_name_id),
.access_kind = SemIR::AccessKind::Public});
return index;
});
Expand Down Expand Up @@ -310,14 +310,14 @@ static auto ImportScopeFromApiFile(Context& context,
.impl_parent_scope_id = impl_scope_id});
} else {
// Add an ImportRef for other instructions.
auto impl_bind_name_id = context.bind_names().Add(
auto impl_entity_name_id = context.entity_names().Add(
{.name_id = impl_name_id,
.parent_scope_id = impl_scope_id,
.bind_index = SemIR::CompileTimeBindIndex::Invalid});
auto import_ref_id = AddImportRef(context,
{.ir_id = SemIR::ImportIRId::ApiForImpl,
.inst_id = api_entry.inst_id},
impl_bind_name_id);
impl_entity_name_id);
impl_scope.AddRequired({.name_id = impl_name_id,
.inst_id = import_ref_id,
.access_kind = api_entry.access_kind});
Expand Down
32 changes: 16 additions & 16 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ auto AddImportIR(Context& context, SemIR::ImportIR import_ir)
}

auto AddImportRef(Context& context, SemIR::ImportIRInst import_ir_inst,
SemIR::BindNameId bind_name_id) -> SemIR::InstId {
SemIR::EntityNameId entity_name_id) -> SemIR::InstId {
auto import_ir_inst_id = context.import_ir_insts().Add(import_ir_inst);
SemIR::ImportRefUnloaded inst = {.import_ir_inst_id = import_ir_inst_id,
.bind_name_id = bind_name_id};
.entity_name_id = entity_name_id};
auto import_ref_id = context.AddPlaceholderInstInNoBlock(
SemIR::LocIdAndInst(import_ir_inst_id, inst));

Expand Down Expand Up @@ -114,7 +114,7 @@ auto VerifySameCanonicalImportIRInst(Context& context, SemIR::InstId prev_id,
}
auto conflict_id =
AddImportRef(context, {.ir_id = new_ir_id, .inst_id = new_inst_id},
SemIR::BindNameId::Invalid);
SemIR::EntityNameId::Invalid);
context.DiagnoseDuplicateName(conflict_id, prev_id);
}

Expand Down Expand Up @@ -519,13 +519,13 @@ class ImportRefResolver {
if (bind_inst) {
switch (bind_inst->kind) {
case SemIR::BindName::Kind: {
auto bind_name_id = context_.bind_names().Add(
auto entity_name_id = context_.entity_names().Add(
{.name_id = name_id,
.parent_scope_id = SemIR::NameScopeId::Invalid,
.bind_index = SemIR::CompileTimeBindIndex::Invalid});
new_param_id = context_.AddInstInNoBlock<SemIR::BindName>(
AddImportIRInst(bind_id), {.type_id = type_id,
.bind_name_id = bind_name_id,
.entity_name_id = entity_name_id,
.value_id = new_param_id});
break;
}
Expand Down Expand Up @@ -648,7 +648,7 @@ class ImportRefResolver {
for (auto entry : import_scope.names) {
auto ref_id = AddImportRef(
context_, {.ir_id = import_ir_id_, .inst_id = entry.inst_id},
SemIR::BindNameId::Invalid);
SemIR::EntityNameId::Invalid);
new_scope.AddRequired({.name_id = GetLocalNameId(entry.name_id),
.inst_id = ref_id,
.access_kind = entry.access_kind});
Expand All @@ -669,7 +669,7 @@ class ImportRefResolver {
for (auto inst_id : associated_entities) {
new_associated_entities.push_back(
AddImportRef(context_, {.ir_id = import_ir_id_, .inst_id = inst_id},
SemIR::BindNameId::Invalid));
SemIR::EntityNameId::Invalid));
}
return context_.inst_blocks().Add(new_associated_entities);
}
Expand Down Expand Up @@ -810,7 +810,7 @@ class ImportRefResolver {
// Add a lazy reference to the target declaration.
auto decl_id = AddImportRef(
context_, {.ir_id = import_ir_id_, .inst_id = inst.decl_id},
SemIR::BindNameId::Invalid);
SemIR::EntityNameId::Invalid);

return ResolveAs<SemIR::AssociatedEntity>(
{.type_id = context_.GetTypeIdForTypeConstant(type_const_id),
Expand Down Expand Up @@ -873,16 +873,16 @@ class ImportRefResolver {
return ResolveResult::Retry();
}

const auto& import_bind_info =
import_ir_.bind_names().Get(inst.bind_name_id);
auto name_id = GetLocalNameId(import_bind_info.name_id);
auto bind_name_id = context_.bind_names().Add(
const auto& import_entity_name =
import_ir_.entity_names().Get(inst.entity_name_id);
auto name_id = GetLocalNameId(import_entity_name.name_id);
auto entity_name_id = context_.entity_names().Add(
{.name_id = name_id,
.parent_scope_id = SemIR::NameScopeId::Invalid,
.bind_index = import_bind_info.bind_index});
.bind_index = import_entity_name.bind_index});
return ResolveAs<SemIR::BindSymbolicName>(
{.type_id = context_.GetTypeIdForTypeConstant(type_id),
.bind_name_id = bind_name_id,
.entity_name_id = entity_name_id,
.value_id = SemIR::InstId::Invalid});
}

Expand Down Expand Up @@ -1603,7 +1603,7 @@ auto LoadImportRef(Context& context, SemIR::InstId inst_id) -> void {
inst_id,
SemIR::ImportRefLoaded{.type_id = type_id,
.import_ir_inst_id = inst->import_ir_inst_id,
.bind_name_id = inst->bind_name_id});
.entity_name_id = inst->entity_name_id});

// Store the constant for both the ImportRefLoaded and indirect instructions.
context.constant_values().Set(inst_id, constant_id);
Expand Down Expand Up @@ -1633,7 +1633,7 @@ static auto ImportImpl(Context& context, SemIR::ImportIRId import_ir_id,
auto& impl = context.impls().Get(impl_id);
impl.witness_id = AddImportRef(
context, {.ir_id = import_ir_id, .inst_id = import_impl.witness_id},
SemIR::BindNameId::Invalid);
SemIR::EntityNameId::Invalid);
}
}

Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/import_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ auto AddImportIR(Context& context, SemIR::ImportIR import_ir)
// Adds an import_ref instruction for the specified instruction in the
// specified IR. The import_ref is initially marked as unused.
auto AddImportRef(Context& context, SemIR::ImportIRInst import_ir_inst,
SemIR::BindNameId bind_name_id) -> SemIR::InstId;
SemIR::EntityNameId entity_name_id) -> SemIR::InstId;

// Returns the canonical IR inst for an entity. Returns an invalid ir_id for the
// current IR.
Expand Down
3 changes: 2 additions & 1 deletion toolchain/check/member_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ static auto PerformImplLookup(Context& context, Parse::NodeId node_id,
auto self_param =
context.insts().GetAs<SemIR::BindSymbolicName>(interface.self_param_id);
Substitution substitutions[1] = {
{.bind_id = context.bind_names().Get(self_param.bind_name_id).bind_index,
{.bind_id =
context.entity_names().Get(self_param.entity_name_id).bind_index,
.replacement_id = type_const_id}};
auto subst_type_id =
SubstType(context, assoc_type.entity_type_id, substitutions);
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/subst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class SubstConstantCallbacks final : public SubstInstCallbacks {
// TODO: Consider building a hash map for substitutions. We might have a
// lot of them.
for (auto [bind_index, replacement_id] : substitutions_) {
if (context_.bind_names().Get(bind->bind_name_id).bind_index ==
if (context_.entity_names().Get(bind->entity_name_id).bind_index ==
bind_index) {
// This is the binding we're replacing. Perform substitution.
inst_id = context_.constant_values().GetInstId(replacement_id);
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/testdata/basics/builtin_insts.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK:STDOUT: import_ir_insts: {}
// CHECK:STDOUT: name_scopes:
// CHECK:STDOUT: name_scope0: {inst: inst+0, parent_scope: name_scope<invalid>, has_error: false, extended_scopes: [], names: {}}
// CHECK:STDOUT: bind_names: {}
// CHECK:STDOUT: entity_names: {}
// CHECK:STDOUT: functions: {}
// CHECK:STDOUT: classes: {}
// CHECK:STDOUT: generics: {}
Expand Down
Loading

0 comments on commit 3266098

Please sign in to comment.