| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- // 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/impl/no_prelude/import_self.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/import_self.carbon
- // --- a.carbon
- library "[[@TEST_NAME]]";
- interface Add {
- fn Op[self: Self](other: Self) -> Self;
- }
- // --- b.carbon
- library "[[@TEST_NAME]]";
- import library "a";
- impl () as Add {
- fn Op[self: Self](other: Self) -> Self { return (); }
- }
- fn F(x: (), y: ()) -> () {
- return x.(Add.Op)(y);
- }
- // CHECK:STDOUT: --- a.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Add.type: type = facet_type <@Add> [template]
- // CHECK:STDOUT: %Self: %Add.type = bind_symbolic_name Self, 0 [symbolic]
- // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
- // CHECK:STDOUT: %Op.type: type = fn_type @Op [template]
- // CHECK:STDOUT: %Op: %Op.type = struct_value () [template]
- // CHECK:STDOUT: %Add.assoc_type: type = assoc_entity_type %Add.type [template]
- // CHECK:STDOUT: %assoc0: %Add.assoc_type = assoc_entity element0, @Add.%Op.decl [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Add = %Add.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Add.decl: type = interface_decl @Add [template = constants.%Add.type] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: interface @Add {
- // CHECK:STDOUT: %Self: %Add.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
- // CHECK:STDOUT: %Op.decl: %Op.type = fn_decl @Op [template = constants.%Op] {
- // CHECK:STDOUT: %self.patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = binding_pattern self
- // CHECK:STDOUT: %self.param_patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = value_param_pattern %self.patt, runtime_param0
- // CHECK:STDOUT: %other.patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = binding_pattern other
- // CHECK:STDOUT: %other.param_patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = value_param_pattern %other.patt, runtime_param1
- // CHECK:STDOUT: %return.patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = out_param_pattern %return.patt, runtime_param2
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %Self.ref.loc5_37: %Add.type = name_ref Self, @Add.%Self [symbolic = %Self (constants.%Self)]
- // CHECK:STDOUT: %Self.as_type.loc5_37: type = facet_access_type %Self.ref.loc5_37 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT: %.loc5_37: type = converted %Self.ref.loc5_37, %Self.as_type.loc5_37 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT: %self.param: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = value_param runtime_param0
- // CHECK:STDOUT: %.loc5_15.1: type = splice_block %.loc5_15.2 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)] {
- // CHECK:STDOUT: %Self.ref.loc5_15: %Add.type = name_ref Self, @Add.%Self [symbolic = %Self (constants.%Self)]
- // CHECK:STDOUT: %Self.as_type.loc5_15.2: type = facet_access_type %Self.ref.loc5_15 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT: %.loc5_15.2: type = converted %Self.ref.loc5_15, %Self.as_type.loc5_15.2 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %self: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = bind_name self, %self.param
- // CHECK:STDOUT: %other.param: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = value_param runtime_param1
- // CHECK:STDOUT: %.loc5_28.1: type = splice_block %.loc5_28.2 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)] {
- // CHECK:STDOUT: %Self.ref.loc5_28: %Add.type = name_ref Self, @Add.%Self [symbolic = %Self (constants.%Self)]
- // CHECK:STDOUT: %Self.as_type.loc5_28: type = facet_access_type %Self.ref.loc5_28 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT: %.loc5_28.2: type = converted %Self.ref.loc5_28, %Self.as_type.loc5_28 [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %other: @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = bind_name other, %other.param
- // CHECK:STDOUT: %return.param: ref @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = out_param runtime_param2
- // CHECK:STDOUT: %return: ref @Op.%Self.as_type.loc5_15.1 (%Self.as_type) = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %assoc0: %Add.assoc_type = assoc_entity element0, %Op.decl [template = constants.%assoc0]
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = %Self
- // CHECK:STDOUT: .Op = %assoc0
- // CHECK:STDOUT: witness = (%Op.decl)
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: generic fn @Op(@Add.%Self: %Add.type) {
- // CHECK:STDOUT: %Self: %Add.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
- // CHECK:STDOUT: %Self.as_type.loc5_15.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc5_15.1 (constants.%Self.as_type)]
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn[%self.param_patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type)](%other.param_patt: @Op.%Self.as_type.loc5_15.1 (%Self.as_type)) -> @Op.%Self.as_type.loc5_15.1 (%Self.as_type);
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: specific @Op(constants.%Self) {
- // CHECK:STDOUT: %Self => constants.%Self
- // CHECK:STDOUT: %Self.as_type.loc5_15.1 => constants.%Self.as_type
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- b.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
- // CHECK:STDOUT: %Add.type: type = facet_type <@Add> [template]
- // CHECK:STDOUT: %Self: %Add.type = bind_symbolic_name Self, 0 [symbolic]
- // CHECK:STDOUT: %Op.type.31b: type = fn_type @Op.1 [template]
- // CHECK:STDOUT: %Op.d59: %Op.type.31b = struct_value () [template]
- // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
- // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.%Op.decl) [template]
- // CHECK:STDOUT: %Op.type.adf: type = fn_type @Op.2 [template]
- // CHECK:STDOUT: %Op.489: %Op.type.adf = struct_value () [template]
- // CHECK:STDOUT: %Add.facet: %Add.type = facet_value %empty_tuple.type, %impl_witness [template]
- // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
- // CHECK:STDOUT: %F.type: type = fn_type @F [template]
- // CHECK:STDOUT: %F: %F.type = struct_value () [template]
- // CHECK:STDOUT: %Add.assoc_type: type = assoc_entity_type %Add.type [template]
- // CHECK:STDOUT: %assoc0: %Add.assoc_type = assoc_entity element0, imports.%Main.import_ref.5a3 [template]
- // CHECK:STDOUT: %.a26: type = fn_type_with_self_type %Op.type.31b, %Add.facet [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Main.Add: type = import_ref Main//a, Add, loaded [template = constants.%Add.type]
- // CHECK:STDOUT: %Main.import_ref.07c = import_ref Main//a, inst15 [no loc], unloaded
- // CHECK:STDOUT: %Main.import_ref.db7: %Add.assoc_type = import_ref Main//a, loc5_41, loaded [template = constants.%assoc0]
- // CHECK:STDOUT: %Main.Op: %Op.type.31b = import_ref Main//a, Op, loaded [template = constants.%Op.d59]
- // CHECK:STDOUT: %Main.import_ref.e5e: %Add.type = import_ref Main//a, inst15 [no loc], loaded [symbolic = constants.%Self]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Add = imports.%Main.Add
- // CHECK:STDOUT: .F = %F.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %default.import = import <none>
- // CHECK:STDOUT: impl_decl @impl [template] {} {
- // CHECK:STDOUT: %.loc6_7.1: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %.loc6_7.2: type = converted %.loc6_7.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: %Add.ref: type = name_ref Add, imports.%Main.Add [template = constants.%Add.type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.%Op.decl) [template = constants.%impl_witness]
- // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
- // CHECK:STDOUT: %x.patt: %empty_tuple.type = binding_pattern x
- // CHECK:STDOUT: %x.param_patt: %empty_tuple.type = value_param_pattern %x.patt, runtime_param0
- // CHECK:STDOUT: %y.patt: %empty_tuple.type = binding_pattern y
- // CHECK:STDOUT: %y.param_patt: %empty_tuple.type = value_param_pattern %y.patt, runtime_param1
- // CHECK:STDOUT: %return.patt: %empty_tuple.type = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: %empty_tuple.type = out_param_pattern %return.patt, runtime_param2
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %.loc10_24.1: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %.loc10_24.2: type = converted %.loc10_24.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param runtime_param0
- // CHECK:STDOUT: %.loc10_10.1: type = splice_block %.loc10_10.3 [template = constants.%empty_tuple.type] {
- // CHECK:STDOUT: %.loc10_10.2: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %.loc10_10.3: type = converted %.loc10_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x: %empty_tuple.type = bind_name x, %x.param
- // CHECK:STDOUT: %y.param: %empty_tuple.type = value_param runtime_param1
- // CHECK:STDOUT: %.loc10_17.1: type = splice_block %.loc10_17.3 [template = constants.%empty_tuple.type] {
- // CHECK:STDOUT: %.loc10_17.2: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %.loc10_17.3: type = converted %.loc10_17.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %y: %empty_tuple.type = bind_name y, %y.param
- // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param2
- // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: interface @Add [from "a.carbon"] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = imports.%Main.import_ref.07c
- // CHECK:STDOUT: .Op = imports.%Main.import_ref.db7
- // CHECK:STDOUT: witness = (imports.%Main.Op)
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: impl @impl: %.loc6_7.2 as %Add.ref {
- // CHECK:STDOUT: %Op.decl: %Op.type.adf = fn_decl @Op.2 [template = constants.%Op.489] {
- // CHECK:STDOUT: %self.patt: %empty_tuple.type = binding_pattern self
- // CHECK:STDOUT: %self.param_patt: %empty_tuple.type = value_param_pattern %self.patt, runtime_param0
- // CHECK:STDOUT: %other.patt: %empty_tuple.type = binding_pattern other
- // CHECK:STDOUT: %other.param_patt: %empty_tuple.type = value_param_pattern %other.patt, runtime_param1
- // CHECK:STDOUT: %return.patt: %empty_tuple.type = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: %empty_tuple.type = out_param_pattern %return.patt, runtime_param2
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %Self.ref.loc7_37: type = name_ref Self, @impl.%.loc6_7.2 [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: %self.param: %empty_tuple.type = value_param runtime_param0
- // CHECK:STDOUT: %Self.ref.loc7_15: type = name_ref Self, @impl.%.loc6_7.2 [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: %self: %empty_tuple.type = bind_name self, %self.param
- // CHECK:STDOUT: %other.param: %empty_tuple.type = value_param runtime_param1
- // CHECK:STDOUT: %Self.ref.loc7_28: type = name_ref Self, @impl.%.loc6_7.2 [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: %other: %empty_tuple.type = bind_name other, %other.param
- // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param2
- // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Op = %Op.decl
- // CHECK:STDOUT: witness = file.%impl_witness
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: generic fn @Op.1(imports.%Main.import_ref.e5e: %Add.type) [from "a.carbon"] {
- // CHECK:STDOUT: %Self: %Add.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
- // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic = %Self.as_type (constants.%Self.as_type)]
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn[%self.param_patt: @Op.1.%Self.as_type (%Self.as_type)](%other.param_patt: @Op.1.%Self.as_type (%Self.as_type)) -> @Op.1.%Self.as_type (%Self.as_type);
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Op.2[%self.param_patt: %empty_tuple.type](%other.param_patt: %empty_tuple.type) -> %empty_tuple.type {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %.loc7_52: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template = constants.%empty_tuple]
- // CHECK:STDOUT: %.loc7_53: %empty_tuple.type = converted %.loc7_52, %empty_tuple [template = constants.%empty_tuple]
- // CHECK:STDOUT: return %.loc7_53
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @F(%x.param_patt: %empty_tuple.type, %y.param_patt: %empty_tuple.type) -> %empty_tuple.type {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %x.ref: %empty_tuple.type = name_ref x, %x
- // CHECK:STDOUT: %Add.ref: type = name_ref Add, imports.%Main.Add [template = constants.%Add.type]
- // CHECK:STDOUT: %Op.ref: %Add.assoc_type = name_ref Op, imports.%Main.import_ref.db7 [template = constants.%assoc0]
- // CHECK:STDOUT: %impl.elem0: %.a26 = impl_witness_access constants.%impl_witness, element0 [template = constants.%Op.489]
- // CHECK:STDOUT: %bound_method: <bound method> = bound_method %x.ref, %impl.elem0
- // CHECK:STDOUT: %y.ref: %empty_tuple.type = name_ref y, %y
- // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%x.ref, %y.ref)
- // CHECK:STDOUT: %.loc11_22.1: ref %empty_tuple.type = temporary_storage
- // CHECK:STDOUT: %.loc11_22.2: ref %empty_tuple.type = temporary %.loc11_22.1, %Op.call
- // CHECK:STDOUT: %tuple: %empty_tuple.type = tuple_value () [template = constants.%empty_tuple]
- // CHECK:STDOUT: %.loc11_23: %empty_tuple.type = converted %Op.call, %tuple [template = constants.%empty_tuple]
- // CHECK:STDOUT: return %.loc11_23
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: specific @Op.1(constants.%Self) {
- // CHECK:STDOUT: %Self => constants.%Self
- // CHECK:STDOUT: %Self.as_type => constants.%Self.as_type
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: specific @Op.1(constants.%Add.facet) {
- // CHECK:STDOUT: %Self => constants.%Add.facet
- // CHECK:STDOUT: %Self.as_type => constants.%empty_tuple.type
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|