more_param_ir.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/call/more_param_ir.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/more_param_ir.carbon
  14. fn Foo(a: i32, b: i32) {}
  15. fn Main() {
  16. var x: (i32,) = (1,);
  17. // Generates multiple IR instructions for the first parameter.
  18. Foo(x.0, 6);
  19. }
  20. // CHECK:STDOUT: --- more_param_ir.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  24. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  25. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  26. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  27. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  28. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  29. // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [concrete]
  30. // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [concrete]
  31. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  32. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  33. // CHECK:STDOUT: %tuple.type.85c: type = tuple_type (type) [concrete]
  34. // CHECK:STDOUT: %tuple.type.a1c: type = tuple_type (%i32) [concrete]
  35. // CHECK:STDOUT: %pattern_type.b74: type = pattern_type %tuple.type.a1c [concrete]
  36. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  37. // CHECK:STDOUT: %tuple.type.985: type = tuple_type (Core.IntLiteral) [concrete]
  38. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  39. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  40. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  41. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  42. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  43. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @impl.4f9(%To) [symbolic]
  44. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  45. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  46. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  47. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  49. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  50. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
  51. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  52. // CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
  53. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  54. // CHECK:STDOUT: %tuple: %tuple.type.a1c = tuple_value (%int_1.5d2) [concrete]
  55. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  56. // CHECK:STDOUT: %int_6.462: Core.IntLiteral = int_value 6 [concrete]
  57. // CHECK:STDOUT: %Convert.bound.ce9: <bound method> = bound_method %int_6.462, %Convert.956 [concrete]
  58. // CHECK:STDOUT: %bound_method.efa: <bound method> = bound_method %int_6.462, %Convert.specific_fn [concrete]
  59. // CHECK:STDOUT: %int_6.e56: %i32 = int_value 6 [concrete]
  60. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  61. // CHECK:STDOUT: %Op.type.bae: type = fn_type @Op.2 [concrete]
  62. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  63. // CHECK:STDOUT: %Op.type.bc9: type = fn_type @Op.3, @impl.49c(%T) [symbolic]
  64. // CHECK:STDOUT: %Op.46f: %Op.type.bc9 = struct_value () [symbolic]
  65. // CHECK:STDOUT: %Destroy.impl_witness.088: <witness> = impl_witness imports.%Destroy.impl_witness_table, @impl.49c(%tuple.type.a1c) [concrete]
  66. // CHECK:STDOUT: %Op.type.438: type = fn_type @Op.3, @impl.49c(%tuple.type.a1c) [concrete]
  67. // CHECK:STDOUT: %Op.c8e: %Op.type.438 = struct_value () [concrete]
  68. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %tuple.type.a1c, (%Destroy.impl_witness.088) [concrete]
  69. // CHECK:STDOUT: %.6a9: type = fn_type_with_self_type %Op.type.bae, %Destroy.facet [concrete]
  70. // CHECK:STDOUT: %Op.specific_fn: <specific function> = specific_function %Op.c8e, @Op.3(%tuple.type.a1c) [concrete]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: imports {
  74. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  75. // CHECK:STDOUT: .Int = %Core.Int
  76. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  77. // CHECK:STDOUT: .Destroy = %Core.Destroy
  78. // CHECK:STDOUT: import Core//prelude
  79. // CHECK:STDOUT: import Core//prelude/...
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  82. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  83. // CHECK:STDOUT: %Core.import_ref.a5b: @impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/parts/int, loc16_39, loaded [symbolic = @impl.4f9.%Convert (constants.%Convert.f06)]
  84. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @impl.4f9 [concrete]
  85. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  86. // CHECK:STDOUT: %Core.import_ref.0b9: @impl.49c.%Op.type (%Op.type.bc9) = import_ref Core//prelude/parts/destroy, loc8_23, loaded [symbolic = @impl.49c.%Op (constants.%Op.46f)]
  87. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (%Core.import_ref.0b9), @impl.49c [concrete]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: file {
  91. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  92. // CHECK:STDOUT: .Core = imports.%Core
  93. // CHECK:STDOUT: .Foo = %Foo.decl
  94. // CHECK:STDOUT: .Main = %Main.decl
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %Core.import = import Core
  97. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [concrete = constants.%Foo] {
  98. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  99. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  100. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = binding_pattern b [concrete]
  101. // CHECK:STDOUT: %b.param_patt: %pattern_type.7ce = value_param_pattern %b.patt, call_param1 [concrete]
  102. // CHECK:STDOUT: } {
  103. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  104. // CHECK:STDOUT: %.loc15_11: type = splice_block %i32.loc15_11 [concrete = constants.%i32] {
  105. // CHECK:STDOUT: %int_32.loc15_11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  106. // CHECK:STDOUT: %i32.loc15_11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  109. // CHECK:STDOUT: %b.param: %i32 = value_param call_param1
  110. // CHECK:STDOUT: %.loc15_19: type = splice_block %i32.loc15_19 [concrete = constants.%i32] {
  111. // CHECK:STDOUT: %int_32.loc15_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  112. // CHECK:STDOUT: %i32.loc15_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @Foo(%a.param: %i32, %b.param: %i32) {
  120. // CHECK:STDOUT: !entry:
  121. // CHECK:STDOUT: return
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @Main() {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: name_binding_decl {
  127. // CHECK:STDOUT: %x.patt: %pattern_type.b74 = binding_pattern x [concrete]
  128. // CHECK:STDOUT: %x.var_patt: %pattern_type.b74 = var_pattern %x.patt [concrete]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %x.var: ref %tuple.type.a1c = var %x.var_patt
  131. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  132. // CHECK:STDOUT: %.loc18_22.1: %tuple.type.985 = tuple_literal (%int_1)
  133. // CHECK:STDOUT: %impl.elem0.loc18_22: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  134. // CHECK:STDOUT: %bound_method.loc18_22.1: <bound method> = bound_method %int_1, %impl.elem0.loc18_22 [concrete = constants.%Convert.bound.ab5]
  135. // CHECK:STDOUT: %specific_fn.loc18_22: <specific function> = specific_function %impl.elem0.loc18_22, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  136. // CHECK:STDOUT: %bound_method.loc18_22.2: <bound method> = bound_method %int_1, %specific_fn.loc18_22 [concrete = constants.%bound_method.9a1]
  137. // CHECK:STDOUT: %int.convert_checked.loc18: init %i32 = call %bound_method.loc18_22.2(%int_1) [concrete = constants.%int_1.5d2]
  138. // CHECK:STDOUT: %.loc18_22.2: init %i32 = converted %int_1, %int.convert_checked.loc18 [concrete = constants.%int_1.5d2]
  139. // CHECK:STDOUT: %.loc18_22.3: init %tuple.type.a1c = tuple_init (%.loc18_22.2) to %x.var [concrete = constants.%tuple]
  140. // CHECK:STDOUT: %.loc18_3.1: init %tuple.type.a1c = converted %.loc18_22.1, %.loc18_22.3 [concrete = constants.%tuple]
  141. // CHECK:STDOUT: assign %x.var, %.loc18_3.1
  142. // CHECK:STDOUT: %.loc18_15.1: type = splice_block %.loc18_15.3 [concrete = constants.%tuple.type.a1c] {
  143. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  144. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  145. // CHECK:STDOUT: %.loc18_15.2: %tuple.type.85c = tuple_literal (%i32)
  146. // CHECK:STDOUT: %.loc18_15.3: type = converted %.loc18_15.2, constants.%tuple.type.a1c [concrete = constants.%tuple.type.a1c]
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: %x: ref %tuple.type.a1c = bind_name x, %x.var
  149. // CHECK:STDOUT: %Foo.ref: %Foo.type = name_ref Foo, file.%Foo.decl [concrete = constants.%Foo]
  150. // CHECK:STDOUT: %x.ref: ref %tuple.type.a1c = name_ref x, %x
  151. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  152. // CHECK:STDOUT: %tuple.elem0.loc20: ref %i32 = tuple_access %x.ref, element0
  153. // CHECK:STDOUT: %int_6: Core.IntLiteral = int_value 6 [concrete = constants.%int_6.462]
  154. // CHECK:STDOUT: %.loc20_8: %i32 = bind_value %tuple.elem0.loc20
  155. // CHECK:STDOUT: %impl.elem0.loc20: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  156. // CHECK:STDOUT: %bound_method.loc20_12.1: <bound method> = bound_method %int_6, %impl.elem0.loc20 [concrete = constants.%Convert.bound.ce9]
  157. // CHECK:STDOUT: %specific_fn.loc20: <specific function> = specific_function %impl.elem0.loc20, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  158. // CHECK:STDOUT: %bound_method.loc20_12.2: <bound method> = bound_method %int_6, %specific_fn.loc20 [concrete = constants.%bound_method.efa]
  159. // CHECK:STDOUT: %int.convert_checked.loc20: init %i32 = call %bound_method.loc20_12.2(%int_6) [concrete = constants.%int_6.e56]
  160. // CHECK:STDOUT: %.loc20_12.1: %i32 = value_of_initializer %int.convert_checked.loc20 [concrete = constants.%int_6.e56]
  161. // CHECK:STDOUT: %.loc20_12.2: %i32 = converted %int_6, %.loc20_12.1 [concrete = constants.%int_6.e56]
  162. // CHECK:STDOUT: %Foo.call: init %empty_tuple.type = call %Foo.ref(%.loc20_8, %.loc20_12.2)
  163. // CHECK:STDOUT: %impl.elem0.loc18_3: %.6a9 = impl_witness_access constants.%Destroy.impl_witness.088, element0 [concrete = constants.%Op.c8e]
  164. // CHECK:STDOUT: %bound_method.loc18_3.1: <bound method> = bound_method %x.var, %impl.elem0.loc18_3
  165. // CHECK:STDOUT: %specific_fn.loc18_3: <specific function> = specific_function %impl.elem0.loc18_3, @Op.3(constants.%tuple.type.a1c) [concrete = constants.%Op.specific_fn]
  166. // CHECK:STDOUT: %bound_method.loc18_3.2: <bound method> = bound_method %x.var, %specific_fn.loc18_3
  167. // CHECK:STDOUT: %tuple.elem0.loc18: ref %i32 = tuple_access %x.var, element0
  168. // CHECK:STDOUT: %.loc18_3.2: %i32 = bind_value %tuple.elem0.loc18
  169. // CHECK:STDOUT: %tuple: %tuple.type.a1c = tuple_value (%.loc18_3.2)
  170. // CHECK:STDOUT: %.loc18_3.3: %tuple.type.a1c = converted %x.var, %tuple
  171. // CHECK:STDOUT: %no_op: init %empty_tuple.type = call %bound_method.loc18_3.2(%.loc18_3.3)
  172. // CHECK:STDOUT: return
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: