Skip to content

Commit 44d86e1

Browse files
authored
Minor uses of import_* in import_ref (carbon-language#6428)
Just refactoring calls to use shorter names.
1 parent 3a293a7 commit 44d86e1

File tree

1 file changed

+42
-64
lines changed

1 file changed

+42
-64
lines changed

toolchain/check/import_ref.cpp

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ class ImportContext {
229229
// from `InstId`s in the import IR to corresponding `ConstantId`s in the local
230230
// IR.
231231
auto local_constant_values_for_import_insts() -> SemIR::ConstantValueStore& {
232-
return local_context().import_ir_constant_values()
233-
[local_context().sem_ir().import_irs().GetRawIndex(import_ir_id_)];
232+
auto index = local_ir().import_irs().GetRawIndex(import_ir_id_);
233+
return local_context().import_ir_constant_values()[index];
234234
}
235235

236236
// Returns the file we are importing into.
@@ -1458,8 +1458,7 @@ struct ResolveResult {
14581458
CARBON_CHECK(!resolver.HasNewWork());
14591459
// AddImportedConstant produces an unattached constant, so its type must
14601460
// be unattached as well.
1461-
inst.type_id =
1462-
resolver.local_context().types().GetUnattachedType(inst.type_id);
1461+
inst.type_id = resolver.local_types().GetUnattachedType(inst.type_id);
14631462
auto const_id = AddImportedConstant(resolver.local_context(), inst);
14641463
CARBON_CHECK(const_id.is_constant(), "{0} is not constant", inst);
14651464
return Done(const_id);
@@ -1520,8 +1519,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, ParamPatternT inst,
15201519

15211520
return ResolveResult::Unique<ParamPatternT>(
15221521
resolver, import_inst_id,
1523-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
1524-
type_const_id),
1522+
{.type_id =
1523+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
15251524
.subpattern_id = subpattern_id,
15261525
.index = inst.index});
15271526
}
@@ -1586,8 +1585,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
15861585
}
15871586

15881587
// In the second phase, create the associated constant and its declaration.
1589-
auto type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
1590-
type_const_id);
1588+
auto type_id =
1589+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id);
15911590
std::tie(assoc_const_id, const_id) =
15921591
MakeAssociatedConstant(resolver, import_assoc_const, type_id);
15931592
} else {
@@ -1630,11 +1629,10 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
16301629
auto decl_id = AddImportRef(resolver, inst.decl_id);
16311630

16321631
return ResolveResult::Deduplicated<SemIR::AssociatedEntity>(
1633-
resolver,
1634-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
1635-
type_const_id),
1636-
.index = inst.index,
1637-
.decl_id = decl_id});
1632+
resolver, {.type_id = resolver.local_types().GetTypeIdForTypeConstantId(
1633+
type_const_id),
1634+
.index = inst.index,
1635+
.decl_id = decl_id});
16381636
}
16391637

16401638
static auto TryResolveTypedInst(ImportRefResolver& resolver,
@@ -1672,8 +1670,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
16721670
// Create a corresponding instruction to represent the declaration.
16731671
return ResolveResult::Unique<SemIR::BaseDecl>(
16741672
resolver, import_inst_id,
1675-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
1676-
type_const_id),
1673+
{.type_id =
1674+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
16771675
.base_type_inst_id = base_type_inst_id,
16781676
.index = inst.index});
16791677
}
@@ -1695,8 +1693,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
16951693
GetLocalSymbolicEntityNameId(resolver, inst.entity_name_id);
16961694
return ResolveResult::Deduplicated<SemIR::SymbolicBinding>(
16971695
resolver,
1698-
{.type_id =
1699-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
1696+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
17001697
.entity_name_id = entity_name_id,
17011698
.value_id = SemIR::InstId::None});
17021699
}
@@ -1724,8 +1721,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
17241721
.is_template = import_entity_name.is_template});
17251722
return ResolveResult::Unique<BindingPatternT>(
17261723
resolver, import_inst_id,
1727-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
1728-
type_const_id),
1724+
{.type_id =
1725+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
17291726
.entity_name_id = entity_name_id});
17301727
}
17311728

@@ -1774,8 +1771,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver, SemIR::Call inst)
17741771

17751772
return ResolveResult::Deduplicated<SemIR::Call>(
17761773
resolver,
1777-
{.type_id =
1778-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
1774+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
17791775
.callee_id = callee_id,
17801776
.args_id = GetLocalCanonicalInstBlockId(resolver, inst.args_id, args)});
17811777
}
@@ -1956,8 +1952,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
19561952
new_class.param_patterns_id = GetLocalCanonicalInstBlockId(
19571953
resolver, import_class.param_patterns_id, param_patterns);
19581954
new_class.self_type_id =
1959-
resolver.local_context().types().GetTypeIdForTypeConstantId(
1960-
self_const_id);
1955+
resolver.local_types().GetTypeIdForTypeConstantId(self_const_id);
19611956

19621957
if (import_class.is_complete()) {
19631958
auto complete_type_witness_id = AddLoadedImportRef(
@@ -2082,8 +2077,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
20822077
}
20832078
return ResolveResult::Unique<SemIR::FieldDecl>(
20842079
resolver, import_inst_id,
2085-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
2086-
const_id),
2080+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(const_id),
20872081
.name_id = GetLocalNameId(resolver, inst.name_id),
20882082
.index = inst.index});
20892083
}
@@ -2132,8 +2126,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
21322126

21332127
return ResolveResult::Deduplicated<SemIR::FloatValue>(
21342128
resolver,
2135-
{.type_id =
2136-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
2129+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
21372130
.float_id = float_id});
21382131
}
21392132

@@ -3088,8 +3081,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
30883081

30893082
return ResolveResult::Deduplicated<SemIR::FacetValue>(
30903083
resolver,
3091-
{.type_id =
3092-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3084+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
30933085
.type_inst_id = type_inst_id,
30943086
.witnesses_block_id = GetLocalCanonicalInstBlockId(
30953087
resolver, inst.witnesses_block_id, witnesses)});
@@ -3157,8 +3149,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
31573149

31583150
return ResolveResult::Deduplicated<SemIR::ImplWitnessAccess>(
31593151
resolver,
3160-
{.type_id =
3161-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3152+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
31623153
.witness_id = witness_id,
31633154
.index = inst.index});
31643155
}
@@ -3201,8 +3192,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
32013192

32023193
return ResolveResult::Deduplicated<SemIR::IntValue>(
32033194
resolver,
3204-
{.type_id =
3205-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3195+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
32063196
.int_id = int_id});
32073197
}
32083198

@@ -3312,8 +3302,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
33123302

33133303
return ResolveResult::Unique<SemIR::ReturnSlotPattern>(
33143304
resolver, import_inst_id,
3315-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
3316-
type_const_id),
3305+
{.type_id =
3306+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
33173307
.type_inst_id = SemIR::TypeInstId::None});
33183308
}
33193309

@@ -3326,8 +3316,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
33263316
return ResolveResult::Retry();
33273317
}
33283318

3329-
auto type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
3330-
type_const_id);
3319+
auto type_id =
3320+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id);
33313321
auto specific_id =
33323322
GetOrAddLocalSpecific(resolver, inst.specific_id, specific_data);
33333323
return ResolveResult::Deduplicated<SemIR::SpecificFunction>(
@@ -3368,8 +3358,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
33683358

33693359
return ResolveResult::Deduplicated<SemIR::StructAccess>(
33703360
resolver,
3371-
{.type_id =
3372-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3361+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
33733362
.struct_id = struct_id,
33743363
.index = inst.index});
33753364
}
@@ -3414,8 +3403,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
34143403

34153404
return ResolveResult::Deduplicated<SemIR::StructValue>(
34163405
resolver,
3417-
{.type_id =
3418-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3406+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
34193407
.elements_id =
34203408
GetLocalCanonicalInstBlockId(resolver, inst.elements_id, elems)});
34213409
}
@@ -3452,8 +3440,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
34523440

34533441
return ResolveResult::Deduplicated<SemIR::TupleAccess>(
34543442
resolver,
3455-
{.type_id =
3456-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3443+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
34573444
.tuple_id = tuple_id,
34583445
.index = inst.index});
34593446
}
@@ -3469,8 +3456,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
34693456

34703457
return ResolveResult::Unique<SemIR::TuplePattern>(
34713458
resolver, import_inst_id,
3472-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
3473-
type_const_id),
3459+
{.type_id =
3460+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
34743461
.elements_id =
34753462
GetLocalCanonicalInstBlockId(resolver, inst.elements_id, elements)});
34763463
}
@@ -3509,8 +3496,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
35093496

35103497
return ResolveResult::Deduplicated<SemIR::TupleValue>(
35113498
resolver,
3512-
{.type_id =
3513-
resolver.local_context().types().GetTypeIdForTypeConstantId(type_id),
3499+
{.type_id = resolver.local_types().GetTypeIdForTypeConstantId(type_id),
35143500
.elements_id =
35153501
GetLocalCanonicalInstBlockId(resolver, inst.elements_id, elems)});
35163502
}
@@ -3544,8 +3530,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
35443530

35453531
return ResolveResult::Unique<SemIR::VarPattern>(
35463532
resolver, import_inst_id,
3547-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
3548-
type_const_id),
3533+
{.type_id =
3534+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
35493535
.subpattern_id = subpattern_id});
35503536
}
35513537

@@ -3560,8 +3546,8 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
35603546

35613547
return ResolveResult::Unique<SemIR::VarStorage>(
35623548
resolver, import_inst_id,
3563-
{.type_id = resolver.local_context().types().GetTypeIdForTypeConstantId(
3564-
type_const_id),
3549+
{.type_id =
3550+
resolver.local_types().GetTypeIdForTypeConstantId(type_const_id),
35653551
.pattern_id = pattern_id});
35663552
}
35673553

@@ -3994,7 +3980,7 @@ auto ImportRefResolver::ResolveType(SemIR::TypeId import_type_id)
39943980
// Builtins don't require constant resolution; we can use them directly.
39953981
return GetSingletonType(local_context(), import_type_inst_id);
39963982
} else {
3997-
return local_context().types().GetTypeIdForTypeConstantId(
3983+
return local_types().GetTypeIdForTypeConstantId(
39983984
ResolveConstant(import_type_id.AsConstantId()));
39993985
}
40003986
}
@@ -4071,8 +4057,7 @@ auto ImportRefResolver::FindResolvedConstId(SemIR::InstId inst_id)
40714057
if (auto const_id =
40724058
local_context()
40734059
.import_ir_constant_values()
4074-
[local_context().sem_ir().import_irs().GetRawIndex(
4075-
cursor_ir_id)]
4060+
[local_ir().import_irs().GetRawIndex(cursor_ir_id)]
40764061
.GetAttached(cursor_inst_id);
40774062
const_id.has_value()) {
40784063
SetResolvedConstId(inst_id, result.indirect_insts, const_id);
@@ -4198,21 +4183,14 @@ auto ImportImplsFromApiFile(Context& context) -> void {
41984183
auto ImportImpl(Context& context, SemIR::ImportIRId import_ir_id,
41994184
SemIR::ImplId impl_id) -> void {
42004185
ImportRefResolver resolver(&context, import_ir_id);
4201-
resolver.Resolve(context.import_irs()
4202-
.Get(import_ir_id)
4203-
.sem_ir->impls()
4204-
.Get(impl_id)
4205-
.first_decl_id());
4186+
resolver.Resolve(resolver.import_impls().Get(impl_id).first_decl_id());
42064187
}
42074188

42084189
auto ImportInterface(Context& context, SemIR::ImportIRId import_ir_id,
42094190
SemIR::InterfaceId interface_id) -> SemIR::InterfaceId {
42104191
ImportRefResolver resolver(&context, import_ir_id);
4211-
auto local_id = resolver.Resolve(context.import_irs()
4212-
.Get(import_ir_id)
4213-
.sem_ir->interfaces()
4214-
.Get(interface_id)
4215-
.first_decl_id());
4192+
auto local_id = resolver.Resolve(
4193+
resolver.import_interfaces().Get(interface_id).first_decl_id());
42164194
auto local_inst =
42174195
context.insts().Get(context.constant_values().GetInstId(local_id));
42184196

0 commit comments

Comments
 (0)