more_param_ir.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.d14: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  41. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  42. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  43. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  44. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.1c0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340 = struct_value () [symbolic]
  45. // CHECK:STDOUT: %ImplicitAs.impl_witness.204: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.9e9, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  46. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.584: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  47. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.584 = struct_value () [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.d14 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.204) [concrete]
  49. // CHECK:STDOUT: %.1df: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  50. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.abf: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0 [concrete]
  51. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  52. // CHECK:STDOUT: %bound_method.c11: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.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: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.d66: <bound method> = bound_method %int_6.462, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0 [concrete]
  58. // CHECK:STDOUT: %bound_method.0ef: <bound method> = bound_method %int_6.462, %Core.IntLiteral.as.ImplicitAs.impl.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: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  62. // CHECK:STDOUT: %facet_value: %type_where = facet_value %tuple.type.a1c, () [concrete]
  63. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.fb1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  64. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.5c6: %AggregateT.as_type.as.Destroy.impl.Op.type.fb1 = struct_value () [concrete]
  65. // CHECK:STDOUT: %ptr.0b7: type = ptr_type %tuple.type.a1c [concrete]
  66. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %AggregateT.as_type.as.Destroy.impl.Op.5c6, @AggregateT.as_type.as.Destroy.impl.Op(%facet_value) [concrete]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: imports {
  70. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  71. // CHECK:STDOUT: .Int = %Core.Int
  72. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  73. // CHECK:STDOUT: .Destroy = %Core.Destroy
  74. // CHECK:STDOUT: import Core//prelude
  75. // CHECK:STDOUT: import Core//prelude/...
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  78. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  79. // CHECK:STDOUT: %Core.import_ref.ee7: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340) = import_ref Core//prelude/parts/int, loc23_39, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.1c0)]
  80. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.9e9 = impl_witness_table (%Core.import_ref.ee7), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  81. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: file {
  85. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  86. // CHECK:STDOUT: .Core = imports.%Core
  87. // CHECK:STDOUT: .Foo = %Foo.decl
  88. // CHECK:STDOUT: .Main = %Main.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %Core.import = import Core
  91. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [concrete = constants.%Foo] {
  92. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  93. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  94. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = binding_pattern b [concrete]
  95. // CHECK:STDOUT: %b.param_patt: %pattern_type.7ce = value_param_pattern %b.patt, call_param1 [concrete]
  96. // CHECK:STDOUT: } {
  97. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  98. // CHECK:STDOUT: %.loc15_11: type = splice_block %i32.loc15_11 [concrete = constants.%i32] {
  99. // CHECK:STDOUT: %int_32.loc15_11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  100. // CHECK:STDOUT: %i32.loc15_11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  103. // CHECK:STDOUT: %b.param: %i32 = value_param call_param1
  104. // CHECK:STDOUT: %.loc15_19: type = splice_block %i32.loc15_19 [concrete = constants.%i32] {
  105. // CHECK:STDOUT: %int_32.loc15_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  106. // CHECK:STDOUT: %i32.loc15_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @Foo(%a.param: %i32, %b.param: %i32) {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: return
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: fn @Main() {
  119. // CHECK:STDOUT: !entry:
  120. // CHECK:STDOUT: name_binding_decl {
  121. // CHECK:STDOUT: %x.patt: %pattern_type.b74 = binding_pattern x [concrete]
  122. // CHECK:STDOUT: %x.var_patt: %pattern_type.b74 = var_pattern %x.patt [concrete]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %x.var: ref %tuple.type.a1c = var %x.var_patt
  125. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  126. // CHECK:STDOUT: %.loc18_22.1: %tuple.type.985 = tuple_literal (%int_1)
  127. // CHECK:STDOUT: %impl.elem0.loc18: %.1df = impl_witness_access constants.%ImplicitAs.impl_witness.204, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0]
  128. // CHECK:STDOUT: %bound_method.loc18_22.1: <bound method> = bound_method %int_1, %impl.elem0.loc18 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.abf]
  129. // CHECK:STDOUT: %specific_fn.loc18: <specific function> = specific_function %impl.elem0.loc18, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  130. // CHECK:STDOUT: %bound_method.loc18_22.2: <bound method> = bound_method %int_1, %specific_fn.loc18 [concrete = constants.%bound_method.c11]
  131. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc18: init %i32 = call %bound_method.loc18_22.2(%int_1) [concrete = constants.%int_1.5d2]
  132. // CHECK:STDOUT: %.loc18_22.2: init %i32 = converted %int_1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc18 [concrete = constants.%int_1.5d2]
  133. // CHECK:STDOUT: %.loc18_22.3: init %tuple.type.a1c = tuple_init (%.loc18_22.2) to %x.var [concrete = constants.%tuple]
  134. // CHECK:STDOUT: %.loc18_3.1: init %tuple.type.a1c = converted %.loc18_22.1, %.loc18_22.3 [concrete = constants.%tuple]
  135. // CHECK:STDOUT: assign %x.var, %.loc18_3.1
  136. // CHECK:STDOUT: %.loc18_15.1: type = splice_block %.loc18_15.3 [concrete = constants.%tuple.type.a1c] {
  137. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  138. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  139. // CHECK:STDOUT: %.loc18_15.2: %tuple.type.85c = tuple_literal (%i32)
  140. // CHECK:STDOUT: %.loc18_15.3: type = converted %.loc18_15.2, constants.%tuple.type.a1c [concrete = constants.%tuple.type.a1c]
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %x: ref %tuple.type.a1c = bind_name x, %x.var
  143. // CHECK:STDOUT: %Foo.ref: %Foo.type = name_ref Foo, file.%Foo.decl [concrete = constants.%Foo]
  144. // CHECK:STDOUT: %x.ref: ref %tuple.type.a1c = name_ref x, %x
  145. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  146. // CHECK:STDOUT: %tuple.elem0: ref %i32 = tuple_access %x.ref, element0
  147. // CHECK:STDOUT: %int_6: Core.IntLiteral = int_value 6 [concrete = constants.%int_6.462]
  148. // CHECK:STDOUT: %.loc20_8: %i32 = bind_value %tuple.elem0
  149. // CHECK:STDOUT: %impl.elem0.loc20: %.1df = impl_witness_access constants.%ImplicitAs.impl_witness.204, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0]
  150. // CHECK:STDOUT: %bound_method.loc20_12.1: <bound method> = bound_method %int_6, %impl.elem0.loc20 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.d66]
  151. // CHECK:STDOUT: %specific_fn.loc20: <specific function> = specific_function %impl.elem0.loc20, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  152. // CHECK:STDOUT: %bound_method.loc20_12.2: <bound method> = bound_method %int_6, %specific_fn.loc20 [concrete = constants.%bound_method.0ef]
  153. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc20: init %i32 = call %bound_method.loc20_12.2(%int_6) [concrete = constants.%int_6.e56]
  154. // CHECK:STDOUT: %.loc20_12.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc20 [concrete = constants.%int_6.e56]
  155. // CHECK:STDOUT: %.loc20_12.2: %i32 = converted %int_6, %.loc20_12.1 [concrete = constants.%int_6.e56]
  156. // CHECK:STDOUT: %Foo.call: init %empty_tuple.type = call %Foo.ref(%.loc20_8, %.loc20_12.2)
  157. // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%tuple.type.a1c, () [concrete = constants.%facet_value]
  158. // CHECK:STDOUT: %.loc18_3.2: %type_where = converted constants.%tuple.type.a1c, %facet_value [concrete = constants.%facet_value]
  159. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %x.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.5c6
  160. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function constants.%AggregateT.as_type.as.Destroy.impl.Op.5c6, @AggregateT.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%AggregateT.as_type.as.Destroy.impl.Op.specific_fn]
  161. // CHECK:STDOUT: %bound_method.loc18_3: <bound method> = bound_method %x.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
  162. // CHECK:STDOUT: %addr: %ptr.0b7 = addr_of %x.var
  163. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc18_3(%addr)
  164. // CHECK:STDOUT: return
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: