| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- // 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/int.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/class/base_method_qualified.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/base_method_qualified.carbon
- class Derived;
- base class Base {
- fn F[self: Self]() -> i32;
- fn G[self: Derived]() -> i32;
- }
- class Derived {
- extend base: Base;
- fn F[self: Self]();
- fn G[self: Self]();
- }
- fn Call(a: Derived) -> i32 {
- return a.(Base.F)();
- }
- fn CallIndirect(p: Derived*) -> i32 {
- return p->(Base.F)();
- }
- fn PassDerivedToBase(a: Derived) -> i32 {
- return a.(Base.G)();
- }
- fn PassDerivedToBaseIndirect(p: Derived*) -> i32 {
- return p->(Base.G)();
- }
- // CHECK:STDOUT: --- base_method_qualified.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
- // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
- // CHECK:STDOUT: %pattern_type.bcc: type = pattern_type %Base [concrete]
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
- // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
- // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
- // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
- // CHECK:STDOUT: %Base.F.type: type = fn_type @Base.F [concrete]
- // CHECK:STDOUT: %Base.F: %Base.F.type = struct_value () [concrete]
- // CHECK:STDOUT: %pattern_type.fb9: type = pattern_type %Derived [concrete]
- // CHECK:STDOUT: %Base.G.type: type = fn_type @Base.G [concrete]
- // CHECK:STDOUT: %Base.G: %Base.G.type = struct_value () [concrete]
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
- // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
- // CHECK:STDOUT: %Derived.elem: type = unbound_element_type %Derived, %Base [concrete]
- // CHECK:STDOUT: %Derived.F.type: type = fn_type @Derived.F [concrete]
- // CHECK:STDOUT: %Derived.F: %Derived.F.type = struct_value () [concrete]
- // CHECK:STDOUT: %Derived.G.type: type = fn_type @Derived.G [concrete]
- // CHECK:STDOUT: %Derived.G: %Derived.G.type = struct_value () [concrete]
- // CHECK:STDOUT: %struct_type.base.b1e: type = struct_type {.base: %Base} [concrete]
- // CHECK:STDOUT: %complete_type.15c: <witness> = complete_type_witness %struct_type.base.b1e [concrete]
- // CHECK:STDOUT: %Call.type: type = fn_type @Call [concrete]
- // CHECK:STDOUT: %Call: %Call.type = struct_value () [concrete]
- // CHECK:STDOUT: %ptr.404: type = ptr_type %Derived [concrete]
- // CHECK:STDOUT: %pattern_type.605: type = pattern_type %ptr.404 [concrete]
- // CHECK:STDOUT: %CallIndirect.type: type = fn_type @CallIndirect [concrete]
- // CHECK:STDOUT: %CallIndirect: %CallIndirect.type = struct_value () [concrete]
- // CHECK:STDOUT: %PassDerivedToBase.type: type = fn_type @PassDerivedToBase [concrete]
- // CHECK:STDOUT: %PassDerivedToBase: %PassDerivedToBase.type = struct_value () [concrete]
- // CHECK:STDOUT: %PassDerivedToBaseIndirect.type: type = fn_type @PassDerivedToBaseIndirect [concrete]
- // CHECK:STDOUT: %PassDerivedToBaseIndirect: %PassDerivedToBaseIndirect.type = struct_value () [concrete]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
- // CHECK:STDOUT: .Int = %Core.Int
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .Derived = %Derived.decl.loc15
- // CHECK:STDOUT: .Base = %Base.decl
- // CHECK:STDOUT: .Call = %Call.decl
- // CHECK:STDOUT: .CallIndirect = %CallIndirect.decl
- // CHECK:STDOUT: .PassDerivedToBase = %PassDerivedToBase.decl
- // CHECK:STDOUT: .PassDerivedToBaseIndirect = %PassDerivedToBaseIndirect.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %Derived.decl.loc15: type = class_decl @Derived [concrete = constants.%Derived] {} {}
- // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
- // CHECK:STDOUT: %Derived.decl.loc22: type = class_decl @Derived [concrete = constants.%Derived] {} {}
- // CHECK:STDOUT: %Call.decl: %Call.type = fn_decl @Call [concrete = constants.%Call] {
- // CHECK:STDOUT: %a.patt: %pattern_type.fb9 = value_binding_pattern a [concrete]
- // CHECK:STDOUT: %a.param_patt: %pattern_type.fb9 = value_param_pattern %a.patt, call_param0 [concrete]
- // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
- // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
- // CHECK:STDOUT: %a.param: %Derived = value_param call_param0
- // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl.loc15 [concrete = constants.%Derived]
- // CHECK:STDOUT: %a: %Derived = value_binding a, %a.param
- // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
- // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %CallIndirect.decl: %CallIndirect.type = fn_decl @CallIndirect [concrete = constants.%CallIndirect] {
- // CHECK:STDOUT: %p.patt: %pattern_type.605 = value_binding_pattern p [concrete]
- // CHECK:STDOUT: %p.param_patt: %pattern_type.605 = value_param_pattern %p.patt, call_param0 [concrete]
- // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
- // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
- // CHECK:STDOUT: %p.param: %ptr.404 = value_param call_param0
- // CHECK:STDOUT: %.loc33: type = splice_block %ptr [concrete = constants.%ptr.404] {
- // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl.loc15 [concrete = constants.%Derived]
- // CHECK:STDOUT: %ptr: type = ptr_type %Derived.ref [concrete = constants.%ptr.404]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %p: %ptr.404 = value_binding p, %p.param
- // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
- // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %PassDerivedToBase.decl: %PassDerivedToBase.type = fn_decl @PassDerivedToBase [concrete = constants.%PassDerivedToBase] {
- // CHECK:STDOUT: %a.patt: %pattern_type.fb9 = value_binding_pattern a [concrete]
- // CHECK:STDOUT: %a.param_patt: %pattern_type.fb9 = value_param_pattern %a.patt, call_param0 [concrete]
- // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
- // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
- // CHECK:STDOUT: %a.param: %Derived = value_param call_param0
- // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl.loc15 [concrete = constants.%Derived]
- // CHECK:STDOUT: %a: %Derived = value_binding a, %a.param
- // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
- // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %PassDerivedToBaseIndirect.decl: %PassDerivedToBaseIndirect.type = fn_decl @PassDerivedToBaseIndirect [concrete = constants.%PassDerivedToBaseIndirect] {
- // CHECK:STDOUT: %p.patt: %pattern_type.605 = value_binding_pattern p [concrete]
- // CHECK:STDOUT: %p.param_patt: %pattern_type.605 = value_param_pattern %p.patt, call_param0 [concrete]
- // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
- // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
- // CHECK:STDOUT: %p.param: %ptr.404 = value_param call_param0
- // CHECK:STDOUT: %.loc41: type = splice_block %ptr [concrete = constants.%ptr.404] {
- // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl.loc15 [concrete = constants.%Derived]
- // CHECK:STDOUT: %ptr: type = ptr_type %Derived.ref [concrete = constants.%ptr.404]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %p: %ptr.404 = value_binding p, %p.param
- // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
- // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Derived {
- // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
- // CHECK:STDOUT: %.loc23: %Derived.elem = base_decl %Base.ref, element0 [concrete]
- // CHECK:STDOUT: %Derived.F.decl: %Derived.F.type = fn_decl @Derived.F [concrete = constants.%Derived.F] {
- // CHECK:STDOUT: %self.patt: %pattern_type.fb9 = value_binding_pattern self [concrete]
- // CHECK:STDOUT: %self.param_patt: %pattern_type.fb9 = value_param_pattern %self.patt, call_param0 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %self.param: %Derived = value_param call_param0
- // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Derived [concrete = constants.%Derived]
- // CHECK:STDOUT: %self: %Derived = value_binding self, %self.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Derived.G.decl: %Derived.G.type = fn_decl @Derived.G [concrete = constants.%Derived.G] {
- // CHECK:STDOUT: %self.patt: %pattern_type.fb9 = value_binding_pattern self [concrete]
- // CHECK:STDOUT: %self.param_patt: %pattern_type.fb9 = value_param_pattern %self.patt, call_param0 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %self.param: %Derived = value_param call_param0
- // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Derived [concrete = constants.%Derived]
- // CHECK:STDOUT: %self: %Derived = value_binding self, %self.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.base.b1e [concrete = constants.%complete_type.15c]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Derived
- // CHECK:STDOUT: .Base = <poisoned>
- // CHECK:STDOUT: .base = %.loc23
- // CHECK:STDOUT: .F = %Derived.F.decl
- // CHECK:STDOUT: .G = %Derived.G.decl
- // CHECK:STDOUT: extend %Base.ref
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Base {
- // CHECK:STDOUT: %Base.F.decl: %Base.F.type = fn_decl @Base.F [concrete = constants.%Base.F] {
- // CHECK:STDOUT: %self.patt: %pattern_type.bcc = value_binding_pattern self [concrete]
- // CHECK:STDOUT: %self.param_patt: %pattern_type.bcc = value_param_pattern %self.patt, call_param0 [concrete]
- // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
- // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
- // CHECK:STDOUT: %self.param: %Base = value_param call_param0
- // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Base [concrete = constants.%Base]
- // CHECK:STDOUT: %self: %Base = value_binding self, %self.param
- // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
- // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Base.G.decl: %Base.G.type = fn_decl @Base.G [concrete = constants.%Base.G] {
- // CHECK:STDOUT: %self.patt: %pattern_type.fb9 = value_binding_pattern self [concrete]
- // CHECK:STDOUT: %self.param_patt: %pattern_type.fb9 = value_param_pattern %self.patt, call_param0 [concrete]
- // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
- // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
- // CHECK:STDOUT: %self.param: %Derived = value_param call_param0
- // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl.loc15 [concrete = constants.%Derived]
- // CHECK:STDOUT: %self: %Derived = value_binding self, %self.param
- // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
- // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Base
- // CHECK:STDOUT: .F = %Base.F.decl
- // CHECK:STDOUT: .Derived = <poisoned>
- // CHECK:STDOUT: .G = %Base.G.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Base.F(%self.param: %Base) -> %i32;
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Base.G(%self.param: %Derived) -> %i32;
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Derived.F(%self.param: %Derived);
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Derived.G(%self.param: %Derived);
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Call(%a.param: %Derived) -> %i32 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %a.ref: %Derived = name_ref a, %a
- // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
- // CHECK:STDOUT: %F.ref: %Base.F.type = name_ref F, @Base.%Base.F.decl [concrete = constants.%Base.F]
- // CHECK:STDOUT: %Base.F.bound: <bound method> = bound_method %a.ref, %F.ref
- // CHECK:STDOUT: %.loc30_10.1: ref %Base = class_element_access %a.ref, element0
- // CHECK:STDOUT: %.loc30_10.2: ref %Base = converted %a.ref, %.loc30_10.1
- // CHECK:STDOUT: %.loc30_10.3: %Base = acquire_value %.loc30_10.2
- // CHECK:STDOUT: %Base.F.call: init %i32 = call %Base.F.bound(%.loc30_10.3)
- // CHECK:STDOUT: return %Base.F.call to %return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @CallIndirect(%p.param: %ptr.404) -> %i32 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %p.ref: %ptr.404 = name_ref p, %p
- // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
- // CHECK:STDOUT: %F.ref: %Base.F.type = name_ref F, @Base.%Base.F.decl [concrete = constants.%Base.F]
- // CHECK:STDOUT: %.loc34_11.1: ref %Derived = deref %p.ref
- // CHECK:STDOUT: %Base.F.bound: <bound method> = bound_method %.loc34_11.1, %F.ref
- // CHECK:STDOUT: %.loc34_11.2: ref %Base = class_element_access %.loc34_11.1, element0
- // CHECK:STDOUT: %.loc34_11.3: ref %Base = converted %.loc34_11.1, %.loc34_11.2
- // CHECK:STDOUT: %.loc34_11.4: %Base = acquire_value %.loc34_11.3
- // CHECK:STDOUT: %Base.F.call: init %i32 = call %Base.F.bound(%.loc34_11.4)
- // CHECK:STDOUT: return %Base.F.call to %return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @PassDerivedToBase(%a.param: %Derived) -> %i32 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %a.ref: %Derived = name_ref a, %a
- // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
- // CHECK:STDOUT: %G.ref: %Base.G.type = name_ref G, @Base.%Base.G.decl [concrete = constants.%Base.G]
- // CHECK:STDOUT: %Base.G.bound: <bound method> = bound_method %a.ref, %G.ref
- // CHECK:STDOUT: %Base.G.call: init %i32 = call %Base.G.bound(%a.ref)
- // CHECK:STDOUT: return %Base.G.call to %return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @PassDerivedToBaseIndirect(%p.param: %ptr.404) -> %i32 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %p.ref: %ptr.404 = name_ref p, %p
- // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
- // CHECK:STDOUT: %G.ref: %Base.G.type = name_ref G, @Base.%Base.G.decl [concrete = constants.%Base.G]
- // CHECK:STDOUT: %.loc42_11.1: ref %Derived = deref %p.ref
- // CHECK:STDOUT: %Base.G.bound: <bound method> = bound_method %.loc42_11.1, %G.ref
- // CHECK:STDOUT: %.loc42_11.2: %Derived = acquire_value %.loc42_11.1
- // CHECK:STDOUT: %Base.G.call: init %i32 = call %Base.G.bound(%.loc42_11.2)
- // CHECK:STDOUT: return %Base.G.call to %return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|