constant_condition.carbon 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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/if_expr/constant_condition.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if_expr/constant_condition.carbon
  10. fn A() -> i32 { return 1; }
  11. fn B() -> i32 { return 2; }
  12. fn F() -> i32 {
  13. return if true then A() else B();
  14. }
  15. fn G() -> i32 {
  16. return if false then A() else B();
  17. }
  18. fn Constant() -> i32 {
  19. var v: if true then i32 else i32* = 1;
  20. var w: if false then i32 else i32* = &v;
  21. return *w;
  22. }
  23. fn PartiallyConstant(t: type) -> i32 {
  24. var v: if true then i32 else t = 1;
  25. var w: if false then t else i32* = &v;
  26. return *w;
  27. }
  28. // CHECK:STDOUT: --- constant_condition.carbon
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: constants {
  31. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  32. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  33. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  34. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  35. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  36. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  37. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  38. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  39. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  40. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  41. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  42. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  43. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  44. // CHECK:STDOUT: %To.c80: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  45. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @impl.4f9(%To.c80) [symbolic]
  46. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  47. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  48. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  49. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  50. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  51. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  52. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
  53. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  54. // CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
  55. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  56. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  57. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  58. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
  59. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [concrete]
  60. // CHECK:STDOUT: %bound_method.b92: <bound method> = bound_method %int_2.ecc, %Convert.specific_fn [concrete]
  61. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
  62. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  63. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  64. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  65. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  66. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  67. // CHECK:STDOUT: %false: bool = bool_literal false [concrete]
  68. // CHECK:STDOUT: %Constant.type: type = fn_type @Constant [concrete]
  69. // CHECK:STDOUT: %Constant: %Constant.type = struct_value () [concrete]
  70. // CHECK:STDOUT: %ptr.235: type = ptr_type %i32 [concrete]
  71. // CHECK:STDOUT: %pattern_type.fe8: type = pattern_type %ptr.235 [concrete]
  72. // CHECK:STDOUT: %PartiallyConstant.type: type = fn_type @PartiallyConstant [concrete]
  73. // CHECK:STDOUT: %PartiallyConstant: %PartiallyConstant.type = struct_value () [concrete]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: imports {
  77. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  78. // CHECK:STDOUT: .Int = %Core.Int
  79. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  80. // CHECK:STDOUT: import Core//prelude
  81. // CHECK:STDOUT: import Core//prelude/...
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  84. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  85. // CHECK:STDOUT: %Core.import_ref.a5b: @impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/types/int, loc19_39, loaded [symbolic = @impl.4f9.%Convert (constants.%Convert.f06)]
  86. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @impl.4f9 [concrete]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: file {
  90. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  91. // CHECK:STDOUT: .Core = imports.%Core
  92. // CHECK:STDOUT: .A = %A.decl
  93. // CHECK:STDOUT: .B = %B.decl
  94. // CHECK:STDOUT: .F = %F.decl
  95. // CHECK:STDOUT: .G = %G.decl
  96. // CHECK:STDOUT: .Constant = %Constant.decl
  97. // CHECK:STDOUT: .PartiallyConstant = %PartiallyConstant.decl
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %Core.import = import Core
  100. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [concrete = constants.%A] {
  101. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  102. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  103. // CHECK:STDOUT: } {
  104. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  105. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  106. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  107. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [concrete = constants.%B] {
  110. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  111. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  112. // CHECK:STDOUT: } {
  113. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  114. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  115. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  116. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  119. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  120. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  121. // CHECK:STDOUT: } {
  122. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  123. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  124. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  125. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  128. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  129. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  130. // CHECK:STDOUT: } {
  131. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  132. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  133. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  134. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %Constant.decl: %Constant.type = fn_decl @Constant [concrete = constants.%Constant] {
  137. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  138. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param0 [concrete]
  139. // CHECK:STDOUT: } {
  140. // CHECK:STDOUT: %int_32.loc22: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  141. // CHECK:STDOUT: %i32.loc22: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  142. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  143. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: %PartiallyConstant.decl: %PartiallyConstant.type = fn_decl @PartiallyConstant [concrete = constants.%PartiallyConstant] {
  146. // CHECK:STDOUT: %t.patt: %pattern_type.98f = binding_pattern t [concrete]
  147. // CHECK:STDOUT: %t.param_patt: %pattern_type.98f = value_param_pattern %t.patt, call_param0 [concrete]
  148. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  149. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  150. // CHECK:STDOUT: } {
  151. // CHECK:STDOUT: %int_32.loc28: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  152. // CHECK:STDOUT: %i32.loc28: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  153. // CHECK:STDOUT: %t.param: type = value_param call_param0
  154. // CHECK:STDOUT: %t: type = bind_name t, %t.param
  155. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  156. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: fn @A() -> %i32 {
  161. // CHECK:STDOUT: !entry:
  162. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  163. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  164. // CHECK:STDOUT: %bound_method.loc11_25.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound.ab5]
  165. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  166. // CHECK:STDOUT: %bound_method.loc11_25.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method.9a1]
  167. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc11_25.2(%int_1) [concrete = constants.%int_1.5d2]
  168. // CHECK:STDOUT: %.loc11_25.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.5d2]
  169. // CHECK:STDOUT: %.loc11_25.2: %i32 = converted %int_1, %.loc11_25.1 [concrete = constants.%int_1.5d2]
  170. // CHECK:STDOUT: return %.loc11_25.2
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: fn @B() -> %i32 {
  174. // CHECK:STDOUT: !entry:
  175. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  176. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  177. // CHECK:STDOUT: %bound_method.loc12_25.1: <bound method> = bound_method %int_2, %impl.elem0 [concrete = constants.%Convert.bound.ef9]
  178. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  179. // CHECK:STDOUT: %bound_method.loc12_25.2: <bound method> = bound_method %int_2, %specific_fn [concrete = constants.%bound_method.b92]
  180. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc12_25.2(%int_2) [concrete = constants.%int_2.ef8]
  181. // CHECK:STDOUT: %.loc12_25.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_2.ef8]
  182. // CHECK:STDOUT: %.loc12_25.2: %i32 = converted %int_2, %.loc12_25.1 [concrete = constants.%int_2.ef8]
  183. // CHECK:STDOUT: return %.loc12_25.2
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: fn @F() -> %i32 {
  187. // CHECK:STDOUT: !entry:
  188. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  189. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: !if.expr.then:
  192. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  193. // CHECK:STDOUT: %A.call: init %i32 = call %A.ref()
  194. // CHECK:STDOUT: %.loc15_25.1: %i32 = value_of_initializer %A.call
  195. // CHECK:STDOUT: %.loc15_25.2: %i32 = converted %A.call, %.loc15_25.1
  196. // CHECK:STDOUT: br !if.expr.result(%.loc15_25.2)
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: !if.expr.else:
  199. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [concrete = constants.%B]
  200. // CHECK:STDOUT: %B.call: init %i32 = call %B.ref()
  201. // CHECK:STDOUT: %.loc15_27.1: %i32 = value_of_initializer %B.call
  202. // CHECK:STDOUT: %.loc15_27.2: %i32 = converted %B.call, %.loc15_27.1
  203. // CHECK:STDOUT: br !if.expr.result(%.loc15_27.2)
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: !if.expr.result:
  206. // CHECK:STDOUT: %.loc15_10: %i32 = block_arg !if.expr.result
  207. // CHECK:STDOUT: return %.loc15_10
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: fn @G() -> %i32 {
  211. // CHECK:STDOUT: !entry:
  212. // CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
  213. // CHECK:STDOUT: if %false br !if.expr.then else br !if.expr.else
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: !if.expr.then:
  216. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  217. // CHECK:STDOUT: %A.call: init %i32 = call %A.ref()
  218. // CHECK:STDOUT: %.loc19_26.1: %i32 = value_of_initializer %A.call
  219. // CHECK:STDOUT: %.loc19_26.2: %i32 = converted %A.call, %.loc19_26.1
  220. // CHECK:STDOUT: br !if.expr.result(%.loc19_26.2)
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: !if.expr.else:
  223. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [concrete = constants.%B]
  224. // CHECK:STDOUT: %B.call: init %i32 = call %B.ref()
  225. // CHECK:STDOUT: %.loc19_28.1: %i32 = value_of_initializer %B.call
  226. // CHECK:STDOUT: %.loc19_28.2: %i32 = converted %B.call, %.loc19_28.1
  227. // CHECK:STDOUT: br !if.expr.result(%.loc19_28.2)
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: !if.expr.result:
  230. // CHECK:STDOUT: %.loc19_10: %i32 = block_arg !if.expr.result
  231. // CHECK:STDOUT: return %.loc19_10
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: fn @Constant() -> %i32 {
  235. // CHECK:STDOUT: !entry:
  236. // CHECK:STDOUT: name_binding_decl {
  237. // CHECK:STDOUT: %v.patt: %pattern_type.7ce = binding_pattern v [concrete]
  238. // CHECK:STDOUT: %.loc23_3.1: %pattern_type.7ce = var_pattern %v.patt [concrete]
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT: %v.var: ref %i32 = var v
  241. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  242. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  243. // CHECK:STDOUT: %bound_method.loc23_3.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound.ab5]
  244. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  245. // CHECK:STDOUT: %bound_method.loc23_3.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method.9a1]
  246. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc23_3.2(%int_1) [concrete = constants.%int_1.5d2]
  247. // CHECK:STDOUT: %.loc23_3.2: init %i32 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.5d2]
  248. // CHECK:STDOUT: assign %v.var, %.loc23_3.2
  249. // CHECK:STDOUT: br !.loc23_13
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: !.loc23_13:
  252. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  253. // CHECK:STDOUT: if %true br !if.expr.then.loc23 else br !if.expr.else.loc23
  254. // CHECK:STDOUT:
  255. // CHECK:STDOUT: !if.expr.then.loc23:
  256. // CHECK:STDOUT: %int_32.loc23_23: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  257. // CHECK:STDOUT: %i32.loc23_23: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  258. // CHECK:STDOUT: br !if.expr.result.loc23(%i32.loc23_23)
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: !if.expr.else.loc23:
  261. // CHECK:STDOUT: %int_32.loc23_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  262. // CHECK:STDOUT: %i32.loc23_32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  263. // CHECK:STDOUT: %ptr.loc23: type = ptr_type %i32.loc23_32 [concrete = constants.%ptr.235]
  264. // CHECK:STDOUT: br !if.expr.result.loc23(%ptr.loc23)
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: !if.expr.result.loc23:
  267. // CHECK:STDOUT: %.loc23_10: type = block_arg !if.expr.result.loc23 [concrete = constants.%i32]
  268. // CHECK:STDOUT: br !.loc23_7
  269. // CHECK:STDOUT:
  270. // CHECK:STDOUT: !.loc23_7:
  271. // CHECK:STDOUT: %v: ref %i32 = bind_name v, %v.var
  272. // CHECK:STDOUT: name_binding_decl {
  273. // CHECK:STDOUT: %w.patt: %pattern_type.fe8 = binding_pattern w [concrete]
  274. // CHECK:STDOUT: %.loc24_3: %pattern_type.fe8 = var_pattern %w.patt [concrete]
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT: %w.var: ref %ptr.235 = var w
  277. // CHECK:STDOUT: %v.ref: ref %i32 = name_ref v, %v
  278. // CHECK:STDOUT: %addr: %ptr.235 = addr_of %v.ref
  279. // CHECK:STDOUT: assign %w.var, %addr
  280. // CHECK:STDOUT: br !.loc24_13
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: !.loc24_13:
  283. // CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
  284. // CHECK:STDOUT: if %false br !if.expr.then.loc24 else br !if.expr.else.loc24
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: !if.expr.then.loc24:
  287. // CHECK:STDOUT: %int_32.loc24_24: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  288. // CHECK:STDOUT: %i32.loc24_24: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  289. // CHECK:STDOUT: br !if.expr.result.loc24(%i32.loc24_24)
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: !if.expr.else.loc24:
  292. // CHECK:STDOUT: %int_32.loc24_33: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  293. // CHECK:STDOUT: %i32.loc24_33: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  294. // CHECK:STDOUT: %ptr.loc24: type = ptr_type %i32.loc24_33 [concrete = constants.%ptr.235]
  295. // CHECK:STDOUT: br !if.expr.result.loc24(%ptr.loc24)
  296. // CHECK:STDOUT:
  297. // CHECK:STDOUT: !if.expr.result.loc24:
  298. // CHECK:STDOUT: %.loc24_10: type = block_arg !if.expr.result.loc24 [concrete = constants.%ptr.235]
  299. // CHECK:STDOUT: br !.loc24_7
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: !.loc24_7:
  302. // CHECK:STDOUT: %w: ref %ptr.235 = bind_name w, %w.var
  303. // CHECK:STDOUT: %w.ref: ref %ptr.235 = name_ref w, %w
  304. // CHECK:STDOUT: %.loc25_11: %ptr.235 = bind_value %w.ref
  305. // CHECK:STDOUT: %.loc25_10.1: ref %i32 = deref %.loc25_11
  306. // CHECK:STDOUT: %.loc25_10.2: %i32 = bind_value %.loc25_10.1
  307. // CHECK:STDOUT: return %.loc25_10.2
  308. // CHECK:STDOUT: }
  309. // CHECK:STDOUT:
  310. // CHECK:STDOUT: fn @PartiallyConstant(%t.param: type) -> %i32 {
  311. // CHECK:STDOUT: !entry:
  312. // CHECK:STDOUT: name_binding_decl {
  313. // CHECK:STDOUT: %v.patt: %pattern_type.7ce = binding_pattern v [concrete]
  314. // CHECK:STDOUT: %.loc29_3.1: %pattern_type.7ce = var_pattern %v.patt [concrete]
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT: %v.var: ref %i32 = var v
  317. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  318. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  319. // CHECK:STDOUT: %bound_method.loc29_3.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound.ab5]
  320. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  321. // CHECK:STDOUT: %bound_method.loc29_3.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method.9a1]
  322. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc29_3.2(%int_1) [concrete = constants.%int_1.5d2]
  323. // CHECK:STDOUT: %.loc29_3.2: init %i32 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.5d2]
  324. // CHECK:STDOUT: assign %v.var, %.loc29_3.2
  325. // CHECK:STDOUT: br !.loc29_13
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: !.loc29_13:
  328. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  329. // CHECK:STDOUT: if %true br !if.expr.then.loc29 else br !if.expr.else.loc29
  330. // CHECK:STDOUT:
  331. // CHECK:STDOUT: !if.expr.then.loc29:
  332. // CHECK:STDOUT: %int_32.loc29: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  333. // CHECK:STDOUT: %i32.loc29: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  334. // CHECK:STDOUT: br !if.expr.result.loc29(%i32.loc29)
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: !if.expr.else.loc29:
  337. // CHECK:STDOUT: %t.ref.loc29: type = name_ref t, %t
  338. // CHECK:STDOUT: br !if.expr.result.loc29(%t.ref.loc29)
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: !if.expr.result.loc29:
  341. // CHECK:STDOUT: %.loc29_10: type = block_arg !if.expr.result.loc29 [concrete = constants.%i32]
  342. // CHECK:STDOUT: br !.loc29_7
  343. // CHECK:STDOUT:
  344. // CHECK:STDOUT: !.loc29_7:
  345. // CHECK:STDOUT: %v: ref %i32 = bind_name v, %v.var
  346. // CHECK:STDOUT: name_binding_decl {
  347. // CHECK:STDOUT: %w.patt: %pattern_type.fe8 = binding_pattern w [concrete]
  348. // CHECK:STDOUT: %.loc30_3: %pattern_type.fe8 = var_pattern %w.patt [concrete]
  349. // CHECK:STDOUT: }
  350. // CHECK:STDOUT: %w.var: ref %ptr.235 = var w
  351. // CHECK:STDOUT: %v.ref: ref %i32 = name_ref v, %v
  352. // CHECK:STDOUT: %addr: %ptr.235 = addr_of %v.ref
  353. // CHECK:STDOUT: assign %w.var, %addr
  354. // CHECK:STDOUT: br !.loc30_13
  355. // CHECK:STDOUT:
  356. // CHECK:STDOUT: !.loc30_13:
  357. // CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
  358. // CHECK:STDOUT: if %false br !if.expr.then.loc30 else br !if.expr.else.loc30
  359. // CHECK:STDOUT:
  360. // CHECK:STDOUT: !if.expr.then.loc30:
  361. // CHECK:STDOUT: %t.ref.loc30: type = name_ref t, %t
  362. // CHECK:STDOUT: br !if.expr.result.loc30(%t.ref.loc30)
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: !if.expr.else.loc30:
  365. // CHECK:STDOUT: %int_32.loc30: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  366. // CHECK:STDOUT: %i32.loc30: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  367. // CHECK:STDOUT: %ptr: type = ptr_type %i32.loc30 [concrete = constants.%ptr.235]
  368. // CHECK:STDOUT: br !if.expr.result.loc30(%ptr)
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: !if.expr.result.loc30:
  371. // CHECK:STDOUT: %.loc30_10: type = block_arg !if.expr.result.loc30 [concrete = constants.%ptr.235]
  372. // CHECK:STDOUT: br !.loc30_7
  373. // CHECK:STDOUT:
  374. // CHECK:STDOUT: !.loc30_7:
  375. // CHECK:STDOUT: %w: ref %ptr.235 = bind_name w, %w.var
  376. // CHECK:STDOUT: %w.ref: ref %ptr.235 = name_ref w, %w
  377. // CHECK:STDOUT: %.loc31_11: %ptr.235 = bind_value %w.ref
  378. // CHECK:STDOUT: %.loc31_10.1: ref %i32 = deref %.loc31_11
  379. // CHECK:STDOUT: %.loc31_10.2: %i32 = bind_value %.loc31_10.1
  380. // CHECK:STDOUT: return %.loc31_10.2
  381. // CHECK:STDOUT: }
  382. // CHECK:STDOUT: