bit_complement.carbon 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/overloaded/bit_complement.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/bit_complement.carbon
  13. // This file was generated from unary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  14. package User;
  15. class C {};
  16. impl C as Core.BitComplement {
  17. fn Op[self: C]() -> C {
  18. return {};
  19. }
  20. }
  21. fn TestOp(a: C) -> C {
  22. return ^a;
  23. }
  24. // CHECK:STDOUT: --- bit_complement.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  28. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  29. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  30. // CHECK:STDOUT: %BitComplement.type: type = facet_type <@BitComplement> [concrete]
  31. // CHECK:STDOUT: %Op.type.f25: type = fn_type @Op.1 [concrete]
  32. // CHECK:STDOUT: %BitComplement.impl_witness: <witness> = impl_witness file.%BitComplement.impl_witness_table [concrete]
  33. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  34. // CHECK:STDOUT: %Op.type.544: type = fn_type @Op.2 [concrete]
  35. // CHECK:STDOUT: %Op.bf2: %Op.type.544 = struct_value () [concrete]
  36. // CHECK:STDOUT: %BitComplement.facet: %BitComplement.type = facet_value %C, (%BitComplement.impl_witness) [concrete]
  37. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  38. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [concrete]
  39. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [concrete]
  40. // CHECK:STDOUT: %.669: type = fn_type_with_self_type %Op.type.f25, %BitComplement.facet [concrete]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  45. // CHECK:STDOUT: .BitComplement = %Core.BitComplement
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.BitComplement: type = import_ref Core//prelude/operators/bitwise, BitComplement, loaded [concrete = constants.%BitComplement.type]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  54. // CHECK:STDOUT: .Core = imports.%Core
  55. // CHECK:STDOUT: .C = %C.decl
  56. // CHECK:STDOUT: .TestOp = %TestOp.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  60. // CHECK:STDOUT: impl_decl @impl.5a3 [concrete] {} {
  61. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  62. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  63. // CHECK:STDOUT: %BitComplement.ref: type = name_ref BitComplement, imports.%Core.BitComplement [concrete = constants.%BitComplement.type]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %BitComplement.impl_witness_table = impl_witness_table (@impl.5a3.%Op.decl), @impl.5a3 [concrete]
  66. // CHECK:STDOUT: %BitComplement.impl_witness: <witness> = impl_witness %BitComplement.impl_witness_table [concrete = constants.%BitComplement.impl_witness]
  67. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [concrete = constants.%TestOp] {
  68. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  69. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  70. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  71. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param1 [concrete]
  72. // CHECK:STDOUT: } {
  73. // CHECK:STDOUT: %C.ref.loc26_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
  74. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  75. // CHECK:STDOUT: %C.ref.loc26_14: type = name_ref C, file.%C.decl [concrete = constants.%C]
  76. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  77. // CHECK:STDOUT: %return.param: ref %C = out_param call_param1
  78. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: impl @impl.5a3: %C.ref as %BitComplement.ref {
  83. // CHECK:STDOUT: %Op.decl: %Op.type.544 = fn_decl @Op.2 [concrete = constants.%Op.bf2] {
  84. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  85. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  86. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  87. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param1 [concrete]
  88. // CHECK:STDOUT: } {
  89. // CHECK:STDOUT: %C.ref.loc21_23: type = name_ref C, file.%C.decl [concrete = constants.%C]
  90. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  91. // CHECK:STDOUT: %C.ref.loc21_15: type = name_ref C, file.%C.decl [concrete = constants.%C]
  92. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  93. // CHECK:STDOUT: %return.param: ref %C = out_param call_param1
  94. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .C = <poisoned>
  99. // CHECK:STDOUT: .Op = %Op.decl
  100. // CHECK:STDOUT: witness = file.%BitComplement.impl_witness
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: class @C {
  104. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  105. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  106. // CHECK:STDOUT: complete_type_witness = %complete_type
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: !members:
  109. // CHECK:STDOUT: .Self = constants.%C
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: fn @Op.2(%self.param: %C) -> %return.param: %C {
  113. // CHECK:STDOUT: !entry:
  114. // CHECK:STDOUT: %.loc22_13.1: %empty_struct_type = struct_literal ()
  115. // CHECK:STDOUT: %.loc22_13.2: init %C = class_init (), %return [concrete = constants.%C.val]
  116. // CHECK:STDOUT: %.loc22_14: init %C = converted %.loc22_13.1, %.loc22_13.2 [concrete = constants.%C.val]
  117. // CHECK:STDOUT: return %.loc22_14 to %return
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @TestOp(%a.param: %C) -> %return.param: %C {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  123. // CHECK:STDOUT: %impl.elem0: %.669 = impl_witness_access constants.%BitComplement.impl_witness, element0 [concrete = constants.%Op.bf2]
  124. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  125. // CHECK:STDOUT: %.loc26: ref %C = splice_block %return {}
  126. // CHECK:STDOUT: %Op.call: init %C = call %bound_method(%a.ref) to %.loc26
  127. // CHECK:STDOUT: return %Op.call to %return
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: