less.carbon 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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/builtins/int/less.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/less.carbon
  10. // --- int_less.carbon
  11. fn Less(a: i32, b: i32) -> bool = "int.less";
  12. fn Negate(a: i32) -> i32 = "int.snegate";
  13. class True {}
  14. class False {}
  15. fn F(true_: True, false_: False) {
  16. true_ as (if Less(1, 2) then True else False);
  17. false_ as (if Less(1, 1) then True else False);
  18. false_ as (if Less(1, 0) then True else False);
  19. true_ as (if Less(Negate(1), 0) then True else False);
  20. false_ as (if Less(0, Negate(1)) then True else False);
  21. }
  22. fn RuntimeCall(a: i32, b: i32) -> bool {
  23. return Less(a, b);
  24. }
  25. // CHECK:STDOUT: --- int_less.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  29. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  30. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  31. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  32. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  33. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  34. // CHECK:STDOUT: %Less.type: type = fn_type @Less [template]
  35. // CHECK:STDOUT: %Less: %Less.type = struct_value () [template]
  36. // CHECK:STDOUT: %Negate.type: type = fn_type @Negate [template]
  37. // CHECK:STDOUT: %Negate: %Negate.type = struct_value () [template]
  38. // CHECK:STDOUT: %True: type = class_type @True [template]
  39. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  40. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  41. // CHECK:STDOUT: %False: type = class_type @False [template]
  42. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  44. // CHECK:STDOUT: %.5: Core.IntLiteral = int_value 1 [template]
  45. // CHECK:STDOUT: %.6: Core.IntLiteral = int_value 2 [template]
  46. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  47. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  48. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  49. // CHECK:STDOUT: %.26: <witness> = interface_witness (%Convert.14) [template]
  50. // CHECK:STDOUT: %.27: <bound method> = bound_method %.5, %Convert.14 [template]
  51. // CHECK:STDOUT: %.28: <specific function> = specific_function %.27, @Convert.2(%.1) [template]
  52. // CHECK:STDOUT: %.29: %i32 = int_value 1 [template]
  53. // CHECK:STDOUT: %.30: <bound method> = bound_method %.6, %Convert.14 [template]
  54. // CHECK:STDOUT: %.31: <specific function> = specific_function %.30, @Convert.2(%.1) [template]
  55. // CHECK:STDOUT: %.32: %i32 = int_value 2 [template]
  56. // CHECK:STDOUT: %.33: bool = bool_literal true [template]
  57. // CHECK:STDOUT: %.34: bool = bool_literal false [template]
  58. // CHECK:STDOUT: %.35: Core.IntLiteral = int_value 0 [template]
  59. // CHECK:STDOUT: %.36: <bound method> = bound_method %.35, %Convert.14 [template]
  60. // CHECK:STDOUT: %.37: <specific function> = specific_function %.36, @Convert.2(%.1) [template]
  61. // CHECK:STDOUT: %.38: %i32 = int_value 0 [template]
  62. // CHECK:STDOUT: %.39: %i32 = int_value -1 [template]
  63. // CHECK:STDOUT: %RuntimeCall.type: type = fn_type @RuntimeCall [template]
  64. // CHECK:STDOUT: %RuntimeCall: %RuntimeCall.type = struct_value () [template]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: imports {
  68. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  69. // CHECK:STDOUT: .Int = %import_ref.1
  70. // CHECK:STDOUT: .Bool = %import_ref.2
  71. // CHECK:STDOUT: .ImplicitAs = %import_ref.3
  72. // CHECK:STDOUT: import Core//prelude
  73. // CHECK:STDOUT: import Core//prelude/...
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {
  78. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  79. // CHECK:STDOUT: .Core = imports.%Core
  80. // CHECK:STDOUT: .Less = %Less.decl
  81. // CHECK:STDOUT: .Negate = %Negate.decl
  82. // CHECK:STDOUT: .True = %True.decl
  83. // CHECK:STDOUT: .False = %False.decl
  84. // CHECK:STDOUT: .F = %F.decl
  85. // CHECK:STDOUT: .RuntimeCall = %RuntimeCall.decl
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %Core.import = import Core
  88. // CHECK:STDOUT: %Less.decl: %Less.type = fn_decl @Less [template = constants.%Less] {
  89. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  90. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  91. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  92. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, runtime_param1
  93. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  94. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  95. // CHECK:STDOUT: } {
  96. // CHECK:STDOUT: %.loc2_12.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  97. // CHECK:STDOUT: %int.make_type_signed.loc2_12: init type = call constants.%Int(%.loc2_12.1) [template = constants.%i32]
  98. // CHECK:STDOUT: %.loc2_12.2: type = value_of_initializer %int.make_type_signed.loc2_12 [template = constants.%i32]
  99. // CHECK:STDOUT: %.loc2_12.3: type = converted %int.make_type_signed.loc2_12, %.loc2_12.2 [template = constants.%i32]
  100. // CHECK:STDOUT: %.loc2_20.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  101. // CHECK:STDOUT: %int.make_type_signed.loc2_20: init type = call constants.%Int(%.loc2_20.1) [template = constants.%i32]
  102. // CHECK:STDOUT: %.loc2_20.2: type = value_of_initializer %int.make_type_signed.loc2_20 [template = constants.%i32]
  103. // CHECK:STDOUT: %.loc2_20.3: type = converted %int.make_type_signed.loc2_20, %.loc2_20.2 [template = constants.%i32]
  104. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  105. // CHECK:STDOUT: %.loc2_28.1: type = value_of_initializer %bool.make_type [template = bool]
  106. // CHECK:STDOUT: %.loc2_28.2: type = converted %bool.make_type, %.loc2_28.1 [template = bool]
  107. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  108. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  109. // CHECK:STDOUT: %b.param: %i32 = value_param runtime_param1
  110. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  111. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  112. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %Negate.decl: %Negate.type = fn_decl @Negate [template = constants.%Negate] {
  115. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  116. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  117. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  118. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  119. // CHECK:STDOUT: } {
  120. // CHECK:STDOUT: %.loc3_14.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  121. // CHECK:STDOUT: %int.make_type_signed.loc3_14: init type = call constants.%Int(%.loc3_14.1) [template = constants.%i32]
  122. // CHECK:STDOUT: %.loc3_14.2: type = value_of_initializer %int.make_type_signed.loc3_14 [template = constants.%i32]
  123. // CHECK:STDOUT: %.loc3_14.3: type = converted %int.make_type_signed.loc3_14, %.loc3_14.2 [template = constants.%i32]
  124. // CHECK:STDOUT: %.loc3_22.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  125. // CHECK:STDOUT: %int.make_type_signed.loc3_22: init type = call constants.%Int(%.loc3_22.1) [template = constants.%i32]
  126. // CHECK:STDOUT: %.loc3_22.2: type = value_of_initializer %int.make_type_signed.loc3_22 [template = constants.%i32]
  127. // CHECK:STDOUT: %.loc3_22.3: type = converted %int.make_type_signed.loc3_22, %.loc3_22.2 [template = constants.%i32]
  128. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  129. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  130. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  131. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: %True.decl: type = class_decl @True [template = constants.%True] {} {}
  134. // CHECK:STDOUT: %False.decl: type = class_decl @False [template = constants.%False] {} {}
  135. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  136. // CHECK:STDOUT: %true_.patt: %True = binding_pattern true_
  137. // CHECK:STDOUT: %true_.param_patt: %True = value_param_pattern %true_.patt, runtime_param0
  138. // CHECK:STDOUT: %false_.patt: %False = binding_pattern false_
  139. // CHECK:STDOUT: %false_.param_patt: %False = value_param_pattern %false_.patt, runtime_param1
  140. // CHECK:STDOUT: } {
  141. // CHECK:STDOUT: %True.ref.loc8: type = name_ref True, file.%True.decl [template = constants.%True]
  142. // CHECK:STDOUT: %False.ref.loc8: type = name_ref False, file.%False.decl [template = constants.%False]
  143. // CHECK:STDOUT: %true_.param: %True = value_param runtime_param0
  144. // CHECK:STDOUT: %true_: %True = bind_name true_, %true_.param
  145. // CHECK:STDOUT: %false_.param: %False = value_param runtime_param1
  146. // CHECK:STDOUT: %false_: %False = bind_name false_, %false_.param
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: %RuntimeCall.decl: %RuntimeCall.type = fn_decl @RuntimeCall [template = constants.%RuntimeCall] {
  149. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  150. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  151. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  152. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, runtime_param1
  153. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  154. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param2
  155. // CHECK:STDOUT: } {
  156. // CHECK:STDOUT: %.loc16_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  157. // CHECK:STDOUT: %int.make_type_signed.loc16_19: init type = call constants.%Int(%.loc16_19.1) [template = constants.%i32]
  158. // CHECK:STDOUT: %.loc16_19.2: type = value_of_initializer %int.make_type_signed.loc16_19 [template = constants.%i32]
  159. // CHECK:STDOUT: %.loc16_19.3: type = converted %int.make_type_signed.loc16_19, %.loc16_19.2 [template = constants.%i32]
  160. // CHECK:STDOUT: %.loc16_27.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  161. // CHECK:STDOUT: %int.make_type_signed.loc16_27: init type = call constants.%Int(%.loc16_27.1) [template = constants.%i32]
  162. // CHECK:STDOUT: %.loc16_27.2: type = value_of_initializer %int.make_type_signed.loc16_27 [template = constants.%i32]
  163. // CHECK:STDOUT: %.loc16_27.3: type = converted %int.make_type_signed.loc16_27, %.loc16_27.2 [template = constants.%i32]
  164. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  165. // CHECK:STDOUT: %.loc16_35.1: type = value_of_initializer %bool.make_type [template = bool]
  166. // CHECK:STDOUT: %.loc16_35.2: type = converted %bool.make_type, %.loc16_35.1 [template = bool]
  167. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  168. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  169. // CHECK:STDOUT: %b.param: %i32 = value_param runtime_param1
  170. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  171. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
  172. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: class @True {
  177. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.2 [template = constants.%.3]
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: !members:
  180. // CHECK:STDOUT: .Self = constants.%True
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: class @False {
  184. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.2 [template = constants.%.3]
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: !members:
  187. // CHECK:STDOUT: .Self = constants.%False
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn @Less(%a.param_patt: %i32, %b.param_patt: %i32) -> bool = "int.less";
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: fn @Negate(%a.param_patt: %i32) -> %i32 = "int.snegate";
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: fn @F(%true_.param_patt: %True, %false_.param_patt: %False) {
  195. // CHECK:STDOUT: !entry:
  196. // CHECK:STDOUT: %true_.ref.loc9: %True = name_ref true_, %true_
  197. // CHECK:STDOUT: %Less.ref.loc9: %Less.type = name_ref Less, file.%Less.decl [template = constants.%Less]
  198. // CHECK:STDOUT: %.loc9_21.1: Core.IntLiteral = int_value 1 [template = constants.%.5]
  199. // CHECK:STDOUT: %.loc9_24.1: Core.IntLiteral = int_value 2 [template = constants.%.6]
  200. // CHECK:STDOUT: %.loc9_21.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  201. // CHECK:STDOUT: %.loc9_21.3: <bound method> = bound_method %.loc9_21.1, %.loc9_21.2 [template = constants.%.27]
  202. // CHECK:STDOUT: %.loc9_21.4: <specific function> = specific_function %.loc9_21.3, @Convert.2(constants.%.1) [template = constants.%.28]
  203. // CHECK:STDOUT: %int.convert_checked.loc9_21: init %i32 = call %.loc9_21.4(%.loc9_21.1) [template = constants.%.29]
  204. // CHECK:STDOUT: %.loc9_21.5: %i32 = value_of_initializer %int.convert_checked.loc9_21 [template = constants.%.29]
  205. // CHECK:STDOUT: %.loc9_21.6: %i32 = converted %.loc9_21.1, %.loc9_21.5 [template = constants.%.29]
  206. // CHECK:STDOUT: %.loc9_24.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  207. // CHECK:STDOUT: %.loc9_24.3: <bound method> = bound_method %.loc9_24.1, %.loc9_24.2 [template = constants.%.30]
  208. // CHECK:STDOUT: %.loc9_24.4: <specific function> = specific_function %.loc9_24.3, @Convert.2(constants.%.1) [template = constants.%.31]
  209. // CHECK:STDOUT: %int.convert_checked.loc9_24: init %i32 = call %.loc9_24.4(%.loc9_24.1) [template = constants.%.32]
  210. // CHECK:STDOUT: %.loc9_24.5: %i32 = value_of_initializer %int.convert_checked.loc9_24 [template = constants.%.32]
  211. // CHECK:STDOUT: %.loc9_24.6: %i32 = converted %.loc9_24.1, %.loc9_24.5 [template = constants.%.32]
  212. // CHECK:STDOUT: %int.less.loc9: init bool = call %Less.ref.loc9(%.loc9_21.6, %.loc9_24.6) [template = constants.%.33]
  213. // CHECK:STDOUT: %.loc9_13.1: bool = value_of_initializer %int.less.loc9 [template = constants.%.33]
  214. // CHECK:STDOUT: %.loc9_13.2: bool = converted %int.less.loc9, %.loc9_13.1 [template = constants.%.33]
  215. // CHECK:STDOUT: if %.loc9_13.2 br !if.expr.then.loc9 else br !if.expr.else.loc9
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: !if.expr.then.loc9:
  218. // CHECK:STDOUT: %True.ref.loc9: type = name_ref True, file.%True.decl [template = constants.%True]
  219. // CHECK:STDOUT: br !if.expr.result.loc9(%True.ref.loc9)
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: !if.expr.else.loc9:
  222. // CHECK:STDOUT: %False.ref.loc9: type = name_ref False, file.%False.decl [template = constants.%False]
  223. // CHECK:STDOUT: br !if.expr.result.loc9(%False.ref.loc9)
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: !if.expr.result.loc9:
  226. // CHECK:STDOUT: %.loc9_13.3: type = block_arg !if.expr.result.loc9 [template = constants.%True]
  227. // CHECK:STDOUT: %false_.ref.loc10: %False = name_ref false_, %false_
  228. // CHECK:STDOUT: %Less.ref.loc10: %Less.type = name_ref Less, file.%Less.decl [template = constants.%Less]
  229. // CHECK:STDOUT: %.loc10_22.1: Core.IntLiteral = int_value 1 [template = constants.%.5]
  230. // CHECK:STDOUT: %.loc10_25.1: Core.IntLiteral = int_value 1 [template = constants.%.5]
  231. // CHECK:STDOUT: %.loc10_22.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  232. // CHECK:STDOUT: %.loc10_22.3: <bound method> = bound_method %.loc10_22.1, %.loc10_22.2 [template = constants.%.27]
  233. // CHECK:STDOUT: %.loc10_22.4: <specific function> = specific_function %.loc10_22.3, @Convert.2(constants.%.1) [template = constants.%.28]
  234. // CHECK:STDOUT: %int.convert_checked.loc10_22: init %i32 = call %.loc10_22.4(%.loc10_22.1) [template = constants.%.29]
  235. // CHECK:STDOUT: %.loc10_22.5: %i32 = value_of_initializer %int.convert_checked.loc10_22 [template = constants.%.29]
  236. // CHECK:STDOUT: %.loc10_22.6: %i32 = converted %.loc10_22.1, %.loc10_22.5 [template = constants.%.29]
  237. // CHECK:STDOUT: %.loc10_25.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  238. // CHECK:STDOUT: %.loc10_25.3: <bound method> = bound_method %.loc10_25.1, %.loc10_25.2 [template = constants.%.27]
  239. // CHECK:STDOUT: %.loc10_25.4: <specific function> = specific_function %.loc10_25.3, @Convert.2(constants.%.1) [template = constants.%.28]
  240. // CHECK:STDOUT: %int.convert_checked.loc10_25: init %i32 = call %.loc10_25.4(%.loc10_25.1) [template = constants.%.29]
  241. // CHECK:STDOUT: %.loc10_25.5: %i32 = value_of_initializer %int.convert_checked.loc10_25 [template = constants.%.29]
  242. // CHECK:STDOUT: %.loc10_25.6: %i32 = converted %.loc10_25.1, %.loc10_25.5 [template = constants.%.29]
  243. // CHECK:STDOUT: %int.less.loc10: init bool = call %Less.ref.loc10(%.loc10_22.6, %.loc10_25.6) [template = constants.%.34]
  244. // CHECK:STDOUT: %.loc10_14.1: bool = value_of_initializer %int.less.loc10 [template = constants.%.34]
  245. // CHECK:STDOUT: %.loc10_14.2: bool = converted %int.less.loc10, %.loc10_14.1 [template = constants.%.34]
  246. // CHECK:STDOUT: if %.loc10_14.2 br !if.expr.then.loc10 else br !if.expr.else.loc10
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: !if.expr.then.loc10:
  249. // CHECK:STDOUT: %True.ref.loc10: type = name_ref True, file.%True.decl [template = constants.%True]
  250. // CHECK:STDOUT: br !if.expr.result.loc10(%True.ref.loc10)
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: !if.expr.else.loc10:
  253. // CHECK:STDOUT: %False.ref.loc10: type = name_ref False, file.%False.decl [template = constants.%False]
  254. // CHECK:STDOUT: br !if.expr.result.loc10(%False.ref.loc10)
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: !if.expr.result.loc10:
  257. // CHECK:STDOUT: %.loc10_14.3: type = block_arg !if.expr.result.loc10 [template = constants.%False]
  258. // CHECK:STDOUT: %false_.ref.loc11: %False = name_ref false_, %false_
  259. // CHECK:STDOUT: %Less.ref.loc11: %Less.type = name_ref Less, file.%Less.decl [template = constants.%Less]
  260. // CHECK:STDOUT: %.loc11_22.1: Core.IntLiteral = int_value 1 [template = constants.%.5]
  261. // CHECK:STDOUT: %.loc11_25.1: Core.IntLiteral = int_value 0 [template = constants.%.35]
  262. // CHECK:STDOUT: %.loc11_22.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  263. // CHECK:STDOUT: %.loc11_22.3: <bound method> = bound_method %.loc11_22.1, %.loc11_22.2 [template = constants.%.27]
  264. // CHECK:STDOUT: %.loc11_22.4: <specific function> = specific_function %.loc11_22.3, @Convert.2(constants.%.1) [template = constants.%.28]
  265. // CHECK:STDOUT: %int.convert_checked.loc11_22: init %i32 = call %.loc11_22.4(%.loc11_22.1) [template = constants.%.29]
  266. // CHECK:STDOUT: %.loc11_22.5: %i32 = value_of_initializer %int.convert_checked.loc11_22 [template = constants.%.29]
  267. // CHECK:STDOUT: %.loc11_22.6: %i32 = converted %.loc11_22.1, %.loc11_22.5 [template = constants.%.29]
  268. // CHECK:STDOUT: %.loc11_25.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  269. // CHECK:STDOUT: %.loc11_25.3: <bound method> = bound_method %.loc11_25.1, %.loc11_25.2 [template = constants.%.36]
  270. // CHECK:STDOUT: %.loc11_25.4: <specific function> = specific_function %.loc11_25.3, @Convert.2(constants.%.1) [template = constants.%.37]
  271. // CHECK:STDOUT: %int.convert_checked.loc11_25: init %i32 = call %.loc11_25.4(%.loc11_25.1) [template = constants.%.38]
  272. // CHECK:STDOUT: %.loc11_25.5: %i32 = value_of_initializer %int.convert_checked.loc11_25 [template = constants.%.38]
  273. // CHECK:STDOUT: %.loc11_25.6: %i32 = converted %.loc11_25.1, %.loc11_25.5 [template = constants.%.38]
  274. // CHECK:STDOUT: %int.less.loc11: init bool = call %Less.ref.loc11(%.loc11_22.6, %.loc11_25.6) [template = constants.%.34]
  275. // CHECK:STDOUT: %.loc11_14.1: bool = value_of_initializer %int.less.loc11 [template = constants.%.34]
  276. // CHECK:STDOUT: %.loc11_14.2: bool = converted %int.less.loc11, %.loc11_14.1 [template = constants.%.34]
  277. // CHECK:STDOUT: if %.loc11_14.2 br !if.expr.then.loc11 else br !if.expr.else.loc11
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: !if.expr.then.loc11:
  280. // CHECK:STDOUT: %True.ref.loc11: type = name_ref True, file.%True.decl [template = constants.%True]
  281. // CHECK:STDOUT: br !if.expr.result.loc11(%True.ref.loc11)
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: !if.expr.else.loc11:
  284. // CHECK:STDOUT: %False.ref.loc11: type = name_ref False, file.%False.decl [template = constants.%False]
  285. // CHECK:STDOUT: br !if.expr.result.loc11(%False.ref.loc11)
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: !if.expr.result.loc11:
  288. // CHECK:STDOUT: %.loc11_14.3: type = block_arg !if.expr.result.loc11 [template = constants.%False]
  289. // CHECK:STDOUT: %true_.ref.loc12: %True = name_ref true_, %true_
  290. // CHECK:STDOUT: %Less.ref.loc12: %Less.type = name_ref Less, file.%Less.decl [template = constants.%Less]
  291. // CHECK:STDOUT: %Negate.ref.loc12: %Negate.type = name_ref Negate, file.%Negate.decl [template = constants.%Negate]
  292. // CHECK:STDOUT: %.loc12_28.1: Core.IntLiteral = int_value 1 [template = constants.%.5]
  293. // CHECK:STDOUT: %.loc12_28.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  294. // CHECK:STDOUT: %.loc12_28.3: <bound method> = bound_method %.loc12_28.1, %.loc12_28.2 [template = constants.%.27]
  295. // CHECK:STDOUT: %.loc12_28.4: <specific function> = specific_function %.loc12_28.3, @Convert.2(constants.%.1) [template = constants.%.28]
  296. // CHECK:STDOUT: %int.convert_checked.loc12_28: init %i32 = call %.loc12_28.4(%.loc12_28.1) [template = constants.%.29]
  297. // CHECK:STDOUT: %.loc12_28.5: %i32 = value_of_initializer %int.convert_checked.loc12_28 [template = constants.%.29]
  298. // CHECK:STDOUT: %.loc12_28.6: %i32 = converted %.loc12_28.1, %.loc12_28.5 [template = constants.%.29]
  299. // CHECK:STDOUT: %int.snegate.loc12: init %i32 = call %Negate.ref.loc12(%.loc12_28.6) [template = constants.%.39]
  300. // CHECK:STDOUT: %.loc12_32.1: Core.IntLiteral = int_value 0 [template = constants.%.35]
  301. // CHECK:STDOUT: %.loc12_27.1: %i32 = value_of_initializer %int.snegate.loc12 [template = constants.%.39]
  302. // CHECK:STDOUT: %.loc12_27.2: %i32 = converted %int.snegate.loc12, %.loc12_27.1 [template = constants.%.39]
  303. // CHECK:STDOUT: %.loc12_32.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  304. // CHECK:STDOUT: %.loc12_32.3: <bound method> = bound_method %.loc12_32.1, %.loc12_32.2 [template = constants.%.36]
  305. // CHECK:STDOUT: %.loc12_32.4: <specific function> = specific_function %.loc12_32.3, @Convert.2(constants.%.1) [template = constants.%.37]
  306. // CHECK:STDOUT: %int.convert_checked.loc12_32: init %i32 = call %.loc12_32.4(%.loc12_32.1) [template = constants.%.38]
  307. // CHECK:STDOUT: %.loc12_32.5: %i32 = value_of_initializer %int.convert_checked.loc12_32 [template = constants.%.38]
  308. // CHECK:STDOUT: %.loc12_32.6: %i32 = converted %.loc12_32.1, %.loc12_32.5 [template = constants.%.38]
  309. // CHECK:STDOUT: %int.less.loc12: init bool = call %Less.ref.loc12(%.loc12_27.2, %.loc12_32.6) [template = constants.%.33]
  310. // CHECK:STDOUT: %.loc12_13.1: bool = value_of_initializer %int.less.loc12 [template = constants.%.33]
  311. // CHECK:STDOUT: %.loc12_13.2: bool = converted %int.less.loc12, %.loc12_13.1 [template = constants.%.33]
  312. // CHECK:STDOUT: if %.loc12_13.2 br !if.expr.then.loc12 else br !if.expr.else.loc12
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: !if.expr.then.loc12:
  315. // CHECK:STDOUT: %True.ref.loc12: type = name_ref True, file.%True.decl [template = constants.%True]
  316. // CHECK:STDOUT: br !if.expr.result.loc12(%True.ref.loc12)
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: !if.expr.else.loc12:
  319. // CHECK:STDOUT: %False.ref.loc12: type = name_ref False, file.%False.decl [template = constants.%False]
  320. // CHECK:STDOUT: br !if.expr.result.loc12(%False.ref.loc12)
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: !if.expr.result.loc12:
  323. // CHECK:STDOUT: %.loc12_13.3: type = block_arg !if.expr.result.loc12 [template = constants.%True]
  324. // CHECK:STDOUT: %false_.ref.loc13: %False = name_ref false_, %false_
  325. // CHECK:STDOUT: %Less.ref.loc13: %Less.type = name_ref Less, file.%Less.decl [template = constants.%Less]
  326. // CHECK:STDOUT: %.loc13_22.1: Core.IntLiteral = int_value 0 [template = constants.%.35]
  327. // CHECK:STDOUT: %Negate.ref.loc13: %Negate.type = name_ref Negate, file.%Negate.decl [template = constants.%Negate]
  328. // CHECK:STDOUT: %.loc13_32.1: Core.IntLiteral = int_value 1 [template = constants.%.5]
  329. // CHECK:STDOUT: %.loc13_32.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  330. // CHECK:STDOUT: %.loc13_32.3: <bound method> = bound_method %.loc13_32.1, %.loc13_32.2 [template = constants.%.27]
  331. // CHECK:STDOUT: %.loc13_32.4: <specific function> = specific_function %.loc13_32.3, @Convert.2(constants.%.1) [template = constants.%.28]
  332. // CHECK:STDOUT: %int.convert_checked.loc13_32: init %i32 = call %.loc13_32.4(%.loc13_32.1) [template = constants.%.29]
  333. // CHECK:STDOUT: %.loc13_32.5: %i32 = value_of_initializer %int.convert_checked.loc13_32 [template = constants.%.29]
  334. // CHECK:STDOUT: %.loc13_32.6: %i32 = converted %.loc13_32.1, %.loc13_32.5 [template = constants.%.29]
  335. // CHECK:STDOUT: %int.snegate.loc13: init %i32 = call %Negate.ref.loc13(%.loc13_32.6) [template = constants.%.39]
  336. // CHECK:STDOUT: %.loc13_22.2: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.14]
  337. // CHECK:STDOUT: %.loc13_22.3: <bound method> = bound_method %.loc13_22.1, %.loc13_22.2 [template = constants.%.36]
  338. // CHECK:STDOUT: %.loc13_22.4: <specific function> = specific_function %.loc13_22.3, @Convert.2(constants.%.1) [template = constants.%.37]
  339. // CHECK:STDOUT: %int.convert_checked.loc13_22: init %i32 = call %.loc13_22.4(%.loc13_22.1) [template = constants.%.38]
  340. // CHECK:STDOUT: %.loc13_22.5: %i32 = value_of_initializer %int.convert_checked.loc13_22 [template = constants.%.38]
  341. // CHECK:STDOUT: %.loc13_22.6: %i32 = converted %.loc13_22.1, %.loc13_22.5 [template = constants.%.38]
  342. // CHECK:STDOUT: %.loc13_31.1: %i32 = value_of_initializer %int.snegate.loc13 [template = constants.%.39]
  343. // CHECK:STDOUT: %.loc13_31.2: %i32 = converted %int.snegate.loc13, %.loc13_31.1 [template = constants.%.39]
  344. // CHECK:STDOUT: %int.less.loc13: init bool = call %Less.ref.loc13(%.loc13_22.6, %.loc13_31.2) [template = constants.%.34]
  345. // CHECK:STDOUT: %.loc13_14.1: bool = value_of_initializer %int.less.loc13 [template = constants.%.34]
  346. // CHECK:STDOUT: %.loc13_14.2: bool = converted %int.less.loc13, %.loc13_14.1 [template = constants.%.34]
  347. // CHECK:STDOUT: if %.loc13_14.2 br !if.expr.then.loc13 else br !if.expr.else.loc13
  348. // CHECK:STDOUT:
  349. // CHECK:STDOUT: !if.expr.then.loc13:
  350. // CHECK:STDOUT: %True.ref.loc13: type = name_ref True, file.%True.decl [template = constants.%True]
  351. // CHECK:STDOUT: br !if.expr.result.loc13(%True.ref.loc13)
  352. // CHECK:STDOUT:
  353. // CHECK:STDOUT: !if.expr.else.loc13:
  354. // CHECK:STDOUT: %False.ref.loc13: type = name_ref False, file.%False.decl [template = constants.%False]
  355. // CHECK:STDOUT: br !if.expr.result.loc13(%False.ref.loc13)
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: !if.expr.result.loc13:
  358. // CHECK:STDOUT: %.loc13_14.3: type = block_arg !if.expr.result.loc13 [template = constants.%False]
  359. // CHECK:STDOUT: return
  360. // CHECK:STDOUT: }
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: fn @RuntimeCall(%a.param_patt: %i32, %b.param_patt: %i32) -> bool {
  363. // CHECK:STDOUT: !entry:
  364. // CHECK:STDOUT: %Less.ref: %Less.type = name_ref Less, file.%Less.decl [template = constants.%Less]
  365. // CHECK:STDOUT: %a.ref: %i32 = name_ref a, %a
  366. // CHECK:STDOUT: %b.ref: %i32 = name_ref b, %b
  367. // CHECK:STDOUT: %int.less: init bool = call %Less.ref(%a.ref, %b.ref)
  368. // CHECK:STDOUT: %.loc17_20.1: bool = value_of_initializer %int.less
  369. // CHECK:STDOUT: %.loc17_20.2: bool = converted %int.less, %.loc17_20.1
  370. // CHECK:STDOUT: return %.loc17_20.2
  371. // CHECK:STDOUT: }
  372. // CHECK:STDOUT: