Make SemIR::TypeType be an empty FacetType instruction (#7813)

The type `type` is now a `FacetType` inst with no constraints. This
brings the model implemented in the toolchain into better alignment with
the language design. The `SemIR::TypeType` struct remains as a scope for
holding the `TypeInstId`, `ConstantId`, and `TypeId` constants, but is
not an `InstKind` anymore.

The `TypeType` inst looks a lot like singletons, but there are many
`FacetType` insts so it doesn't quite fit that model. So we put it
alongside singletons with a fixed inst id but refer to it as a more
general "builtin" inst that is not a singleton.
`Namespace::PackageInstId` is similar, and we group it with `TypeType`
conceptually as another builtin instruction with a fixed id.

No conversion is needed anymore to use a `type` as a facet, since types
also have a `FacetType` type. This simplifies and removes a number of
helpers and branches throughout the code.

The `TypeType` inst is now part of the constant store, so we end up
printing it in the constants block in every test. But it's also named
`type` rather than `%type` to preserve the majority of existing
formatting behaviour, though this does look different from other
constants.

Assisted-by: Opus 5 was used to generate a first draft and validate the
refactoring. Though nearly everything non-trivial the tool wrote has
been modified or rewritten.
This commit is contained in:
Dana Jansens
2026-09-22 15:04:40 +00:00
committed by GitHub
parent 83ca5b71e3
commit fcae9610bd
795 changed files with 9505 additions and 8048 deletions
+19 -12
View File
@@ -263,6 +263,7 @@ import library "extern_api";
// CHECK:STDOUT: --- api.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
// CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
@@ -277,8 +278,8 @@ import library "extern_api";
// CHECK:STDOUT: %return.patt.e1b: %pattern_type.6b6 = return_slot_pattern %return.param_patt.a9a, %i32 [concrete]
// CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
// CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
// CHECK:STDOUT: %tuple.type.85c: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple: %tuple.type.85c = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.135: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple: %tuple.type.135 = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.a8a: type = tuple_type (%i32) [concrete]
// CHECK:STDOUT: %pattern_type.e71: type = pattern_type %tuple.type.a8a [concrete]
// CHECK:STDOUT: %c.param_patt: %pattern_type.e71 = value_param_pattern [concrete]
@@ -342,7 +343,7 @@ import library "extern_api";
// CHECK:STDOUT: %c.param: %tuple.type.a8a = value_param call_param0
// CHECK:STDOUT: %.loc6_14.1: type = splice_block %.loc6_14.3 [concrete = constants.%tuple.type.a8a] {
// CHECK:STDOUT: %i32.loc6_10: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc6_14.2: %tuple.type.85c = tuple_literal (%i32.loc6_10) [concrete = constants.%tuple]
// CHECK:STDOUT: %.loc6_14.2: %tuple.type.135 = tuple_literal (%i32.loc6_10) [concrete = constants.%tuple]
// CHECK:STDOUT: %.loc6_14.3: type = converted %.loc6_14.2, constants.%tuple.type.a8a [concrete = constants.%tuple.type.a8a]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.a8a = wrapper_binding c, %c.param
@@ -369,6 +370,7 @@ import library "extern_api";
// CHECK:STDOUT: --- extern_api.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
// CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
@@ -383,8 +385,8 @@ import library "extern_api";
// CHECK:STDOUT: %return.patt.e1b: %pattern_type.6b6 = return_slot_pattern %return.param_patt.a9a, %i32 [concrete]
// CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
// CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
// CHECK:STDOUT: %tuple.type.85c: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple: %tuple.type.85c = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.135: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple: %tuple.type.135 = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.a8a: type = tuple_type (%i32) [concrete]
// CHECK:STDOUT: %pattern_type.e71: type = pattern_type %tuple.type.a8a [concrete]
// CHECK:STDOUT: %c.param_patt: %pattern_type.e71 = value_param_pattern [concrete]
@@ -448,7 +450,7 @@ import library "extern_api";
// CHECK:STDOUT: %c.param: %tuple.type.a8a = value_param call_param0
// CHECK:STDOUT: %.loc6_49.1: type = splice_block %.loc6_49.3 [concrete = constants.%tuple.type.a8a] {
// CHECK:STDOUT: %i32.loc6_45: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc6_49.2: %tuple.type.85c = tuple_literal (%i32.loc6_45) [concrete = constants.%tuple]
// CHECK:STDOUT: %.loc6_49.2: %tuple.type.135 = tuple_literal (%i32.loc6_45) [concrete = constants.%tuple]
// CHECK:STDOUT: %.loc6_49.3: type = converted %.loc6_49.2, constants.%tuple.type.a8a [concrete = constants.%tuple.type.a8a]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.a8a = wrapper_binding c, %c.param
@@ -475,6 +477,7 @@ import library "extern_api";
// CHECK:STDOUT: --- basics.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
// CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
@@ -668,6 +671,7 @@ import library "extern_api";
// CHECK:STDOUT: --- fail_redecl_api.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
// CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
@@ -679,8 +683,8 @@ import library "extern_api";
// CHECK:STDOUT: %.795f: Core.Form = init_form %i32 [concrete]
// CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
// CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
// CHECK:STDOUT: %tuple.type.85c: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple.19c: %tuple.type.85c = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.135: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple.e3d: %tuple.type.135 = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.a8a: type = tuple_type (%i32) [concrete]
// CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %i32} [concrete]
// CHECK:STDOUT: %.510: Core.Form = init_form %struct_type.c [concrete]
@@ -775,7 +779,7 @@ import library "extern_api";
// CHECK:STDOUT: %c.param: %tuple.type.a8a = value_param call_param0
// CHECK:STDOUT: %.loc32_21.1: type = splice_block %.loc32_21.3 [concrete = constants.%tuple.type.a8a] {
// CHECK:STDOUT: %i32.loc32_17: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc32_21.2: %tuple.type.85c = tuple_literal (%i32.loc32_17) [concrete = constants.%tuple.19c]
// CHECK:STDOUT: %.loc32_21.2: %tuple.type.135 = tuple_literal (%i32.loc32_17) [concrete = constants.%tuple.e3d]
// CHECK:STDOUT: %.loc32_21.3: type = converted %.loc32_21.2, constants.%tuple.type.a8a [concrete = constants.%tuple.type.a8a]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.a8a = wrapper_binding c, %c.param
@@ -886,6 +890,7 @@ import library "extern_api";
// CHECK:STDOUT: --- redecl_extern_api.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
// CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
// CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
@@ -907,8 +912,8 @@ import library "extern_api";
// CHECK:STDOUT: %D: %D.type = struct_value () [concrete]
// CHECK:STDOUT: %E.type: type = fn_type @E [concrete]
// CHECK:STDOUT: %E: %E.type = struct_value () [concrete]
// CHECK:STDOUT: %tuple.type.85c: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple.19c: %tuple.type.85c = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %tuple.type.135: type = tuple_type (type) [concrete]
// CHECK:STDOUT: %tuple.e3d: %tuple.type.135 = tuple_value (%i32) [concrete]
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
// CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
// CHECK:STDOUT: %a.patt: %pattern_type.cb1 = ref_binding_pattern a [concrete]
@@ -993,7 +998,7 @@ import library "extern_api";
// CHECK:STDOUT: %c.param: %tuple.type.a8a = value_param call_param0
// CHECK:STDOUT: %.loc8_21.1: type = splice_block %.loc8_21.3 [concrete = constants.%tuple.type.a8a] {
// CHECK:STDOUT: %i32.loc8_17: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc8_21.2: %tuple.type.85c = tuple_literal (%i32.loc8_17) [concrete = constants.%tuple.19c]
// CHECK:STDOUT: %.loc8_21.2: %tuple.type.135 = tuple_literal (%i32.loc8_17) [concrete = constants.%tuple.e3d]
// CHECK:STDOUT: %.loc8_21.3: type = converted %.loc8_21.2, constants.%tuple.type.a8a [concrete = constants.%tuple.type.a8a]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %tuple.type.a8a = wrapper_binding c, %c.param
@@ -1104,6 +1109,7 @@ import library "extern_api";
// CHECK:STDOUT: --- fail_merge.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
// CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
@@ -1297,6 +1303,7 @@ import library "extern_api";
// CHECK:STDOUT: --- fail_merge_reverse.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
// CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]