bit_complement.carbon 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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: %empty_struct_type: type = struct_type {} [template]
  26. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  27. // CHECK:STDOUT: %BitComplement.type: type = facet_type <@BitComplement> [template]
  28. // CHECK:STDOUT: %Op.type.f25: type = fn_type @Op.1 [template]
  29. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.1.%Op.decl) [template]
  30. // CHECK:STDOUT: %Op.type.544: type = fn_type @Op.2 [template]
  31. // CHECK:STDOUT: %Op.bf2: %Op.type.544 = struct_value () [template]
  32. // CHECK:STDOUT: %BitComplement.facet: %BitComplement.type = facet_value %C, %impl_witness [template]
  33. // CHECK:STDOUT: %C.val: %C = struct_value () [template]
  34. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [template]
  35. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [template]
  36. // CHECK:STDOUT: %.784: type = fn_type_with_self_type %Op.type.f25, %BitComplement.facet [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .BitComplement = %Core.BitComplement
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/...
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core.BitComplement: type = import_ref Core//prelude/operators/bitwise, BitComplement, loaded [template = constants.%BitComplement.type]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .C = %C.decl
  52. // CHECK:STDOUT: .TestOp = %TestOp.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.import = import Core
  55. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  56. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  57. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  58. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  59. // CHECK:STDOUT: %BitComplement.ref: type = name_ref BitComplement, imports.%Core.BitComplement [template = constants.%BitComplement.type]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.1.%Op.decl) [template = constants.%impl_witness]
  62. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [template = constants.%TestOp] {
  63. // CHECK:STDOUT: %a.patt: %C = binding_pattern a
  64. // CHECK:STDOUT: %a.param_patt: %C = value_param_pattern %a.patt, runtime_param0
  65. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  66. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param1
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [template = constants.%C]
  69. // CHECK:STDOUT: %a.param: %C = value_param runtime_param0
  70. // CHECK:STDOUT: %C.ref.loc23_14: type = name_ref C, file.%C.decl [template = constants.%C]
  71. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  72. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param1
  73. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: impl @impl.1: %C.ref as %BitComplement.ref {
  78. // CHECK:STDOUT: %Op.decl: %Op.type.544 = fn_decl @Op.2 [template = constants.%Op.bf2] {
  79. // CHECK:STDOUT: %self.patt: %C = binding_pattern self
  80. // CHECK:STDOUT: %self.param_patt: %C = value_param_pattern %self.patt, runtime_param0
  81. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  82. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param1
  83. // CHECK:STDOUT: } {
  84. // CHECK:STDOUT: %C.ref.loc18_23: type = name_ref C, file.%C.decl [template = constants.%C]
  85. // CHECK:STDOUT: %self.param: %C = value_param runtime_param0
  86. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [template = constants.%C]
  87. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  88. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param1
  89. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !members:
  93. // CHECK:STDOUT: .Op = %Op.decl
  94. // CHECK:STDOUT: witness = file.%impl_witness
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: class @C {
  98. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  99. // CHECK:STDOUT: complete_type_witness = %complete_type
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !members:
  102. // CHECK:STDOUT: .Self = constants.%C
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: fn @Op.2[%self.param_patt: %C]() -> %return.param_patt: %C {
  106. // CHECK:STDOUT: !entry:
  107. // CHECK:STDOUT: %.loc19_13.1: %empty_struct_type = struct_literal ()
  108. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), %return [template = constants.%C.val]
  109. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [template = constants.%C.val]
  110. // CHECK:STDOUT: return %.loc19_14 to %return
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @TestOp(%a.param_patt: %C) -> %return.param_patt: %C {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  116. // CHECK:STDOUT: %impl.elem0: %.784 = impl_witness_access constants.%impl_witness, element0 [template = constants.%Op.bf2]
  117. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  118. // CHECK:STDOUT: %.loc23: ref %C = splice_block %return {}
  119. // CHECK:STDOUT: %Op.call: init %C = call %bound_method(%a.ref) to %.loc23
  120. // CHECK:STDOUT: return %Op.call to %return
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: