mod.carbon 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/mod.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/mod.carbon
  13. // This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  14. package User;
  15. class C {};
  16. impl C as Core.ModWith(C) where .Result = C {
  17. fn Op[self: C](other: C) -> C {
  18. return {};
  19. }
  20. }
  21. impl C as Core.ModAssignWith(C) {
  22. fn Op[addr self: C*](other: C) {}
  23. }
  24. fn TestOp(a: C, b: C) -> C {
  25. //@dump-sem-ir-begin
  26. return a % b;
  27. //@dump-sem-ir-end
  28. }
  29. fn TestAssign(a: C*, b: C) {
  30. //@dump-sem-ir-begin
  31. *a %= b;
  32. //@dump-sem-ir-end
  33. }
  34. // CHECK:STDOUT: --- mod.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  38. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  39. // CHECK:STDOUT: %Other: type = bind_symbolic_name Other, 0 [symbolic]
  40. // CHECK:STDOUT: %ModWith.type.bcb: type = facet_type <@ModWith, @ModWith(%Other)> [symbolic]
  41. // CHECK:STDOUT: %Self.9cc: %ModWith.type.bcb = bind_symbolic_name Self, 1 [symbolic]
  42. // CHECK:STDOUT: %ModWith.type.4d0: type = facet_type <@ModWith, @ModWith(%C)> [concrete]
  43. // CHECK:STDOUT: %.Self.d23: %ModWith.type.4d0 = bind_symbolic_name .Self [symbolic_self]
  44. // CHECK:STDOUT: %Op.type.140: type = fn_type @Op.1, @ModWith(%C) [concrete]
  45. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self.d23 [symbolic_self]
  46. // CHECK:STDOUT: %ModWith.lookup_impl_witness.e42: <witness> = lookup_impl_witness %.Self.d23, @ModWith, @ModWith(%C) [symbolic_self]
  47. // CHECK:STDOUT: %ModWith.facet.d9a: %ModWith.type.4d0 = facet_value %.Self.as_type, (%ModWith.lookup_impl_witness.e42) [symbolic_self]
  48. // CHECK:STDOUT: %ModWith.impl_witness: <witness> = impl_witness file.%ModWith.impl_witness_table [concrete]
  49. // CHECK:STDOUT: %Op.type.0ad: type = fn_type @Op.6 [concrete]
  50. // CHECK:STDOUT: %Op.d57: %Op.type.0ad = struct_value () [concrete]
  51. // CHECK:STDOUT: %ModWith.facet.517: %ModWith.type.4d0 = facet_value %C, (%ModWith.impl_witness) [concrete]
  52. // CHECK:STDOUT: %ModAssignWith.type.8eb: type = facet_type <@ModAssignWith, @ModAssignWith(%C)> [concrete]
  53. // CHECK:STDOUT: %Op.type.dd0: type = fn_type @Op.7, @ModAssignWith(%C) [concrete]
  54. // CHECK:STDOUT: %ModAssignWith.impl_witness: <witness> = impl_witness file.%ModAssignWith.impl_witness_table [concrete]
  55. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
  56. // CHECK:STDOUT: %Op.type.4dd: type = fn_type @Op.8 [concrete]
  57. // CHECK:STDOUT: %Op.4f0: %Op.type.4dd = struct_value () [concrete]
  58. // CHECK:STDOUT: %ModAssignWith.facet: %ModAssignWith.type.8eb = facet_value %C, (%ModAssignWith.impl_witness) [concrete]
  59. // CHECK:STDOUT: %.f08: type = fn_type_with_self_type %Op.type.140, %ModWith.facet.517 [concrete]
  60. // CHECK:STDOUT: %.f3c: type = fn_type_with_self_type %Op.type.dd0, %ModAssignWith.facet [concrete]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: imports {
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @TestOp(%a.param: %C, %b.param: %C) -> %return.param: %C {
  67. // CHECK:STDOUT: !entry:
  68. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  69. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  70. // CHECK:STDOUT: %impl.elem1: %.f08 = impl_witness_access constants.%ModWith.impl_witness, element1 [concrete = constants.%Op.d57]
  71. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem1
  72. // CHECK:STDOUT: <elided>
  73. // CHECK:STDOUT: %Op.call: init %C = call %bound_method(%a.ref, %b.ref) to %.loc29
  74. // CHECK:STDOUT: return %Op.call to %return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @TestAssign(%a.param: %ptr.019, %b.param: %C) {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %a.ref: %ptr.019 = name_ref a, %a
  80. // CHECK:STDOUT: %.loc37: ref %C = deref %a.ref
  81. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  82. // CHECK:STDOUT: %impl.elem0: %.f3c = impl_witness_access constants.%ModAssignWith.impl_witness, element0 [concrete = constants.%Op.4f0]
  83. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc37, %impl.elem0
  84. // CHECK:STDOUT: %addr: %ptr.019 = addr_of %.loc37
  85. // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%addr, %b.ref)
  86. // CHECK:STDOUT: <elided>
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: specific @Result(constants.%Other, constants.%Self.9cc) {}
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: specific @Result(constants.%C, constants.%ModWith.facet.d9a) {}
  92. // CHECK:STDOUT: