Files
carbon-lang/toolchain/check/testdata/var/global_decl_import.carbon
T
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

61 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/none.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/var/global_decl_import.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/global_decl_import.carbon
// --- decl.carbon
library "[[@TEST_NAME]]";
var x: {.v: ()} = {.v = ()};
// --- import.carbon
library "[[@TEST_NAME]]";
import library "decl";
fn G() -> {.v: ()} {
//@dump-sem-ir-begin
return x;
//@dump-sem-ir-end
}
// CHECK:STDOUT: --- import.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: %struct_type.v: type = struct_type {.v: %empty_tuple.type} [concrete]
// CHECK:STDOUT: %pattern_type: type = pattern_type %struct_type.v [concrete]
// CHECK:STDOUT: %x.patt: %pattern_type = ref_binding_pattern x [concrete]
// CHECK:STDOUT: %x.var_patt: %pattern_type = var_pattern %x.patt [concrete]
// CHECK:STDOUT: %.7ba: ref %empty_tuple.type = struct_access imports.%x.var, element0 [concrete]
// CHECK:STDOUT: %struct: %struct_type.v = struct_value (%empty_tuple) [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Main.x: ref %struct_type.v = import_ref Main//decl, x, loaded [concrete = %x.var]
// CHECK:STDOUT: %x.var: ref %struct_type.v = var_storage constants.%x.var_patt [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @G() -> out %return.param: %struct_type.v {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x.ref: ref %struct_type.v = name_ref x, imports.%Main.x [concrete = imports.%x.var]
// CHECK:STDOUT: %.loc8_10.1: ref %empty_tuple.type = struct_access %x.ref, element0 [concrete = constants.%.7ba]
// CHECK:STDOUT: %.loc8_10.2: init %empty_tuple.type = tuple_init () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc8_10.3: init %empty_tuple.type = converted %.loc8_10.1, %.loc8_10.2 [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc8_10.4: init %struct_type.v = struct_init (%.loc8_10.3) [concrete = constants.%struct]
// CHECK:STDOUT: %.loc8_11: init %struct_type.v = converted %x.ref, %.loc8_10.4 [concrete = constants.%struct]
// CHECK:STDOUT: return %.loc8_11
// CHECK:STDOUT: }
// CHECK:STDOUT: