Skip to content

Commit 42e2280

Browse files
jonmeowdanakj
andauthored
Clean up singleton TypeId use (#6300)
#6289 absentmindedly added fields in more places, and this is undoing that plus further fixes. This does some cleanup of types with relation to singletons. For `TypeType` and `ErrorInst`, they're always complete due to a `SetComplete` call in `file.cpp`. For `CppVoidType`, it's intended to be incomplete by construction, and so a `TypeId` should be okay. The intent though on not generally providing these had been that `GetSingletonType` needs to be called to get a type to be marked as complete. In the case of `AutoType`, removing `TypeId`does change a small printing detail. I think that's old legacy that's just been carried forward. Otherwise, for both `InstType` and `AutoType`, I've added `GetSingletonType` calls where they were used in order to ensure completeness is applied correctly. These calls cause small SemIR permutations. This causes `AutoType` to be seen by lowering, so I'm adding a placeholder for it. Also merging two functions that look like they're identical in intent -- not sure why they're separate. --------- Co-authored-by: Dana Jansens <[email protected]>
1 parent f272198 commit 42e2280

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+215
-210
lines changed

toolchain/check/action.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "toolchain/base/kind_switch.h"
88
#include "toolchain/check/generic_region_stack.h"
99
#include "toolchain/check/inst.h"
10+
#include "toolchain/check/type.h"
1011
#include "toolchain/sem_ir/constant.h"
1112
#include "toolchain/sem_ir/id_kind.h"
1213
#include "toolchain/sem_ir/inst.h"
@@ -134,7 +135,8 @@ static auto RefineOperand(Context& context, SemIR::LocId loc_id,
134135
context,
135136
SemIR::LocIdAndInst(
136137
loc_id,
137-
SemIR::RefineTypeAction{.type_id = SemIR::InstType::TypeId,
138+
SemIR::RefineTypeAction{.type_id = GetSingletonType(
139+
context, SemIR::InstType::TypeInstId),
138140
.inst_id = *inst_id,
139141
.inst_type_inst_id = type_inst_id}),
140142
type_inst_id);

toolchain/check/convert.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,9 +1459,10 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
14591459
auto target_type_inst_id = context.types().GetInstId(target.type_id);
14601460
return AddDependentActionSplice(
14611461
context, loc_id,
1462-
SemIR::ConvertToValueAction{.type_id = SemIR::InstType::TypeId,
1463-
.inst_id = expr_id,
1464-
.target_type_inst_id = target_type_inst_id},
1462+
SemIR::ConvertToValueAction{
1463+
.type_id = GetSingletonType(context, SemIR::InstType::TypeInstId),
1464+
.inst_id = expr_id,
1465+
.target_type_inst_id = target_type_inst_id},
14651466
target_type_inst_id);
14661467
}
14671468

@@ -1735,7 +1736,7 @@ auto ExprAsType(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id,
17351736
bool diagnose) -> TypeExpr {
17361737
auto type_inst_id =
17371738
ConvertToValueOfType(context, loc_id, value_id, SemIR::TypeType::TypeId);
1738-
if (type_inst_id == SemIR::ErrorInst::InstId) {
1739+
if (type_inst_id == SemIR::ErrorInst::TypeInstId) {
17391740
return {.inst_id = SemIR::ErrorInst::TypeInstId,
17401741
.type_id = SemIR::ErrorInst::TypeId};
17411742
}

toolchain/check/eval.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,9 @@ static auto PerformCheckedCharConvert(Context& context, SemIR::LocId loc_id,
987987
static auto MakeIntTypeResult(Context& context, SemIR::LocId loc_id,
988988
SemIR::IntKind int_kind, SemIR::InstId width_id,
989989
Phase phase) -> SemIR::ConstantId {
990-
auto result = SemIR::IntType{
991-
.type_id = GetSingletonType(context, SemIR::TypeType::TypeInstId),
992-
.int_kind = int_kind,
993-
.bit_width_id = width_id};
990+
auto result = SemIR::IntType{.type_id = SemIR::TypeType::TypeId,
991+
.int_kind = int_kind,
992+
.bit_width_id = width_id};
994993
if (!ValidateIntType(context, loc_id, result)) {
995994
return SemIR::ErrorInst::ConstantId;
996995
}
@@ -1002,10 +1001,9 @@ static auto MakeIntTypeResult(Context& context, SemIR::LocId loc_id,
10021001
static auto MakeFloatTypeResult(Context& context, SemIR::LocId loc_id,
10031002
SemIR::InstId width_id, Phase phase)
10041003
-> SemIR::ConstantId {
1005-
auto result = SemIR::FloatType{
1006-
.type_id = GetSingletonType(context, SemIR::TypeType::TypeInstId),
1007-
.bit_width_id = width_id,
1008-
.float_kind = SemIR::FloatKind::None};
1004+
auto result = SemIR::FloatType{.type_id = SemIR::TypeType::TypeId,
1005+
.bit_width_id = width_id,
1006+
.float_kind = SemIR::FloatKind::None};
10091007
if (!ValidateFloatTypeAndSetKind(context, loc_id, result)) {
10101008
return SemIR::ErrorInst::ConstantId;
10111009
}
@@ -2085,8 +2083,10 @@ static auto TryEvalTypedInst(EvalContext& eval_context, SemIR::InstId inst_id,
20852083
// The result is an instruction.
20862084
return MakeConstantResult(
20872085
eval_context.context(),
2088-
SemIR::InstValue{.type_id = SemIR::InstType::TypeId,
2089-
.inst_id = result_inst_id},
2086+
SemIR::InstValue{
2087+
.type_id = GetSingletonType(eval_context.context(),
2088+
SemIR::InstType::TypeInstId),
2089+
.inst_id = result_inst_id},
20902090
Phase::Concrete);
20912091
}
20922092
// Couldn't perform the action because it's still dependent.

toolchain/check/handle_binding_pattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ auto HandleParseNode(Context& context, Parse::AddrId node_id) -> bool {
412412
if (pointer_type) {
413413
auto addr_pattern_id = AddPatternInst<SemIR::AddrPattern>(
414414
context, node_id,
415-
{.type_id = GetPatternType(context, SemIR::AutoType::TypeId),
415+
{.type_id = GetPatternType(
416+
context, GetSingletonType(context, SemIR::AutoType::TypeInstId)),
416417
.inner_id = param_pattern_id});
417418
context.node_stack().Push(node_id, addr_pattern_id);
418419
} else {

toolchain/check/member_access.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,13 @@ auto PerformMemberAccess(Context& context, SemIR::LocId loc_id,
461461
if (required) {
462462
return HandleAction<SemIR::AccessMemberAction>(
463463
context, loc_id,
464-
{.type_id = SemIR::InstType::TypeId,
464+
{.type_id = GetSingletonType(context, SemIR::InstType::TypeInstId),
465465
.base_id = base_id,
466466
.name_id = name_id});
467467
} else {
468468
return HandleAction<SemIR::AccessOptionalMemberAction>(
469469
context, loc_id,
470-
{.type_id = SemIR::InstType::TypeId,
470+
{.type_id = GetSingletonType(context, SemIR::InstType::TypeInstId),
471471
.base_id = base_id,
472472
.name_id = name_id});
473473
}

0 commit comments

Comments
 (0)