Files
carbon-lang/toolchain/check/testdata/interface/no_prelude/self.carbon
T
67f2c9ce26 Add a FacetValue instruction (#4545)
The new `FacetValue` instruction represents `C as I` for some type `C`
and facet type `I`. It is named `FacetValue` instead of just `Facet` to
parallel the `FacetType` instruction.

This PR uses this instruction represent the facet value `Self` in an
`impl` declaration. This instruction will be used in the future to also
support things like:

* `C as I` where `C` is a class; and
* forming a specific for a generic with a `T:! I` parameter where `T` is
being given a concrete value.

(Here `I` is an interface or other non-`type` facet type.)

Also do some renaming and add some comments to make things a bit more
clear.

* `FacetTypeAccess` -> `FacetAccessType` to clarify this is not access
of a facet type, but access of the type of a facet
* `.facet_id` -> `.facet_value_inst_id` to parallel the `FacetValue`
instruction

`FacetAccessWitness` will be in a future PR.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-11-21 22:29:53 +00:00

73 lines
4.0 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
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/no_prelude/self.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/no_prelude/self.carbon
interface UseSelf {
fn F[self: Self]() -> Self;
}
// CHECK:STDOUT: --- self.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %UseSelf.type: type = facet_type <@UseSelf> [template]
// CHECK:STDOUT: %Self: %UseSelf.type = bind_symbolic_name Self, 0 [symbolic]
// CHECK:STDOUT: %.1: type = facet_access_type %Self [symbolic]
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
// CHECK:STDOUT: %.2: type = assoc_entity_type %UseSelf.type, %F.type [template]
// CHECK:STDOUT: %.3: %.2 = assoc_entity element0, @UseSelf.%F.decl [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .UseSelf = %UseSelf.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %UseSelf.decl: type = interface_decl @UseSelf [template = constants.%UseSelf.type] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @UseSelf {
// CHECK:STDOUT: %Self: %UseSelf.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
// CHECK:STDOUT: %self.patt: @F.%.loc12_14.1 (%.1) = binding_pattern self
// CHECK:STDOUT: %self.param_patt: @F.%.loc12_14.1 (%.1) = value_param_pattern %self.patt, runtime_param0
// CHECK:STDOUT: %return.patt: @F.%.loc12_14.1 (%.1) = return_slot_pattern
// CHECK:STDOUT: %return.param_patt: @F.%.loc12_14.1 (%.1) = out_param_pattern %return.patt, runtime_param1
// CHECK:STDOUT: } {
// CHECK:STDOUT: %Self.ref.loc12_14: %UseSelf.type = name_ref Self, @UseSelf.%Self [symbolic = %Self (constants.%Self)]
// CHECK:STDOUT: %.loc12_14.2: type = facet_access_type %Self.ref.loc12_14 [symbolic = %.loc12_14.1 (constants.%.1)]
// CHECK:STDOUT: %.loc12_14.3: type = converted %Self.ref.loc12_14, %.loc12_14.2 [symbolic = %.loc12_14.1 (constants.%.1)]
// CHECK:STDOUT: %Self.ref.loc12_25: %UseSelf.type = name_ref Self, @UseSelf.%Self [symbolic = %Self (constants.%Self)]
// CHECK:STDOUT: %.loc12_25.1: type = facet_access_type %Self.ref.loc12_25 [symbolic = %.loc12_14.1 (constants.%.1)]
// CHECK:STDOUT: %.loc12_25.2: type = converted %Self.ref.loc12_25, %.loc12_25.1 [symbolic = %.loc12_14.1 (constants.%.1)]
// CHECK:STDOUT: %self.param: @F.%.loc12_14.1 (%.1) = value_param runtime_param0
// CHECK:STDOUT: %self: @F.%.loc12_14.1 (%.1) = bind_name self, %self.param
// CHECK:STDOUT: %return.param: ref @F.%.loc12_14.1 (%.1) = out_param runtime_param1
// CHECK:STDOUT: %return: ref @F.%.loc12_14.1 (%.1) = return_slot %return.param
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc12: %.2 = assoc_entity element0, %F.decl [template = constants.%.3]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = %Self
// CHECK:STDOUT: .F = %.loc12
// CHECK:STDOUT: witness = (%F.decl)
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @F(@UseSelf.%Self: %UseSelf.type) {
// CHECK:STDOUT: %Self: %UseSelf.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
// CHECK:STDOUT: %.loc12_14.1: type = facet_access_type %Self [symbolic = %.loc12_14.1 (constants.%.1)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn[%self.param_patt: @F.%.loc12_14.1 (%.1)]() -> @F.%.loc12_14.1 (%.1);
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @F(constants.%Self) {
// CHECK:STDOUT: %Self => constants.%Self
// CHECK:STDOUT: %.loc12_14.1 => constants.%.1
// CHECK:STDOUT: }
// CHECK:STDOUT: