mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 11:11:05 +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:
@@ -20,6 +20,7 @@ fn F() -> i32 {
|
||||
// CHECK:STDOUT: --- address_of_deref.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
|
||||
@@ -27,6 +27,7 @@ fn F() {
|
||||
// CHECK:STDOUT: --- address_of_lvalue.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
||||
@@ -91,8 +92,8 @@ fn F() {
|
||||
// CHECK:STDOUT: %ptr.as.Copy.impl.Op.specific_fn.b3e: <specific function> = specific_function %ptr.as.Copy.impl.Op.d1c, @ptr.as.Copy.impl.Op(%i32) [concrete]
|
||||
// CHECK:STDOUT: %r.patt: %pattern_type.f00 = ref_binding_pattern r [concrete]
|
||||
// CHECK:STDOUT: %r.var_patt: %pattern_type.f00 = var_pattern %r.patt [concrete]
|
||||
// CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
|
||||
// CHECK:STDOUT: %tuple.b59: %tuple.type.24b = tuple_value (%i32, %i32) [concrete]
|
||||
// CHECK:STDOUT: %tuple.type.693: type = tuple_type (type, type) [concrete]
|
||||
// CHECK:STDOUT: %tuple.94e: %tuple.type.693 = tuple_value (%i32, %i32) [concrete]
|
||||
// CHECK:STDOUT: %tuple.type.e55: type = tuple_type (%i32, %i32) [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.394: type = pattern_type %tuple.type.e55 [concrete]
|
||||
// CHECK:STDOUT: %t.patt: %pattern_type.394 = ref_binding_pattern t [concrete]
|
||||
@@ -263,7 +264,7 @@ fn F() {
|
||||
// CHECK:STDOUT: %.loc22_19.1: type = splice_block %.loc22_19.3 [concrete = constants.%tuple.type.e55] {
|
||||
// CHECK:STDOUT: %i32.loc22_11: type = type_literal constants.%i32 [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %i32.loc22_16: type = type_literal constants.%i32 [concrete = constants.%i32]
|
||||
// CHECK:STDOUT: %.loc22_19.2: %tuple.type.24b = tuple_literal (%i32.loc22_11, %i32.loc22_16) [concrete = constants.%tuple.b59]
|
||||
// CHECK:STDOUT: %.loc22_19.2: %tuple.type.693 = tuple_literal (%i32.loc22_11, %i32.loc22_16) [concrete = constants.%tuple.94e]
|
||||
// CHECK:STDOUT: %.loc22_19.3: type = converted %.loc22_19.2, constants.%tuple.type.e55 [concrete = constants.%tuple.type.e55]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %t: ref %tuple.type.e55 = wrapper_binding t, %t.var
|
||||
|
||||
@@ -30,6 +30,7 @@ fn Foo(ptr: C*) {
|
||||
// CHECK:STDOUT: --- arrow.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.98b: type = pattern_type %C [concrete]
|
||||
// CHECK:STDOUT: %self.param_patt: %pattern_type.98b = value_param_pattern [concrete]
|
||||
|
||||
@@ -22,6 +22,7 @@ fn F() -> i32 {
|
||||
// CHECK:STDOUT: --- basic.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
|
||||
@@ -124,6 +124,7 @@ fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
|
||||
// CHECK:STDOUT: --- same_or_added_qualifiers.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %X: type = class_type @X [concrete]
|
||||
// CHECK:STDOUT: %const.435: type = const_type %X [concrete]
|
||||
// CHECK:STDOUT: %ptr.faf: type = ptr_type %const.435 [concrete]
|
||||
@@ -174,6 +175,7 @@ fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
|
||||
// CHECK:STDOUT: --- fail_todo_nested_qualifiers.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %X: type = class_type @X [concrete]
|
||||
// CHECK:STDOUT: %const.435: type = const_type %X [concrete]
|
||||
// CHECK:STDOUT: %ptr.faf: type = ptr_type %const.435 [concrete]
|
||||
|
||||
@@ -32,6 +32,7 @@ fn Test() {
|
||||
// CHECK:STDOUT: --- fail_address_of_error.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %Test.type: type = fn_type @Test [concrete]
|
||||
// CHECK:STDOUT: %Test: %Test.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
@@ -26,6 +26,7 @@ let n2: i32 = undeclared->foo;
|
||||
// CHECK:STDOUT: --- fail_deref_error.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
|
||||
@@ -28,6 +28,7 @@ fn A() {
|
||||
// CHECK:STDOUT: --- fail_deref_function.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: }
|
||||
|
||||
@@ -30,6 +30,7 @@ fn F() {
|
||||
// CHECK:STDOUT: --- fail_deref_namespace.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
@@ -48,6 +48,7 @@ fn Deref(n: i32) {
|
||||
// CHECK:STDOUT: --- fail_deref_not_pointer.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
||||
|
||||
@@ -29,6 +29,7 @@ var p2: i32->foo;
|
||||
// CHECK:STDOUT: --- fail_deref_type.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
|
||||
@@ -26,6 +26,7 @@ fn ConstMismatch(p: const {}*) -> const ({}*) {
|
||||
// CHECK:STDOUT: --- fail_type_mismatch.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
||||
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %const.c48: type = const_type %empty_struct_type [concrete]
|
||||
|
||||
@@ -28,6 +28,7 @@ var a: i32* = a_ref;
|
||||
// CHECK:STDOUT: --- implicit.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
@@ -139,6 +140,7 @@ var a: i32* = a_ref;
|
||||
// CHECK:STDOUT: --- implicit.impl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
|
||||
|
||||
@@ -21,6 +21,7 @@ fn F(p: const (const (const i32*)*)) -> const i32 {
|
||||
// CHECK:STDOUT: --- nested_const.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
|
||||
@@ -23,6 +23,7 @@ fn ConstPtr(p: const i32*) -> (const i32)* {
|
||||
// CHECK:STDOUT: --- types.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
||||
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
|
||||
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
|
||||
|
||||
Reference in New Issue
Block a user