Call GetAttached less frequently in import (#6350)

This has subtle effects on the number of imported instructions, but
seems more standard for how this code is being written...
`GetLocalConstantId` calls `GetLocalConstantValueOrPush` which does
`local_constant_values_for_import_insts().GetAttached`. So what this is
really doing is causing some intermediate import steps to be skipped.
But per test changes, that doesn't really affect SemIR and will probably
have negligible effect. This *seems* right to me, otherwise I'd expect
we should probably refactor all `GetLocalConstantId(InstId)` calls.
This commit is contained in:
Jon Ross-Perkins
2025-11-12 00:12:46 +00:00
committed by GitHub
parent 43ffd721a4
commit 8ba0274e81
2 changed files with 433 additions and 436 deletions
+10 -17
View File
@@ -1343,9 +1343,8 @@ static auto ResolveAsUnique(ImportRefResolver& resolver,
static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::AdaptDecl inst,
SemIR::InstId import_inst_id) -> ResolveResult {
auto adapted_type_const_id = GetLocalConstantId(
resolver,
resolver.import_constant_values().GetAttached(inst.adapted_type_inst_id));
auto adapted_type_const_id =
GetLocalConstantId(resolver, inst.adapted_type_inst_id);
if (resolver.HasNewWork()) {
return ResolveResult::Retry();
}
@@ -1528,9 +1527,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
SemIR::BaseDecl inst,
SemIR::InstId import_inst_id) -> ResolveResult {
auto type_const_id = GetLocalConstantId(resolver, inst.type_id);
auto base_type_const_id = GetLocalConstantId(
resolver,
resolver.import_constant_values().GetAttached(inst.base_type_inst_id));
auto base_type_const_id =
GetLocalConstantId(resolver, inst.base_type_inst_id);
if (resolver.HasNewWork()) {
return ResolveResult::Retry();
}
@@ -2164,9 +2162,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
llvm::SmallVector<SemIR::InstId> lazy_virtual_functions;
lazy_virtual_functions.reserve(virtual_functions.size());
for (auto vtable_entry_id : virtual_functions) {
auto local_attached_constant_id = GetLocalConstantId(
resolver,
resolver.import_constant_values().GetAttached(vtable_entry_id));
auto local_attached_constant_id =
GetLocalConstantId(resolver, vtable_entry_id);
lazy_virtual_functions.push_back(
resolver.local_constant_values().GetInstIdIfValid(
local_attached_constant_id));
@@ -2400,12 +2397,9 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
auto implicit_param_patterns = GetLocalInstBlockContents(
resolver, import_impl.implicit_param_patterns_id);
auto generic_data = GetLocalGenericData(resolver, import_impl.generic_id);
auto self_const_id = GetLocalConstantId(
resolver,
resolver.import_constant_values().GetAttached(import_impl.self_id));
auto constraint_const_id = GetLocalConstantId(
resolver,
resolver.import_constant_values().GetAttached(import_impl.constraint_id));
auto self_const_id = GetLocalConstantId(resolver, import_impl.self_id);
auto constraint_const_id =
GetLocalConstantId(resolver, import_impl.constraint_id);
auto& new_impl = resolver.local_impls().Get(impl_id);
if (resolver.HasNewWork()) {
@@ -2456,8 +2450,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
return ResolveResult::Done(constant_id);
}
auto new_constant_id = GetLocalConstantId(
resolver, resolver.import_constant_values().GetInstId(constant_id));
auto new_constant_id = GetLocalConstantId(resolver, constant_id);
return RetryOrDone(resolver, new_constant_id);
}
File diff suppressed because it is too large Load Diff