i32.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/i32.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/i32.carbon
  14. fn Echo(a: i32) -> i32 {
  15. return a;
  16. }
  17. fn Main() {
  18. var b: i32 = Echo(1);
  19. }
  20. // CHECK:STDOUT: --- i32.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: %N: Core.IntLiteral = symbolic_binding N, 0 [symbolic]
  28. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  29. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  30. // CHECK:STDOUT: %Echo.type: type = fn_type @Echo [concrete]
  31. // CHECK:STDOUT: %Echo: %Echo.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  33. // CHECK:STDOUT: %Copy.Op.type: type = fn_type @Copy.Op [concrete]
  34. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.24b: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  35. // CHECK:STDOUT: %Int.as.Copy.impl.Op.c95: %Int.as.Copy.impl.Op.type.24b = struct_value () [symbolic]
  36. // CHECK:STDOUT: %Copy.impl_witness.fb7: <witness> = impl_witness imports.%Copy.impl_witness_table.b6a, @Int.as.Copy.impl(%int_32) [concrete]
  37. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.469: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  38. // CHECK:STDOUT: %Int.as.Copy.impl.Op.dfd: %Int.as.Copy.impl.Op.type.469 = struct_value () [concrete]
  39. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %i32, (%Copy.impl_witness.fb7) [concrete]
  40. // CHECK:STDOUT: %.65f: type = fn_type_with_self_type %Copy.Op.type, %Copy.facet [concrete]
  41. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.dfd, @Int.as.Copy.impl.Op(%int_32) [concrete]
  42. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  43. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  44. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  45. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  46. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  47. // CHECK:STDOUT: %ImplicitAs.type.d14: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  49. // CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
  50. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.f51: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  51. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.2a1: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.f51 = struct_value () [symbolic]
  52. // CHECK:STDOUT: %ImplicitAs.impl_witness.bc9: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.132, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  53. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.51e: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  54. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.51e = struct_value () [concrete]
  55. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.d14 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.bc9) [concrete]
  56. // CHECK:STDOUT: %.322: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  57. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b [concrete]
  58. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  59. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_1.5b8, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  60. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  61. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  62. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  63. // CHECK:STDOUT: %facet_value: %type_where = facet_value %i32, () [concrete]
  64. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.d4e: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  65. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.424: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.d4e = struct_value () [concrete]
  66. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %DestroyT.binding.as_type.as.Destroy.impl.Op.424, @DestroyT.binding.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: .Copy = %Core.Copy
  73. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  74. // CHECK:STDOUT: .Destroy = %Core.Destroy
  75. // CHECK:STDOUT: import Core//prelude
  76. // CHECK:STDOUT: import Core//prelude/...
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  79. // CHECK:STDOUT: %Core.Copy: type = import_ref Core//prelude/parts/copy, Copy, loaded [concrete = constants.%Copy.type]
  80. // CHECK:STDOUT: %Core.import_ref.d12: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.24b) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.c95)]
  81. // CHECK:STDOUT: %Copy.impl_witness_table.b6a = impl_witness_table (%Core.import_ref.d12), @Int.as.Copy.impl [concrete]
  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.e24: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.f51) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.2a1)]
  84. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.132 = impl_witness_table (%Core.import_ref.e24), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  85. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: file {
  89. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  90. // CHECK:STDOUT: .Core = imports.%Core
  91. // CHECK:STDOUT: .Echo = %Echo.decl
  92. // CHECK:STDOUT: .Main = %Main.decl
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %Core.import = import Core
  95. // CHECK:STDOUT: %Echo.decl: %Echo.type = fn_decl @Echo [concrete = constants.%Echo] {
  96. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  97. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  98. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  99. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  100. // CHECK:STDOUT: } {
  101. // CHECK:STDOUT: %int_32.loc15_20: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  102. // CHECK:STDOUT: %i32.loc15_20: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  103. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  104. // CHECK:STDOUT: %.loc15: type = splice_block %i32.loc15_12 [concrete = constants.%i32] {
  105. // CHECK:STDOUT: %int_32.loc15_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  106. // CHECK:STDOUT: %i32.loc15_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %a: %i32 = value_binding a, %a.param
  109. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  110. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @Echo(%a.param: %i32) -> %i32 {
  116. // CHECK:STDOUT: !entry:
  117. // CHECK:STDOUT: %a.ref: %i32 = name_ref a, %a
  118. // CHECK:STDOUT: %impl.elem0: %.65f = impl_witness_access constants.%Copy.impl_witness.fb7, element0 [concrete = constants.%Int.as.Copy.impl.Op.dfd]
  119. // CHECK:STDOUT: %bound_method.loc16_10.1: <bound method> = bound_method %a.ref, %impl.elem0
  120. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  121. // CHECK:STDOUT: %bound_method.loc16_10.2: <bound method> = bound_method %a.ref, %specific_fn
  122. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc16_10.2(%a.ref)
  123. // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call to %return
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: fn @Main() {
  127. // CHECK:STDOUT: !entry:
  128. // CHECK:STDOUT: name_binding_decl {
  129. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = ref_binding_pattern b [concrete]
  130. // CHECK:STDOUT: %b.var_patt: %pattern_type.7ce = var_pattern %b.patt [concrete]
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: %b.var: ref %i32 = var %b.var_patt
  133. // CHECK:STDOUT: %Echo.ref: %Echo.type = name_ref Echo, file.%Echo.decl [concrete = constants.%Echo]
  134. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  135. // CHECK:STDOUT: %impl.elem0: %.322 = impl_witness_access constants.%ImplicitAs.impl_witness.bc9, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.e9b]
  136. // CHECK:STDOUT: %bound_method.loc20_21.1: <bound method> = bound_method %int_1, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  137. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  138. // CHECK:STDOUT: %bound_method.loc20_21.2: <bound method> = bound_method %int_1, %specific_fn [concrete = constants.%bound_method]
  139. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc20_21.2(%int_1) [concrete = constants.%int_1.5d2]
  140. // CHECK:STDOUT: %.loc20_21.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_1.5d2]
  141. // CHECK:STDOUT: %.loc20_21.2: %i32 = converted %int_1, %.loc20_21.1 [concrete = constants.%int_1.5d2]
  142. // CHECK:STDOUT: %Echo.call: init %i32 = call %Echo.ref(%.loc20_21.2)
  143. // CHECK:STDOUT: assign %b.var, %Echo.call
  144. // CHECK:STDOUT: %.loc20_10: type = splice_block %i32 [concrete = constants.%i32] {
  145. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  146. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: %b: ref %i32 = ref_binding b, %b.var
  149. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %b.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.424
  150. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.424, @DestroyT.binding.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn]
  151. // CHECK:STDOUT: %bound_method.loc20_3: <bound method> = bound_method %b.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
  152. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method.loc20_3(%b.var)
  153. // CHECK:STDOUT: return
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: