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:
+27
-34
@@ -29,7 +29,7 @@ impl i32 as false {}
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_impl_as_type.carbon:[[@LINE+4]]:1: error: impl as non-facet type `type` [ImplAsNonFacetType]
|
||||
// CHECK:STDERR: fail_impl_as_type.carbon:[[@LINE+4]]:1: error: impl as 0 interfaces, expected 1 [ImplOfNotOneInterface]
|
||||
// CHECK:STDERR: impl bool as type {}
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
@@ -60,6 +60,7 @@ impl {.a: bool} as type where .Self impls I {}
|
||||
// CHECK:STDOUT: --- fail_impl_as_false.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]
|
||||
@@ -100,6 +101,10 @@ impl {.a: bool} as type where .Self impls I {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- fail_impl_as_type.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
||||
// CHECK:STDOUT: .Bool = %Core.Bool
|
||||
@@ -129,15 +134,13 @@ impl {.a: bool} as type where .Self impls I {}
|
||||
// CHECK:STDOUT: --- fail_impl_as_type_where.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
|
||||
// CHECK:STDOUT: %Float.type: type = generic_class_type @Float [concrete]
|
||||
// CHECK:STDOUT: %Float.generic: %Float.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %f64: type = class_type @Float, @Float(%int_64) [concrete]
|
||||
// CHECK:STDOUT: %type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self.frozen.as_type: type = facet_access_type %.Self.frozen [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self: type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
@@ -157,21 +160,17 @@ impl {.a: bool} as type where .Self impls I {}
|
||||
// CHECK:STDOUT: impl_decl @f64.as.<error>.impl [concrete] {} {
|
||||
// CHECK:STDOUT: %f64: type = type_literal constants.%f64 [concrete = constants.%f64]
|
||||
// CHECK:STDOUT: %.loc8_13: type = type_literal type [concrete = type]
|
||||
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %base_facet_type = requirement_base_facet_type %.loc8_13 [concrete]
|
||||
// CHECK:STDOUT: %.Self.ref.loc8_24.1: %type = name_ref .Self, %.Self.frozen [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %.Self.ref.loc8_24.1: type = name_ref .Self, %.Self.frozen [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %.loc8_36: type = type_literal type [concrete = type]
|
||||
// CHECK:STDOUT: %.Self.as_type.loc8_24.1: type = facet_access_type %.Self.ref.loc8_24.1 [symbolic_self = constants.%.Self.frozen.as_type]
|
||||
// CHECK:STDOUT: %.loc8_24.1: type = converted %.Self.ref.loc8_24.1, %.Self.as_type.loc8_24.1 [symbolic_self = constants.%.Self.frozen.as_type]
|
||||
// CHECK:STDOUT: %impls.loc8_30.1 = requirement_impls %.loc8_24.1, %.loc8_36 [concrete]
|
||||
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %.Self.ref.loc8_24.2: %type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %.Self.as_type.loc8_24.2: type = facet_access_type %.Self.ref.loc8_24.2 [symbolic_self = constants.%.Self.as_type]
|
||||
// CHECK:STDOUT: %.loc8_24.2: type = converted %.Self.ref.loc8_24.1, %.Self.as_type.loc8_24.2 [symbolic_self = constants.%.Self.as_type]
|
||||
// CHECK:STDOUT: %impls.loc8_30.2 = requirement_impls %.loc8_24.2, %.loc8_36 [concrete]
|
||||
// CHECK:STDOUT: %.loc8_18: type = where_expr [concrete = constants.%type] {
|
||||
// CHECK:STDOUT: %impls.loc8_30.1 = requirement_impls %.Self.ref.loc8_24.1, %.loc8_36 [concrete]
|
||||
// CHECK:STDOUT: %.Self: type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %.Self.ref.loc8_24.2: type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %impls.loc8_30.2 = requirement_impls %.Self.ref.loc8_24.2, %.loc8_36 [concrete]
|
||||
// CHECK:STDOUT: %.loc8_18: type = where_expr [concrete = type] {
|
||||
// CHECK:STDOUT: %base_facet_type = requirement_base_facet_type %.loc8_13 [concrete]
|
||||
// CHECK:STDOUT: %impls.loc8_30.2 = requirement_impls %.loc8_24.2, %.loc8_36 [concrete]
|
||||
// CHECK:STDOUT: %impls.loc8_30.2 = requirement_impls %.Self.ref.loc8_24.2, %.loc8_36 [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
@@ -185,14 +184,12 @@ impl {.a: bool} as type where .Self impls I {}
|
||||
// CHECK:STDOUT: --- fail_impl_as_type_where_impls_interface.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
|
||||
// CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
|
||||
// CHECK:STDOUT: %struct_type.a: type = struct_type {.a: bool} [concrete]
|
||||
// CHECK:STDOUT: %type: type = facet_type <type> [concrete]
|
||||
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self.frozen.as_type: type = facet_access_type %.Self.frozen [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %.Self: type = symbolic_binding .Self [symbolic_self]
|
||||
// CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls @I> [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -216,21 +213,17 @@ impl {.a: bool} as type where .Self impls I {}
|
||||
// CHECK:STDOUT: %.loc10_11: type = type_literal bool [concrete = bool]
|
||||
// CHECK:STDOUT: %struct_type.a: type = struct_type {.a: bool} [concrete = constants.%struct_type.a]
|
||||
// CHECK:STDOUT: %.loc10_20: type = type_literal type [concrete = type]
|
||||
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %base_facet_type = requirement_base_facet_type %.loc10_20 [concrete]
|
||||
// CHECK:STDOUT: %.Self.ref.loc10_31.1: %type = name_ref .Self, %.Self.frozen [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %.Self.ref.loc10_31.1: type = name_ref .Self, %.Self.frozen [symbolic_self = constants.%.Self.frozen]
|
||||
// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
|
||||
// CHECK:STDOUT: %.Self.as_type.loc10_31.1: type = facet_access_type %.Self.ref.loc10_31.1 [symbolic_self = constants.%.Self.frozen.as_type]
|
||||
// CHECK:STDOUT: %.loc10_31.1: type = converted %.Self.ref.loc10_31.1, %.Self.as_type.loc10_31.1 [symbolic_self = constants.%.Self.frozen.as_type]
|
||||
// CHECK:STDOUT: %impls.loc10_37.1 = requirement_impls %.loc10_31.1, %I.ref [concrete]
|
||||
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %.Self.ref.loc10_31.2: %type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %.Self.as_type.loc10_31.2: type = facet_access_type %.Self.ref.loc10_31.2 [symbolic_self = constants.%.Self.as_type]
|
||||
// CHECK:STDOUT: %.loc10_31.2: type = converted %.Self.ref.loc10_31.1, %.Self.as_type.loc10_31.2 [symbolic_self = constants.%.Self.as_type]
|
||||
// CHECK:STDOUT: %impls.loc10_37.2 = requirement_impls %.loc10_31.2, %I.ref [concrete]
|
||||
// CHECK:STDOUT: %impls.loc10_37.1 = requirement_impls %.Self.ref.loc10_31.1, %I.ref [concrete]
|
||||
// CHECK:STDOUT: %.Self: type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %.Self.ref.loc10_31.2: type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
|
||||
// CHECK:STDOUT: %impls.loc10_37.2 = requirement_impls %.Self.ref.loc10_31.2, %I.ref [concrete]
|
||||
// CHECK:STDOUT: %.loc10_25: type = where_expr [concrete = constants.%type_where] {
|
||||
// CHECK:STDOUT: %base_facet_type = requirement_base_facet_type %.loc10_20 [concrete]
|
||||
// CHECK:STDOUT: %impls.loc10_37.2 = requirement_impls %.loc10_31.2, %I.ref [concrete]
|
||||
// CHECK:STDOUT: %impls.loc10_37.2 = requirement_impls %.Self.ref.loc10_31.2, %I.ref [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
|
||||
Reference in New Issue
Block a user