mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -32,6 +32,7 @@ class Derived {
|
||||
// CHECK:STDOUT: --- base.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %Base: type = class_type @Base [concrete]
|
||||
// CHECK:STDOUT: %.edf: type = partial_type %Base [concrete]
|
||||
// CHECK:STDOUT: %Base.Make.type: type = fn_type @Base.Make [concrete]
|
||||
|
||||
+12
-3
@@ -178,6 +178,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- base.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %.331: type = partial_type %C [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.331 [concrete]
|
||||
@@ -206,6 +207,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- abstract.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %.331: type = partial_type %C [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.331 [concrete]
|
||||
@@ -234,6 +236,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- abstract_var.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %.331: type = partial_type %C [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.331 [concrete]
|
||||
@@ -262,6 +265,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- fail_partial_nondynamic.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %.331: type = partial_type %C [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.331 [concrete]
|
||||
@@ -290,6 +294,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- fail_partial_final.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
|
||||
// CHECK:STDOUT: %.546: type = partial_type %Derived [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.546 [concrete]
|
||||
@@ -318,6 +323,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- fail_partial_decl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %.331: type = partial_type %C [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.331 [concrete]
|
||||
@@ -346,9 +352,10 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- fail_partial_tuple.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
|
||||
// CHECK:STDOUT: %tuple: %tuple.type.24b = tuple_value (%C, %C) [concrete]
|
||||
// CHECK:STDOUT: %tuple.type.693: type = tuple_type (type, type) [concrete]
|
||||
// CHECK:STDOUT: %tuple: %tuple.type.693 = tuple_value (%C, %C) [concrete]
|
||||
// CHECK:STDOUT: %tuple.type.748: type = tuple_type (%C, %C) [concrete]
|
||||
// CHECK:STDOUT: %.8dc: type = partial_type %tuple.type.748 [concrete]
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %.8dc [concrete]
|
||||
@@ -367,7 +374,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: %.loc10_9.1: type = splice_block %.loc10_9.3 [concrete = constants.%.8dc] {
|
||||
// CHECK:STDOUT: %C.ref.loc10_18: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %C.ref.loc10_21: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %.loc10_22: %tuple.type.24b = tuple_literal (%C.ref.loc10_18, %C.ref.loc10_21) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc10_22: %tuple.type.693 = tuple_literal (%C.ref.loc10_18, %C.ref.loc10_21) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc10_9.2: type = converted %.loc10_22, constants.%tuple.type.748 [concrete = constants.%tuple.type.748]
|
||||
// CHECK:STDOUT: %.loc10_9.3: type = partial_type %.loc10_9.2 [concrete = constants.%.8dc]
|
||||
// CHECK:STDOUT: }
|
||||
@@ -380,6 +387,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- fail_partial_struct.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %struct_type.x: type = struct_type {.x: %C} [concrete]
|
||||
// CHECK:STDOUT: %.91f: type = partial_type %struct_type.x [concrete]
|
||||
@@ -410,6 +418,7 @@ fn F[T: type](p: partial T*);
|
||||
// CHECK:STDOUT: --- fail_duplicate.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %.331: type = partial_type %C [concrete]
|
||||
// CHECK:STDOUT: %.d52: type = partial_type %.331 [concrete]
|
||||
|
||||
Reference in New Issue
Block a user