eq.carbon 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/bool/eq.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/bool/eq.carbon
  12. // --- builtin_call.carbon
  13. library "[[@TEST_NAME]]";
  14. fn Eq(a: bool, b: bool) -> bool = "bool.eq";
  15. class C(B:! bool) {}
  16. fn True() -> C(true);
  17. fn False() -> C(false);
  18. //@dump-sem-ir-begin
  19. var a: C(Eq(true, true)) = True();
  20. //@dump-sem-ir-end
  21. var b: C(Eq(true, false)) = False();
  22. var c: C(Eq(false, true)) = False();
  23. var d: C(Eq(false, false)) = True();
  24. // --- prelude.carbon
  25. library "[[@TEST_NAME]]";
  26. class C(B:! bool) {}
  27. fn True() -> C(true);
  28. fn False() -> C(false);
  29. //@dump-sem-ir-begin
  30. var a: C(true == true) = True();
  31. //@dump-sem-ir-end
  32. var b: C(true == false) = False();
  33. var c: C(false == true) = False();
  34. var d: C(false == false) = True();
  35. // CHECK:STDOUT: --- builtin_call.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %Eq.type: type = fn_type @Eq [concrete]
  39. // CHECK:STDOUT: %Eq: %Eq.type = struct_value () [concrete]
  40. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  41. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  42. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  43. // CHECK:STDOUT: %C.a23: type = class_type @C, @C(%true) [concrete]
  44. // CHECK:STDOUT: %pattern_type.a06: type = pattern_type %C.a23 [concrete]
  45. // CHECK:STDOUT: %True.type: type = fn_type @True [concrete]
  46. // CHECK:STDOUT: %True: %True.type = struct_value () [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: name_binding_decl {
  54. // CHECK:STDOUT: %a.patt: %pattern_type.a06 = ref_binding_pattern a [concrete]
  55. // CHECK:STDOUT: %a.var_patt: %pattern_type.a06 = var_pattern %a.patt [concrete]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %a.var: ref %C.a23 = var %a.var_patt [concrete]
  58. // CHECK:STDOUT: %.loc12_24.1: type = splice_block %C.loc12 [concrete = constants.%C.a23] {
  59. // CHECK:STDOUT: %C.ref.loc12: %C.type = name_ref C, %C.decl [concrete = constants.%C.generic]
  60. // CHECK:STDOUT: %Eq.ref.loc12: %Eq.type = name_ref Eq, %Eq.decl [concrete = constants.%Eq]
  61. // CHECK:STDOUT: %true.loc12_13: bool = bool_literal true [concrete = constants.%true]
  62. // CHECK:STDOUT: %true.loc12_19: bool = bool_literal true [concrete = constants.%true]
  63. // CHECK:STDOUT: %Eq.call.loc12: init bool = call %Eq.ref.loc12(%true.loc12_13, %true.loc12_19) [concrete = constants.%true]
  64. // CHECK:STDOUT: %.loc12_24.2: bool = value_of_initializer %Eq.call.loc12 [concrete = constants.%true]
  65. // CHECK:STDOUT: %.loc12_24.3: bool = converted %Eq.call.loc12, %.loc12_24.2 [concrete = constants.%true]
  66. // CHECK:STDOUT: %C.loc12: type = class_type @C, @C(constants.%true) [concrete = constants.%C.a23]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %a: ref %C.a23 = ref_binding a, %a.var [concrete = %a.var]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @__global_init() {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %True.ref.loc12: %True.type = name_ref True, file.%True.decl [concrete = constants.%True]
  74. // CHECK:STDOUT: %.loc12: ref %C.a23 = splice_block file.%a.var [concrete = file.%a.var] {}
  75. // CHECK:STDOUT: %True.call.loc12: init %C.a23 = call %True.ref.loc12() to %.loc12
  76. // CHECK:STDOUT: assign file.%a.var, %True.call.loc12
  77. // CHECK:STDOUT: <elided>
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: --- prelude.carbon
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: constants {
  83. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  84. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  85. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  86. // CHECK:STDOUT: %C.a23: type = class_type @C, @C(%true) [concrete]
  87. // CHECK:STDOUT: %pattern_type.a06: type = pattern_type %C.a23 [concrete]
  88. // CHECK:STDOUT: %True.type: type = fn_type @True [concrete]
  89. // CHECK:STDOUT: %True: %True.type = struct_value () [concrete]
  90. // CHECK:STDOUT: %EqWith.type.863: type = facet_type <@EqWith, @EqWith(bool)> [concrete]
  91. // CHECK:STDOUT: %EqWith.Equal.type.a58: type = fn_type @EqWith.Equal, @EqWith(bool) [concrete]
  92. // CHECK:STDOUT: %EqWith.impl_witness: <witness> = impl_witness imports.%EqWith.impl_witness_table [concrete]
  93. // CHECK:STDOUT: %EqWith.facet: %EqWith.type.863 = facet_value bool, (%EqWith.impl_witness) [concrete]
  94. // CHECK:STDOUT: %.239: type = fn_type_with_self_type %EqWith.Equal.type.a58, %EqWith.facet [concrete]
  95. // CHECK:STDOUT: %bool.as.EqWith.impl.Equal.type: type = fn_type @bool.as.EqWith.impl.Equal [concrete]
  96. // CHECK:STDOUT: %bool.as.EqWith.impl.Equal: %bool.as.EqWith.impl.Equal.type = struct_value () [concrete]
  97. // CHECK:STDOUT: %bool.as.EqWith.impl.Equal.bound.40b: <bound method> = bound_method %true, %bool.as.EqWith.impl.Equal [concrete]
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: imports {
  101. // CHECK:STDOUT: %Core.import_ref.f73: %bool.as.EqWith.impl.Equal.type = import_ref Core//prelude/operators/comparison, loc{{\d+_\d+}}, loaded [concrete = constants.%bool.as.EqWith.impl.Equal]
  102. // CHECK:STDOUT: %Core.import_ref.115 = import_ref Core//prelude/operators/comparison, loc{{\d+_\d+}}, unloaded
  103. // CHECK:STDOUT: %EqWith.impl_witness_table = impl_witness_table (%Core.import_ref.f73, %Core.import_ref.115), @bool.as.EqWith.impl [concrete]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: file {
  107. // CHECK:STDOUT: name_binding_decl {
  108. // CHECK:STDOUT: %a.patt: %pattern_type.a06 = ref_binding_pattern a [concrete]
  109. // CHECK:STDOUT: %a.var_patt: %pattern_type.a06 = var_pattern %a.patt [concrete]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %a.var: ref %C.a23 = var %a.var_patt [concrete]
  112. // CHECK:STDOUT: %.loc10_22.1: type = splice_block %C.loc10 [concrete = constants.%C.a23] {
  113. // CHECK:STDOUT: %C.ref.loc10: %C.type = name_ref C, %C.decl [concrete = constants.%C.generic]
  114. // CHECK:STDOUT: %true.loc10_10: bool = bool_literal true [concrete = constants.%true]
  115. // CHECK:STDOUT: %true.loc10_18: bool = bool_literal true [concrete = constants.%true]
  116. // CHECK:STDOUT: %impl.elem0.loc10: %.239 = impl_witness_access constants.%EqWith.impl_witness, element0 [concrete = constants.%bool.as.EqWith.impl.Equal]
  117. // CHECK:STDOUT: %bound_method.loc10: <bound method> = bound_method %true.loc10_10, %impl.elem0.loc10 [concrete = constants.%bool.as.EqWith.impl.Equal.bound.40b]
  118. // CHECK:STDOUT: %bool.as.EqWith.impl.Equal.call.loc10: init bool = call %bound_method.loc10(%true.loc10_10, %true.loc10_18) [concrete = constants.%true]
  119. // CHECK:STDOUT: %.loc10_22.2: bool = value_of_initializer %bool.as.EqWith.impl.Equal.call.loc10 [concrete = constants.%true]
  120. // CHECK:STDOUT: %.loc10_22.3: bool = converted %bool.as.EqWith.impl.Equal.call.loc10, %.loc10_22.2 [concrete = constants.%true]
  121. // CHECK:STDOUT: %C.loc10: type = class_type @C, @C(constants.%true) [concrete = constants.%C.a23]
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %a: ref %C.a23 = ref_binding a, %a.var [concrete = %a.var]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: fn @__global_init() {
  127. // CHECK:STDOUT: !entry:
  128. // CHECK:STDOUT: %True.ref.loc10: %True.type = name_ref True, file.%True.decl [concrete = constants.%True]
  129. // CHECK:STDOUT: %.loc10: ref %C.a23 = splice_block file.%a.var [concrete = file.%a.var] {}
  130. // CHECK:STDOUT: %True.call.loc10: init %C.a23 = call %True.ref.loc10() to %.loc10
  131. // CHECK:STDOUT: assign file.%a.var, %True.call.loc10
  132. // CHECK:STDOUT: <elided>
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: