mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +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.
138 lines
7.5 KiB
Plaintext
138 lines
7.5 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
|
|
// 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/pointer/arrow.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/arrow.carbon
|
|
|
|
class C {
|
|
fn Member(self);
|
|
var field: C*;
|
|
}
|
|
|
|
fn Foo(ptr: C*) {
|
|
(*ptr).Member();
|
|
ptr->Member();
|
|
|
|
(*ptr).field;
|
|
ptr->field;
|
|
|
|
ptr->field->field;
|
|
}
|
|
|
|
// 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]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type.98b = wrapper_binding_pattern self, %self.param_patt [concrete]
|
|
// CHECK:STDOUT: %C.Member.type: type = fn_type @C.Member [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %C.Member: %C.Member.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %ptr.6b6: type = ptr_type %C [concrete]
|
|
// CHECK:STDOUT: %pattern_type.fcb: type = pattern_type %ptr.6b6 [concrete]
|
|
// CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %ptr.6b6 [concrete]
|
|
// CHECK:STDOUT: %struct_type.field: type = struct_type {.field: %ptr.6b6} [concrete]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.field [concrete]
|
|
// CHECK:STDOUT: %ptr.param_patt: %pattern_type.fcb = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %ptr.patt: %pattern_type.fcb = wrapper_binding_pattern ptr, %ptr.param_patt [concrete]
|
|
// CHECK:STDOUT: %Foo.type: type = fn_type @Foo [concrete]
|
|
// CHECK:STDOUT: %Foo: %Foo.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .C = %C.decl
|
|
// CHECK:STDOUT: .Foo = %Foo.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
|
|
// CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [concrete = constants.%Foo] {
|
|
// CHECK:STDOUT: %ptr.param_patt: %pattern_type.fcb = value_param_pattern [concrete = constants.%ptr.param_patt]
|
|
// CHECK:STDOUT: %ptr.patt: %pattern_type.fcb = wrapper_binding_pattern ptr, %ptr.param_patt [concrete = constants.%ptr.patt]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %ptr.param: %ptr.6b6 = value_param call_param0
|
|
// CHECK:STDOUT: %.loc20: type = splice_block %ptr.loc20_14 [concrete = constants.%ptr.6b6] {
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr.loc20_14: type = ptr_type %C.ref [concrete = constants.%ptr.6b6]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %ptr.loc20_11: %ptr.6b6 = wrapper_binding ptr, %ptr.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @C {
|
|
// CHECK:STDOUT: %C.Member.decl: %C.Member.type = fn_decl @C.Member [concrete = constants.%C.Member] {
|
|
// CHECK:STDOUT: %self.param_patt: %pattern_type.98b = value_param_pattern [concrete = constants.%self.param_patt]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type.98b = wrapper_binding_pattern self, %self.param_patt [concrete = constants.%self.patt]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %self.param: %C = value_param call_param0
|
|
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
|
|
// CHECK:STDOUT: %self: %C = wrapper_binding self, %self.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %field_decl: %C.elem = field_decl field, element0, %ptr in [concrete] {
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr: type = ptr_type %C.ref [concrete = constants.%ptr.6b6]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.field [concrete = constants.%complete_type]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%C
|
|
// CHECK:STDOUT: .Member = %C.Member.decl
|
|
// CHECK:STDOUT: .C = <poisoned>
|
|
// CHECK:STDOUT: .field = %field_decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @C.Member(%self.param: %C);
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Foo(%ptr.param: %ptr.6b6) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %ptr.ref.loc21: %ptr.6b6 = name_ref ptr, %ptr.loc20_11
|
|
// CHECK:STDOUT: %.loc21_4.1: ref %C = deref %ptr.ref.loc21
|
|
// CHECK:STDOUT: %Member.ref.loc21: %C.Member.type = name_ref Member, @C.%C.Member.decl [concrete = constants.%C.Member]
|
|
// CHECK:STDOUT: %C.Member.bound.loc21: <bound method> = bound_method %.loc21_4.1, %Member.ref.loc21
|
|
// CHECK:STDOUT: %.loc21_4.2: %C = acquire_value %.loc21_4.1
|
|
// CHECK:STDOUT: %C.Member.call.loc21: init %empty_tuple.type = call %C.Member.bound.loc21(%.loc21_4.2)
|
|
// CHECK:STDOUT: %ptr.ref.loc22: %ptr.6b6 = name_ref ptr, %ptr.loc20_11
|
|
// CHECK:STDOUT: %.loc22_6.1: ref %C = deref %ptr.ref.loc22
|
|
// CHECK:STDOUT: %Member.ref.loc22: %C.Member.type = name_ref Member, @C.%C.Member.decl [concrete = constants.%C.Member]
|
|
// CHECK:STDOUT: %C.Member.bound.loc22: <bound method> = bound_method %.loc22_6.1, %Member.ref.loc22
|
|
// CHECK:STDOUT: %.loc22_6.2: %C = acquire_value %.loc22_6.1
|
|
// CHECK:STDOUT: %C.Member.call.loc22: init %empty_tuple.type = call %C.Member.bound.loc22(%.loc22_6.2)
|
|
// CHECK:STDOUT: %ptr.ref.loc24: %ptr.6b6 = name_ref ptr, %ptr.loc20_11
|
|
// CHECK:STDOUT: %.loc24_4: ref %C = deref %ptr.ref.loc24
|
|
// CHECK:STDOUT: %field.ref.loc24: %C.elem = name_ref field, @C.%field_decl [concrete = @C.%field_decl]
|
|
// CHECK:STDOUT: %.loc24_9: ref %ptr.6b6 = class_element_access %.loc24_4, element0
|
|
// CHECK:STDOUT: %ptr.ref.loc25: %ptr.6b6 = name_ref ptr, %ptr.loc20_11
|
|
// CHECK:STDOUT: %.loc25_6.1: ref %C = deref %ptr.ref.loc25
|
|
// CHECK:STDOUT: %field.ref.loc25: %C.elem = name_ref field, @C.%field_decl [concrete = @C.%field_decl]
|
|
// CHECK:STDOUT: %.loc25_6.2: ref %ptr.6b6 = class_element_access %.loc25_6.1, element0
|
|
// CHECK:STDOUT: %ptr.ref.loc27: %ptr.6b6 = name_ref ptr, %ptr.loc20_11
|
|
// CHECK:STDOUT: %.loc27_6.1: ref %C = deref %ptr.ref.loc27
|
|
// CHECK:STDOUT: %field.ref.loc27_6: %C.elem = name_ref field, @C.%field_decl [concrete = @C.%field_decl]
|
|
// CHECK:STDOUT: %.loc27_6.2: ref %ptr.6b6 = class_element_access %.loc27_6.1, element0
|
|
// CHECK:STDOUT: %.loc27_6.3: %ptr.6b6 = acquire_value %.loc27_6.2
|
|
// CHECK:STDOUT: %.loc27_13.1: ref %C = deref %.loc27_6.3
|
|
// CHECK:STDOUT: %field.ref.loc27_13: %C.elem = name_ref field, @C.%field_decl [concrete = @C.%field_decl]
|
|
// CHECK:STDOUT: %.loc27_13.2: ref %ptr.6b6 = class_element_access %.loc27_13.1, element0
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|