Files
Dana Jansens fcae9610bd 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.
2026-09-22 15:04:40 +00:00

69 lines
2.7 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/partial/init.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/partial/init.carbon
// --- base.carbon
library "[[@TEST_NAME]]";
base class Base {
fn Make() -> partial Self {
return {};
}
}
class Derived {
extend base: Base;
fn Make() -> Self {
//@dump-sem-ir-begin
return {.base = Base.Make()};
//@dump-sem-ir-end
}
}
// 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]
// CHECK:STDOUT: %Base.Make: %Base.Make.type = struct_value () [concrete]
// CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
// CHECK:STDOUT: %struct_type.base.343: type = struct_type {.base: %.edf} [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @Derived {
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%Derived
// CHECK:STDOUT: .Base = <poisoned>
// CHECK:STDOUT: .base = %.loc11
// CHECK:STDOUT: .Make = %Derived.Make.decl
// CHECK:STDOUT: extend %Base.ref
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Derived.Make() -> out %return.param: %Derived {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
// CHECK:STDOUT: %Make.ref: %Base.Make.type = name_ref Make, @Base.%Base.Make.decl [concrete = constants.%Base.Make]
// CHECK:STDOUT: %.loc14_32.1: ref %.edf = class_element_access %return.param, element0
// CHECK:STDOUT: %Base.Make.call: init %.edf to %.loc14_32.1 = call %Make.ref()
// CHECK:STDOUT: %.loc14_32.2: %struct_type.base.343 = struct_literal (%Base.Make.call)
// CHECK:STDOUT: %.loc14_32.3: init %Base = as_compatible %Base.Make.call
// CHECK:STDOUT: %.loc14_32.4: init %Derived to %return.param = class_init (%.loc14_32.3)
// CHECK:STDOUT: %.loc14_33: init %Derived = converted %.loc14_32.2, %.loc14_32.4
// CHECK:STDOUT: return %.loc14_33 to %return.param
// CHECK:STDOUT: }
// CHECK:STDOUT: