bit_complement.carbon 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/overloaded/bit_complement.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/bit_complement.carbon
  10. // This file was generated from unary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  11. package User;
  12. class C {};
  13. impl C as Core.BitComplement {
  14. fn Op[self: C]() -> C {
  15. return {};
  16. }
  17. }
  18. fn TestOp(a: C) -> C {
  19. return ^a;
  20. }
  21. // CHECK:STDOUT: --- bit_complement.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %C: type = class_type @C [template]
  25. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  26. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  27. // CHECK:STDOUT: %.3: type = interface_type @BitComplement [template]
  28. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self, 0 [symbolic]
  29. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  30. // CHECK:STDOUT: %.4: type = tuple_type () [template]
  31. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  32. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  33. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  34. // CHECK:STDOUT: %.5: <witness> = interface_witness (%Op.1) [template]
  35. // CHECK:STDOUT: %.6: type = ptr_type %.1 [template]
  36. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  37. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [template]
  38. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [template]
  39. // CHECK:STDOUT: %.7: type = assoc_entity_type %.3, %Op.type.2 [template]
  40. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.5 [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  45. // CHECK:STDOUT: .BitComplement = %import_ref.1
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/operators
  48. // CHECK:STDOUT: import Core//prelude/types
  49. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  50. // CHECK:STDOUT: import Core//prelude/operators/as
  51. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  52. // CHECK:STDOUT: import Core//prelude/operators/comparison
  53. // CHECK:STDOUT: import Core//prelude/types/bool
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %import_ref.1: type = import_ref Core//prelude/operators/bitwise, inst+1, loaded [template = constants.%.3]
  56. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/bitwise, inst+3, unloaded
  57. // CHECK:STDOUT: %import_ref.3: %.7 = import_ref Core//prelude/operators/bitwise, inst+21, loaded [template = constants.%.8]
  58. // CHECK:STDOUT: %import_ref.4: %Op.type.2 = import_ref Core//prelude/operators/bitwise, inst+15, loaded [template = constants.%Op.2]
  59. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/bitwise, inst+15, unloaded
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .C = %C.decl
  66. // CHECK:STDOUT: .TestOp = %TestOp.decl
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core.import = import Core
  69. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  70. // CHECK:STDOUT: impl_decl @impl [template] {} {
  71. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  72. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  73. // CHECK:STDOUT: %BitComplement.ref: type = name_ref BitComplement, imports.%import_ref.1 [template = constants.%.3]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [template = constants.%TestOp] {
  76. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  77. // CHECK:STDOUT: } {
  78. // CHECK:STDOUT: %C.ref.loc23_14: type = name_ref C, file.%C.decl [template = constants.%C]
  79. // CHECK:STDOUT: %a.param: %C = param a, runtime_param0
  80. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  81. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [template = constants.%C]
  82. // CHECK:STDOUT: %return: ref %C = var <return slot>
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: interface @BitComplement {
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = imports.%import_ref.2
  89. // CHECK:STDOUT: .Op = imports.%import_ref.3
  90. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: impl @impl: %C.ref as %BitComplement.ref {
  94. // CHECK:STDOUT: %Op.decl: %Op.type.1 = fn_decl @Op.1 [template = constants.%Op.1] {
  95. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  96. // CHECK:STDOUT: } {
  97. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [template = constants.%C]
  98. // CHECK:STDOUT: %self.param: %C = param self, runtime_param0
  99. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  100. // CHECK:STDOUT: %C.ref.loc18_23: type = name_ref C, file.%C.decl [template = constants.%C]
  101. // CHECK:STDOUT: %return: ref %C = var <return slot>
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %.loc17: <witness> = interface_witness (%Op.decl) [template = constants.%.5]
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: !members:
  106. // CHECK:STDOUT: .Op = %Op.decl
  107. // CHECK:STDOUT: witness = %.loc17
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: class @C {
  111. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.1 [template = constants.%.2]
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: !members:
  114. // CHECK:STDOUT: .Self = constants.%C
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @Op.1[%self: %C]() -> %return: %C {
  118. // CHECK:STDOUT: !entry:
  119. // CHECK:STDOUT: %.loc19_13.1: %.1 = struct_literal ()
  120. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), %return [template = constants.%struct]
  121. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [template = constants.%struct]
  122. // CHECK:STDOUT: return %.loc19_14 to %return
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: generic fn @Op.2(constants.%Self: %.3) {
  126. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: fn[%self: @Op.2.%Self (%Self)]() -> @Op.2.%Self (%Self);
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @TestOp(%a: %C) -> %return: %C {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  134. // CHECK:STDOUT: %Op.ref: %.7 = name_ref Op, imports.%import_ref.3 [template = constants.%.8]
  135. // CHECK:STDOUT: %.loc24_10.1: %Op.type.2 = interface_witness_access constants.%.5, element0 [template = constants.%Op.1]
  136. // CHECK:STDOUT: %.loc24_10.2: <bound method> = bound_method %a.ref, %.loc24_10.1
  137. // CHECK:STDOUT: %.loc23: ref %C = splice_block %return {}
  138. // CHECK:STDOUT: %Op.call: init %C = call %.loc24_10.2(%a.ref) to %.loc23
  139. // CHECK:STDOUT: return %Op.call to %return
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: specific @Op.2(constants.%Self) {
  143. // CHECK:STDOUT: %Self => constants.%Self
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: specific @Op.2(constants.%C) {
  147. // CHECK:STDOUT: %Self => constants.%C
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: