mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:11:04 +01:00
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.
243 lines
15 KiB
Plaintext
243 lines
15 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
|
|
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
|
|
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/assoc_const_in_generic.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/assoc_const_in_generic.carbon
|
|
|
|
interface I(T: type) {
|
|
fn F(generic U: type) -> U;
|
|
}
|
|
|
|
fn G(generic T: type) {
|
|
// This should not result in a `fn_decl` instruction being added to the eval
|
|
// block for the generic G. This used to crash when printing formatted SemIR
|
|
// because the same instruction ended up in multiple scopes.
|
|
I(T).F;
|
|
}
|
|
|
|
fn H() {
|
|
G({});
|
|
}
|
|
|
|
// CHECK:STDOUT: --- assoc_const_in_generic.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self]
|
|
// CHECK:STDOUT: %pattern_type.9a5: type = pattern_type type [concrete]
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.9a5 = symbolic_binding_pattern T, 0 [symbolic]
|
|
// CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic]
|
|
// CHECK:STDOUT: %I.type.335: type = generic_interface_type @I [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %I.generic: %I.type.335 = struct_value () [concrete]
|
|
// CHECK:STDOUT: %I.type.3fe: type = facet_type <@I, @I(%T)> [symbolic]
|
|
// CHECK:STDOUT: %Self.191: %I.type.3fe = symbolic_binding Self, 1 [symbolic]
|
|
// CHECK:STDOUT: %U.patt: %pattern_type.9a5 = symbolic_binding_pattern U, 2 [symbolic]
|
|
// CHECK:STDOUT: %U: type = symbolic_binding U, 2 [symbolic]
|
|
// CHECK:STDOUT: %.a6b: Core.Form = init_form %U [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.62e: type = pattern_type %U [symbolic]
|
|
// CHECK:STDOUT: %return.param_patt: %pattern_type.62e = out_param_pattern [symbolic]
|
|
// CHECK:STDOUT: %return.patt: %pattern_type.62e = return_slot_pattern %return.param_patt, %U [symbolic]
|
|
// CHECK:STDOUT: %I.WithSelf.F.type.09f: type = fn_type @I.WithSelf.F, @I.WithSelf(%T, %Self.191) [symbolic]
|
|
// CHECK:STDOUT: %I.WithSelf.F.5f2: %I.WithSelf.F.type.09f = struct_value () [symbolic]
|
|
// CHECK:STDOUT: %I.assoc_type.b71: type = assoc_entity_type @I, @I(%T) [symbolic]
|
|
// CHECK:STDOUT: %assoc0.13b: %I.assoc_type.b71 = assoc_entity element0, @I.WithSelf.%I.WithSelf.F.decl [symbolic]
|
|
// CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
|
|
// CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %I.type.3fe [symbolic]
|
|
// CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
|
|
// CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %G.specific_fn: <specific function> = specific_function %G, @G(%empty_struct_type) [concrete]
|
|
// CHECK:STDOUT: %I.type.81d: type = facet_type <@I, @I(%empty_struct_type)> [concrete]
|
|
// CHECK:STDOUT: %Self.524: %I.type.81d = symbolic_binding Self, 1 [symbolic]
|
|
// CHECK:STDOUT: %I.WithSelf.F.type.272: type = fn_type @I.WithSelf.F, @I.WithSelf(%empty_struct_type, %Self.191) [symbolic]
|
|
// CHECK:STDOUT: %I.WithSelf.F.fb6: %I.WithSelf.F.type.272 = struct_value () [symbolic]
|
|
// CHECK:STDOUT: %I.assoc_type.cd3: type = assoc_entity_type @I, @I(%empty_struct_type) [concrete]
|
|
// CHECK:STDOUT: %assoc0.a4c: %I.assoc_type.cd3 = assoc_entity element0, @I.WithSelf.%I.WithSelf.F.decl [concrete]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %I.type.81d [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .I = %I.decl
|
|
// CHECK:STDOUT: .G = %G.decl
|
|
// CHECK:STDOUT: .H = %H.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %I.decl: %I.type.335 = interface_decl @I [concrete = constants.%I.generic] {
|
|
// CHECK:STDOUT: %T.patt.loc15_14.1: %pattern_type.9a5 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc15_14.2 (constants.%T.patt)]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc15_16.1: type = splice_block %.loc15_16.2 [concrete = type] {
|
|
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
|
// CHECK:STDOUT: %.loc15_16.2: type = type_literal type [concrete = type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc15_14.2: type = symbolic_binding T, 0 [symbolic = %T.loc15_14.1 (constants.%T)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
|
|
// CHECK:STDOUT: %T.patt.loc19_15.1: %pattern_type.9a5 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc19_15.2 (constants.%T.patt)]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc19_17.1: type = splice_block %.loc19_17.2 [concrete = type] {
|
|
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
|
// CHECK:STDOUT: %.loc19_17.2: type = type_literal type [concrete = type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc19_15.2: type = symbolic_binding T, 0 [symbolic = %T.loc19_15.1 (constants.%T)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic interface @I(%T.loc15_14.2: type) {
|
|
// CHECK:STDOUT: %T.patt.loc15_14.2: %pattern_type.9a5 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc15_14.2 (constants.%T.patt)]
|
|
// CHECK:STDOUT: %T.loc15_14.1: type = symbolic_binding T, 0 [symbolic = %T.loc15_14.1 (constants.%T)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T.loc15_14.1)> [symbolic = %I.type (constants.%I.type.3fe)]
|
|
// CHECK:STDOUT: %Self.loc15_22.2: @I.%I.type (%I.type.3fe) = symbolic_binding Self, 1 [symbolic = %Self.loc15_22.2 (constants.%Self.191)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface {
|
|
// CHECK:STDOUT: %Self.loc15_22.1: @I.%I.type (%I.type.3fe) = symbolic_binding Self, 1 [symbolic = %Self.loc15_22.2 (constants.%Self.191)]
|
|
// CHECK:STDOUT: %I.WithSelf.decl = interface_with_self_decl @I [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !with Self:
|
|
// CHECK:STDOUT: %I.WithSelf.F.decl: @I.WithSelf.%I.WithSelf.F.type (%I.WithSelf.F.type.09f) = fn_decl @I.WithSelf.F [symbolic = @I.WithSelf.%I.WithSelf.F (constants.%I.WithSelf.F.5f2)] {
|
|
// CHECK:STDOUT: %U.patt.loc16_17.1: %pattern_type.9a5 = symbolic_binding_pattern U, 2 [symbolic = %U.patt.loc16_17.2 (constants.%U.patt)]
|
|
// CHECK:STDOUT: %return.param_patt.loc16_28.1: @I.WithSelf.F.%pattern_type (%pattern_type.62e) = out_param_pattern [symbolic = %return.param_patt.loc16_28.2 (constants.%return.param_patt)]
|
|
// CHECK:STDOUT: %return.patt.loc16_25.1: @I.WithSelf.F.%pattern_type (%pattern_type.62e) = return_slot_pattern %return.param_patt.loc16_28.1, %U.ref [symbolic = %return.patt.loc16_25.2 (constants.%return.patt)]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %U.ref: type = name_ref U, %U.loc16_17.2 [symbolic = %U.loc16_17.1 (constants.%U)]
|
|
// CHECK:STDOUT: %.loc16_28.2: Core.Form = init_form %U.ref [symbolic = %.loc16_28.1 (constants.%.a6b)]
|
|
// CHECK:STDOUT: %.loc16_19.1: type = splice_block %.loc16_19.2 [concrete = type] {
|
|
// CHECK:STDOUT: %.Self.frozen: type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
|
|
// CHECK:STDOUT: %.loc16_19.2: type = type_literal type [concrete = type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %U.loc16_17.2: type = symbolic_binding U, 2 [symbolic = %U.loc16_17.1 (constants.%U)]
|
|
// CHECK:STDOUT: %return.param: ref @I.WithSelf.F.%U.loc16_17.1 (%U) = out_param call_param0
|
|
// CHECK:STDOUT: %return: ref @I.WithSelf.F.%U.loc16_17.1 (%U) = return_slot %return.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %assoc0.loc16_29.1: @I.WithSelf.%I.assoc_type (%I.assoc_type.b71) = assoc_entity element0, %I.WithSelf.F.decl [symbolic = %assoc0.loc16_29.2 (constants.%assoc0.13b)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self.loc15_22.1
|
|
// CHECK:STDOUT: .F = @I.WithSelf.%assoc0.loc16_29.1
|
|
// CHECK:STDOUT: witness = (@I.WithSelf.%I.WithSelf.F.decl)
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @I.WithSelf.F(@I.%T.loc15_14.2: type, @I.%Self.loc15_22.1: @I.%I.type (%I.type.3fe), %U.loc16_17.2: type) {
|
|
// CHECK:STDOUT: %U.patt.loc16_17.2: %pattern_type.9a5 = symbolic_binding_pattern U, 2 [symbolic = %U.patt.loc16_17.2 (constants.%U.patt)]
|
|
// CHECK:STDOUT: %U.loc16_17.1: type = symbolic_binding U, 2 [symbolic = %U.loc16_17.1 (constants.%U)]
|
|
// CHECK:STDOUT: %.loc16_28.1: Core.Form = init_form %U.loc16_17.1 [symbolic = %.loc16_28.1 (constants.%.a6b)]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %U.loc16_17.1 [symbolic = %pattern_type (constants.%pattern_type.62e)]
|
|
// CHECK:STDOUT: %return.param_patt.loc16_28.2: @I.WithSelf.F.%pattern_type (%pattern_type.62e) = out_param_pattern [symbolic = %return.param_patt.loc16_28.2 (constants.%return.param_patt)]
|
|
// CHECK:STDOUT: %return.patt.loc16_25.2: @I.WithSelf.F.%pattern_type (%pattern_type.62e) = return_slot_pattern %return.param_patt.loc16_28.2, %U.loc16_17.1 [symbolic = %return.patt.loc16_25.2 (constants.%return.patt)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn() -> out %return.param: @I.WithSelf.F.%U.loc16_17.1 (%U);
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @G(%T.loc19_15.2: type) {
|
|
// CHECK:STDOUT: %T.patt.loc19_15.2: %pattern_type.9a5 = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc19_15.2 (constants.%T.patt)]
|
|
// CHECK:STDOUT: %T.loc19_15.1: type = symbolic_binding T, 0 [symbolic = %T.loc19_15.1 (constants.%T)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %I.type.loc23_6.2: type = facet_type <@I, @I(%T.loc19_15.1)> [symbolic = %I.type.loc23_6.2 (constants.%I.type.3fe)]
|
|
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %I.type.loc23_6.2 [symbolic = %require_complete (constants.%require_complete)]
|
|
// CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I, @I(%T.loc19_15.1) [symbolic = %I.assoc_type (constants.%I.assoc_type.b71)]
|
|
// CHECK:STDOUT: %assoc0: @G.%I.assoc_type (%I.assoc_type.b71) = assoc_entity element0, @I.WithSelf.%I.WithSelf.F.decl [symbolic = %assoc0 (constants.%assoc0.13b)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %I.ref: %I.type.335 = name_ref I, file.%I.decl [concrete = constants.%I.generic]
|
|
// CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc19_15.2 [symbolic = %T.loc19_15.1 (constants.%T)]
|
|
// CHECK:STDOUT: %I.type.loc23_6.1: type = facet_type <@I, @I(constants.%T)> [symbolic = %I.type.loc23_6.2 (constants.%I.type.3fe)]
|
|
// CHECK:STDOUT: %.loc23: @G.%I.assoc_type (%I.assoc_type.b71) = specific_constant @I.WithSelf.%assoc0.loc16_29.1, @I.WithSelf(constants.%T, constants.%Self.191) [symbolic = %assoc0 (constants.%assoc0.13b)]
|
|
// CHECK:STDOUT: %F.ref: @G.%I.assoc_type (%I.assoc_type.b71) = name_ref F, %.loc23 [symbolic = %assoc0 (constants.%assoc0.13b)]
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @H() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
|
|
// CHECK:STDOUT: %.loc27_6: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
|
|
// CHECK:STDOUT: %.loc27_7: type = converted %.loc27_6, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
|
|
// CHECK:STDOUT: %G.specific_fn: <specific function> = specific_function %G.ref, @G(constants.%empty_struct_type) [concrete = constants.%G.specific_fn]
|
|
// CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.specific_fn()
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @I(constants.%T) {
|
|
// CHECK:STDOUT: %T.patt.loc15_14.2 => constants.%T.patt
|
|
// CHECK:STDOUT: %T.loc15_14.1 => constants.%T
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %I.type => constants.%I.type.3fe
|
|
// CHECK:STDOUT: %Self.loc15_22.2 => constants.%Self.191
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @I.WithSelf(constants.%T, constants.%Self.191) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %T => constants.%T
|
|
// CHECK:STDOUT: %I.type => constants.%I.type.3fe
|
|
// CHECK:STDOUT: %Self => constants.%Self.191
|
|
// CHECK:STDOUT: %I.WithSelf.F.type => constants.%I.WithSelf.F.type.09f
|
|
// CHECK:STDOUT: %I.WithSelf.F => constants.%I.WithSelf.F.5f2
|
|
// CHECK:STDOUT: %I.assoc_type => constants.%I.assoc_type.b71
|
|
// CHECK:STDOUT: %assoc0.loc16_29.2 => constants.%assoc0.13b
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @I.WithSelf.F(constants.%T, constants.%Self.191, constants.%U) {
|
|
// CHECK:STDOUT: %U.patt.loc16_17.2 => constants.%U.patt
|
|
// CHECK:STDOUT: %U.loc16_17.1 => constants.%U
|
|
// CHECK:STDOUT: %.loc16_28.1 => constants.%.a6b
|
|
// CHECK:STDOUT: %pattern_type => constants.%pattern_type.62e
|
|
// CHECK:STDOUT: %return.param_patt.loc16_28.2 => constants.%return.param_patt
|
|
// CHECK:STDOUT: %return.patt.loc16_25.2 => constants.%return.patt
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @G(constants.%T) {
|
|
// CHECK:STDOUT: %T.patt.loc19_15.2 => constants.%T.patt
|
|
// CHECK:STDOUT: %T.loc19_15.1 => constants.%T
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @G(constants.%empty_struct_type) {
|
|
// CHECK:STDOUT: %T.patt.loc19_15.2 => constants.%T.patt
|
|
// CHECK:STDOUT: %T.loc19_15.1 => constants.%empty_struct_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %I.type.loc23_6.2 => constants.%I.type.81d
|
|
// CHECK:STDOUT: %require_complete => constants.%complete_type
|
|
// CHECK:STDOUT: %I.assoc_type => constants.%I.assoc_type.cd3
|
|
// CHECK:STDOUT: %assoc0 => constants.%assoc0.a4c
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @I(constants.%empty_struct_type) {
|
|
// CHECK:STDOUT: %T.patt.loc15_14.2 => constants.%T.patt
|
|
// CHECK:STDOUT: %T.loc15_14.1 => constants.%empty_struct_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %I.type => constants.%I.type.81d
|
|
// CHECK:STDOUT: %Self.loc15_22.2 => constants.%Self.524
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @I.WithSelf(constants.%empty_struct_type, constants.%Self.191) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %T => constants.%empty_struct_type
|
|
// CHECK:STDOUT: %I.type => constants.%I.type.81d
|
|
// CHECK:STDOUT: %Self => constants.%Self.191
|
|
// CHECK:STDOUT: %I.WithSelf.F.type => constants.%I.WithSelf.F.type.272
|
|
// CHECK:STDOUT: %I.WithSelf.F => constants.%I.WithSelf.F.fb6
|
|
// CHECK:STDOUT: %I.assoc_type => constants.%I.assoc_type.cd3
|
|
// CHECK:STDOUT: %assoc0.loc16_29.2 => constants.%assoc0.a4c
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|