bit_complement.carbon 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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: type = interface_type @BitComplement [template]
  27. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 0 [symbolic]
  28. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  29. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  30. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  31. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  32. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  33. // CHECK:STDOUT: %.4: <witness> = interface_witness (%Op.1) [template]
  34. // CHECK:STDOUT: %.5: type = ptr_type %.1 [template]
  35. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  36. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [template]
  37. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [template]
  38. // CHECK:STDOUT: %.6: type = assoc_entity_type @BitComplement, %Op.type.2 [template]
  39. // CHECK:STDOUT: %.7: %.6 = assoc_entity element0, imports.%import_ref.6 [template]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %import_ref.1: type = import_ref Core//prelude/operators/bitwise, inst+1, loaded [template = constants.%.2]
  44. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/bitwise, inst+3, unloaded
  45. // CHECK:STDOUT: %import_ref.3: %.6 = import_ref Core//prelude/operators/bitwise, inst+20, loaded [template = constants.%.7]
  46. // CHECK:STDOUT: %import_ref.4: %Op.type.2 = import_ref Core//prelude/operators/bitwise, inst+14, loaded [template = constants.%Op.2]
  47. // CHECK:STDOUT: %import_ref.5: type = import_ref Core//prelude/operators/bitwise, inst+1, loaded [template = constants.%.2]
  48. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/bitwise, inst+14, unloaded
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = %Core
  54. // CHECK:STDOUT: .C = %C.decl
  55. // CHECK:STDOUT: .TestOp = %TestOp.decl
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  59. // CHECK:STDOUT: import Core//prelude
  60. // CHECK:STDOUT: import Core//prelude/operators
  61. // CHECK:STDOUT: import Core//prelude/types
  62. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  63. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  64. // CHECK:STDOUT: import Core//prelude/operators/comparison
  65. // CHECK:STDOUT: import Core//prelude/types/bool
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  68. // CHECK:STDOUT: impl_decl @impl {
  69. // CHECK:STDOUT: %C.ref.loc17: type = name_ref C, %C.decl [template = constants.%C]
  70. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
  71. // CHECK:STDOUT: %BitComplement.ref: type = name_ref BitComplement, imports.%import_ref.1 [template = constants.%.2]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [template = constants.%TestOp] {
  74. // CHECK:STDOUT: %C.ref.loc23_14: type = name_ref C, %C.decl [template = constants.%C]
  75. // CHECK:STDOUT: %a.loc23_11.1: %C = param a
  76. // CHECK:STDOUT: @TestOp.%a: %C = bind_name a, %a.loc23_11.1
  77. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, %C.decl [template = constants.%C]
  78. // CHECK:STDOUT: @TestOp.%return: ref %C = var <return slot>
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: interface @BitComplement {
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .Self = imports.%import_ref.2
  85. // CHECK:STDOUT: .Op = imports.%import_ref.3
  86. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: impl @impl: %C as %.2 {
  90. // CHECK:STDOUT: %Op.decl: %Op.type.1 = fn_decl @Op.1 [template = constants.%Op.1] {
  91. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [template = constants.%C]
  92. // CHECK:STDOUT: %self.loc18_9.1: %C = param self
  93. // CHECK:STDOUT: %self.loc18_9.2: %C = bind_name self, %self.loc18_9.1
  94. // CHECK:STDOUT: %C.ref.loc18_23: type = name_ref C, file.%C.decl [template = constants.%C]
  95. // CHECK:STDOUT: %return.var: ref %C = var <return slot>
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.4]
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: !members:
  100. // CHECK:STDOUT: .Op = %Op.decl
  101. // CHECK:STDOUT: witness = %.1
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: class @C {
  105. // CHECK:STDOUT: !members:
  106. // CHECK:STDOUT: .Self = constants.%C
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn @Op.1[@impl.%self.loc18_9.2: %C]() -> @impl.%return.var: %C {
  110. // CHECK:STDOUT: !entry:
  111. // CHECK:STDOUT: %.loc19_13.1: %.1 = struct_literal ()
  112. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), @impl.%return.var [template = constants.%struct]
  113. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [template = constants.%struct]
  114. // CHECK:STDOUT: return %.loc19_14 to @impl.%return.var
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @Op.2[%self: %Self]() -> %Self;
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @TestOp(%a: %C) -> %return: %C {
  120. // CHECK:STDOUT: !entry:
  121. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  122. // CHECK:STDOUT: %.1: %Op.type.2 = interface_witness_access @impl.%.1, element0 [template = constants.%Op.1]
  123. // CHECK:STDOUT: %.loc24: <bound method> = bound_method %a.ref, %.1
  124. // CHECK:STDOUT: %.loc23: ref %C = splice_block %return {}
  125. // CHECK:STDOUT: %Op.call: init %C = call %.loc24(%a.ref) to %.loc23
  126. // CHECK:STDOUT: return %Op.call to %return
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: