Files
carbon-lang/toolchain/check/testdata/operators/overloaded/left_shift.carbon
T
Richard Smith 17411c5e78 Assign a name to interface_type instructions. (#4369)
This matches what we do for `class_type` and `function_type`.
2024-10-04 23:06:24 +00:00

272 lines
14 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/operators/overloaded/left_shift.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/left_shift.carbon
// This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
package User;
class C {};
impl C as Core.LeftShift {
fn Op[self: C](other: C) -> C {
return {};
}
}
impl C as Core.LeftShiftAssign {
fn Op[addr self: C*](other: C) {}
}
fn TestOp(a: C, b: C) -> C {
return a << b;
}
fn TestAssign(a: C*, b: C) {
*a <<= b;
}
// CHECK:STDOUT: --- left_shift.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %C: type = class_type @C [template]
// CHECK:STDOUT: %.1: type = struct_type {} [template]
// CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
// CHECK:STDOUT: %LeftShift.type: type = interface_type @LeftShift [template]
// CHECK:STDOUT: %Self.1: %LeftShift.type = bind_symbolic_name Self, 0 [symbolic]
// CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
// CHECK:STDOUT: %.3: type = tuple_type () [template]
// CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
// CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
// CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
// CHECK:STDOUT: %.4: <witness> = interface_witness (%Op.1) [template]
// CHECK:STDOUT: %.5: type = ptr_type %.1 [template]
// CHECK:STDOUT: %struct: %C = struct_value () [template]
// CHECK:STDOUT: %LeftShiftAssign.type: type = interface_type @LeftShiftAssign [template]
// CHECK:STDOUT: %Self.2: %LeftShiftAssign.type = bind_symbolic_name Self, 0 [symbolic]
// CHECK:STDOUT: %.6: type = ptr_type %C [template]
// CHECK:STDOUT: %Op.type.3: type = fn_type @Op.3 [template]
// CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
// CHECK:STDOUT: %Op.type.4: type = fn_type @Op.4 [template]
// CHECK:STDOUT: %Op.4: %Op.type.4 = struct_value () [template]
// CHECK:STDOUT: %.7: type = ptr_type %Self.2 [symbolic]
// CHECK:STDOUT: %.8: <witness> = interface_witness (%Op.3) [template]
// CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [template]
// CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [template]
// CHECK:STDOUT: %.9: type = assoc_entity_type %LeftShift.type, %Op.type.2 [template]
// CHECK:STDOUT: %.10: %.9 = assoc_entity element0, imports.%import_ref.9 [template]
// CHECK:STDOUT: %TestAssign.type: type = fn_type @TestAssign [template]
// CHECK:STDOUT: %TestAssign: %TestAssign.type = struct_value () [template]
// CHECK:STDOUT: %.11: type = assoc_entity_type %LeftShiftAssign.type, %Op.type.4 [template]
// CHECK:STDOUT: %.12: %.11 = assoc_entity element0, imports.%import_ref.10 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
// CHECK:STDOUT: .LeftShift = %import_ref.1
// CHECK:STDOUT: .LeftShiftAssign = %import_ref.5
// CHECK:STDOUT: import Core//prelude
// CHECK:STDOUT: import Core//prelude/operators
// CHECK:STDOUT: import Core//prelude/types
// CHECK:STDOUT: import Core//prelude/operators/arithmetic
// CHECK:STDOUT: import Core//prelude/operators/as
// CHECK:STDOUT: import Core//prelude/operators/bitwise
// CHECK:STDOUT: import Core//prelude/operators/comparison
// CHECK:STDOUT: import Core//prelude/types/bool
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: type = import_ref Core//prelude/operators/bitwise, inst+185, loaded [template = constants.%LeftShift.type]
// CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/bitwise, inst+187, unloaded
// CHECK:STDOUT: %import_ref.3: %.9 = import_ref Core//prelude/operators/bitwise, inst+210, loaded [template = constants.%.10]
// CHECK:STDOUT: %import_ref.4: %Op.type.2 = import_ref Core//prelude/operators/bitwise, inst+205, loaded [template = constants.%Op.2]
// CHECK:STDOUT: %import_ref.5: type = import_ref Core//prelude/operators/bitwise, inst+212, loaded [template = constants.%LeftShiftAssign.type]
// CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/bitwise, inst+214, unloaded
// CHECK:STDOUT: %import_ref.7: %.11 = import_ref Core//prelude/operators/bitwise, inst+237, loaded [template = constants.%.12]
// CHECK:STDOUT: %import_ref.8: %Op.type.4 = import_ref Core//prelude/operators/bitwise, inst+231, loaded [template = constants.%Op.4]
// CHECK:STDOUT: %import_ref.9 = import_ref Core//prelude/operators/bitwise, inst+205, unloaded
// CHECK:STDOUT: %import_ref.10 = import_ref Core//prelude/operators/bitwise, inst+231, unloaded
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Core = imports.%Core
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: .TestOp = %TestOp.decl
// CHECK:STDOUT: .TestAssign = %TestAssign.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
// CHECK:STDOUT: impl_decl @impl.1 [template] {} {
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
// CHECK:STDOUT: %LeftShift.ref: type = name_ref LeftShift, imports.%import_ref.1 [template = constants.%LeftShift.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: impl_decl @impl.2 [template] {} {
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
// CHECK:STDOUT: %LeftShiftAssign.ref: type = name_ref LeftShiftAssign, imports.%import_ref.5 [template = constants.%LeftShiftAssign.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [template = constants.%TestOp] {
// CHECK:STDOUT: %a.patt: %C = binding_pattern a
// CHECK:STDOUT: %b.patt: %C = binding_pattern b
// CHECK:STDOUT: } {
// CHECK:STDOUT: %C.ref.loc26_14: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %a.param: %C = param a, runtime_param0
// CHECK:STDOUT: %a: %C = bind_name a, %a.param
// CHECK:STDOUT: %C.ref.loc26_20: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %b.param: %C = param b, runtime_param1
// CHECK:STDOUT: %b: %C = bind_name b, %b.param
// CHECK:STDOUT: %C.ref.loc26_26: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %return: ref %C = var <return slot>
// CHECK:STDOUT: }
// CHECK:STDOUT: %TestAssign.decl: %TestAssign.type = fn_decl @TestAssign [template = constants.%TestAssign] {
// CHECK:STDOUT: %a.patt: %.6 = binding_pattern a
// CHECK:STDOUT: %b.patt: %C = binding_pattern b
// CHECK:STDOUT: } {
// CHECK:STDOUT: %C.ref.loc30_18: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %.loc30: type = ptr_type %C [template = constants.%.6]
// CHECK:STDOUT: %a.param: %.6 = param a, runtime_param0
// CHECK:STDOUT: %a: %.6 = bind_name a, %a.param
// CHECK:STDOUT: %C.ref.loc30_25: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %b.param: %C = param b, runtime_param1
// CHECK:STDOUT: %b: %C = bind_name b, %b.param
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @LeftShift {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = imports.%import_ref.2
// CHECK:STDOUT: .Op = imports.%import_ref.3
// CHECK:STDOUT: witness = (imports.%import_ref.4)
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @LeftShiftAssign {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = imports.%import_ref.6
// CHECK:STDOUT: .Op = imports.%import_ref.7
// CHECK:STDOUT: witness = (imports.%import_ref.8)
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @impl.1: %C.ref as %LeftShift.ref {
// CHECK:STDOUT: %Op.decl: %Op.type.1 = fn_decl @Op.1 [template = constants.%Op.1] {
// CHECK:STDOUT: %self.patt: %C = binding_pattern self
// CHECK:STDOUT: %other.patt: %C = binding_pattern other
// CHECK:STDOUT: } {
// CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %self.param: %C = param self, runtime_param0
// CHECK:STDOUT: %self: %C = bind_name self, %self.param
// CHECK:STDOUT: %C.ref.loc18_25: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %other.param: %C = param other, runtime_param1
// CHECK:STDOUT: %other: %C = bind_name other, %other.param
// CHECK:STDOUT: %C.ref.loc18_31: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %return: ref %C = var <return slot>
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc17: <witness> = interface_witness (%Op.decl) [template = constants.%.4]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Op = %Op.decl
// CHECK:STDOUT: witness = %.loc17
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: impl @impl.2: %C.ref as %LeftShiftAssign.ref {
// CHECK:STDOUT: %Op.decl: %Op.type.3 = fn_decl @Op.3 [template = constants.%Op.3] {
// CHECK:STDOUT: %self.patt: %.6 = binding_pattern self
// CHECK:STDOUT: %other.patt: %C = binding_pattern other
// CHECK:STDOUT: } {
// CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %.loc23_21: type = ptr_type %C [template = constants.%.6]
// CHECK:STDOUT: %self.param: %.6 = param self, runtime_param0
// CHECK:STDOUT: %self: %.6 = bind_name self, %self.param
// CHECK:STDOUT: %.loc23_9: %.6 = addr_pattern %self
// CHECK:STDOUT: %C.ref.loc23_31: type = name_ref C, file.%C.decl [template = constants.%C]
// CHECK:STDOUT: %other.param: %C = param other, runtime_param1
// CHECK:STDOUT: %other: %C = bind_name other, %other.param
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc22: <witness> = interface_witness (%Op.decl) [template = constants.%.8]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Op = %Op.decl
// CHECK:STDOUT: witness = %.loc22
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.1 [template = constants.%.2]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%C
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Op.1[%self: %C](%other: %C) -> %return: %C {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc19_13.1: %.1 = struct_literal ()
// CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), %return [template = constants.%struct]
// CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [template = constants.%struct]
// CHECK:STDOUT: return %.loc19_14 to %return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @Op.2(constants.%Self.1: %LeftShift.type) {
// CHECK:STDOUT: %Self: %LeftShift.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.1)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn[%self: @Op.2.%Self (%Self.1)](%other: @Op.2.%Self (%Self.1)) -> @Op.2.%Self (%Self.1);
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Op.3[addr %self: %.6](%other: %C) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @Op.4(constants.%Self.2: %LeftShiftAssign.type) {
// CHECK:STDOUT: %Self: %LeftShiftAssign.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self.2)]
// CHECK:STDOUT: %.2: type = ptr_type @Op.4.%Self (%Self.2) [symbolic = %.2 (constants.%.7)]
// CHECK:STDOUT:
// CHECK:STDOUT: fn[addr %self: @Op.4.%.2 (%.7)](%other: @Op.4.%Self (%Self.2));
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestOp(%a: %C, %b: %C) -> %return: %C {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %a.ref: %C = name_ref a, %a
// CHECK:STDOUT: %b.ref: %C = name_ref b, %b
// CHECK:STDOUT: %Op.ref: %.9 = name_ref Op, imports.%import_ref.3 [template = constants.%.10]
// CHECK:STDOUT: %.loc27_12.1: %Op.type.2 = interface_witness_access constants.%.4, element0 [template = constants.%Op.1]
// CHECK:STDOUT: %.loc27_12.2: <bound method> = bound_method %a.ref, %.loc27_12.1
// CHECK:STDOUT: %.loc26: ref %C = splice_block %return {}
// CHECK:STDOUT: %Op.call: init %C = call %.loc27_12.2(%a.ref, %b.ref) to %.loc26
// CHECK:STDOUT: return %Op.call to %return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestAssign(%a: %.6, %b: %C) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %a.ref: %.6 = name_ref a, %a
// CHECK:STDOUT: %.loc31_3.1: ref %C = deref %a.ref
// CHECK:STDOUT: %b.ref: %C = name_ref b, %b
// CHECK:STDOUT: %Op.ref: %.11 = name_ref Op, imports.%import_ref.7 [template = constants.%.12]
// CHECK:STDOUT: %.loc31_6.1: %Op.type.4 = interface_witness_access constants.%.8, element0 [template = constants.%Op.3]
// CHECK:STDOUT: %.loc31_6.2: <bound method> = bound_method %.loc31_3.1, %.loc31_6.1
// CHECK:STDOUT: %.loc31_3.2: %.6 = addr_of %.loc31_3.1
// CHECK:STDOUT: %Op.call: init %.3 = call %.loc31_6.2(%.loc31_3.2, %b.ref)
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Op.2(constants.%Self.1) {
// CHECK:STDOUT: %Self => constants.%Self.1
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Op.2(constants.%C) {
// CHECK:STDOUT: %Self => constants.%C
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Op.4(constants.%Self.2) {
// CHECK:STDOUT: %Self => constants.%Self.2
// CHECK:STDOUT: %.2 => constants.%.7
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @Op.4(constants.%C) {
// CHECK:STDOUT: %Self => constants.%C
// CHECK:STDOUT: %.2 => constants.%.6
// CHECK:STDOUT: }
// CHECK:STDOUT: