var_param.carbon 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/generic/var_param.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/var_param.carbon
  12. interface I {
  13. fn Op[self: Self]();
  14. }
  15. impl i32 as I {
  16. fn Op[unused self: Self]() {}
  17. }
  18. //@dump-sem-ir-begin
  19. fn TestOp[T:! I](unused var x: T) {}
  20. //@dump-sem-ir-end
  21. fn Test(x: i32) {
  22. //@dump-sem-ir-begin
  23. TestOp(x);
  24. //@dump-sem-ir-end
  25. }
  26. // CHECK:STDOUT: --- var_param.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  30. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  31. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  32. // CHECK:STDOUT: %N: Core.IntLiteral = symbolic_binding N, 0 [symbolic]
  33. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  34. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness @i32.as.I.impl.%I.impl_witness_table [concrete]
  35. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  36. // CHECK:STDOUT: %I.facet: %I.type = facet_value %i32, (%I.impl_witness) [concrete]
  37. // CHECK:STDOUT: %i32.builtin: type = int_type signed, %int_32 [concrete]
  38. // CHECK:STDOUT: %complete_type.f8a: <witness> = complete_type_witness %i32.builtin [concrete]
  39. // CHECK:STDOUT: %pattern_type.9d9: type = pattern_type %I.type [concrete]
  40. // CHECK:STDOUT: %T.651: %I.type = symbolic_binding T, 0 [symbolic]
  41. // CHECK:STDOUT: %T.as_type.066: type = facet_access_type %T.651 [symbolic]
  42. // CHECK:STDOUT: %pattern_type.f4e: type = pattern_type %T.as_type.066 [symbolic]
  43. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [concrete]
  44. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [concrete]
  45. // CHECK:STDOUT: %require_complete.6bb: <witness> = require_complete_type %T.as_type.066 [symbolic]
  46. // CHECK:STDOUT: %TestOp.specific_fn: <specific function> = specific_function %TestOp, @TestOp(%I.facet) [concrete]
  47. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  48. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.824: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  49. // CHECK:STDOUT: %Int.as.Copy.impl.Op.9b9: %Int.as.Copy.impl.Op.type.824 = struct_value () [symbolic]
  50. // CHECK:STDOUT: %Copy.impl_witness.f17: <witness> = impl_witness imports.%Copy.impl_witness_table.e76, @Int.as.Copy.impl(%int_32) [concrete]
  51. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.546: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  52. // CHECK:STDOUT: %Int.as.Copy.impl.Op.664: %Int.as.Copy.impl.Op.type.546 = struct_value () [concrete]
  53. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %i32, (%Copy.impl_witness.f17) [concrete]
  54. // CHECK:STDOUT: %Copy.WithSelf.Op.type.081: type = fn_type @Copy.WithSelf.Op, @Copy.WithSelf(%Copy.facet) [concrete]
  55. // CHECK:STDOUT: %.8e2: type = fn_type_with_self_type %Copy.WithSelf.Op.type.081, %Copy.facet [concrete]
  56. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.664, @Int.as.Copy.impl.Op(%int_32) [concrete]
  57. // CHECK:STDOUT: %Destroy.Op.type.bae255.2: type = fn_type @Destroy.Op.loc22_25.2 [concrete]
  58. // CHECK:STDOUT: %Destroy.Op.651ba6.2: %Destroy.Op.type.bae255.2 = struct_value () [concrete]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: imports {
  62. // CHECK:STDOUT: %Core.import_ref.18d: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.824) = 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.9b9)]
  63. // CHECK:STDOUT: %Copy.impl_witness_table.e76 = impl_witness_table (%Core.import_ref.18d), @Int.as.Copy.impl [concrete]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: file {
  67. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [concrete = constants.%TestOp] {
  68. // CHECK:STDOUT: %T.patt: %pattern_type.9d9 = symbolic_binding_pattern T, 0 [concrete]
  69. // CHECK:STDOUT: %x.patt: @TestOp.%pattern_type (%pattern_type.f4e) = ref_binding_pattern x [concrete]
  70. // CHECK:STDOUT: %x.param_patt: @TestOp.%pattern_type (%pattern_type.f4e) = var_param_pattern %x.patt [concrete]
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %.loc22_15: type = splice_block %I.ref [concrete = constants.%I.type] {
  73. // CHECK:STDOUT: <elided>
  74. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %T.loc22_12.2: %I.type = symbolic_binding T, 0 [symbolic = %T.loc22_12.1 (constants.%T.651)]
  77. // CHECK:STDOUT: %x.param: ref @TestOp.%T.as_type.loc22_32.1 (%T.as_type.066) = ref_param call_param0
  78. // CHECK:STDOUT: %.loc22_32.1: type = splice_block %.loc22_32.2 [symbolic = %T.as_type.loc22_32.1 (constants.%T.as_type.066)] {
  79. // CHECK:STDOUT: %T.ref: %I.type = name_ref T, %T.loc22_12.2 [symbolic = %T.loc22_12.1 (constants.%T.651)]
  80. // CHECK:STDOUT: %T.as_type.loc22_32.2: type = facet_access_type %T.ref [symbolic = %T.as_type.loc22_32.1 (constants.%T.as_type.066)]
  81. // CHECK:STDOUT: %.loc22_32.2: type = converted %T.ref, %T.as_type.loc22_32.2 [symbolic = %T.as_type.loc22_32.1 (constants.%T.as_type.066)]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %x: ref @TestOp.%T.as_type.loc22_32.1 (%T.as_type.066) = ref_binding x, %x.param
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: generic fn @TestOp(%T.loc22_12.2: %I.type) {
  88. // CHECK:STDOUT: %T.loc22_12.1: %I.type = symbolic_binding T, 0 [symbolic = %T.loc22_12.1 (constants.%T.651)]
  89. // CHECK:STDOUT: %T.as_type.loc22_32.1: type = facet_access_type %T.loc22_12.1 [symbolic = %T.as_type.loc22_32.1 (constants.%T.as_type.066)]
  90. // CHECK:STDOUT: %pattern_type: type = pattern_type %T.as_type.loc22_32.1 [symbolic = %pattern_type (constants.%pattern_type.f4e)]
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !definition:
  93. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.as_type.loc22_32.1 [symbolic = %require_complete (constants.%require_complete.6bb)]
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn(%x.param: ref @TestOp.%T.as_type.loc22_32.1 (%T.as_type.066)) {
  96. // CHECK:STDOUT: !entry:
  97. // CHECK:STDOUT: return
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @Test(%x.param: %i32) {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: %TestOp.ref: %TestOp.type = name_ref TestOp, file.%TestOp.decl [concrete = constants.%TestOp]
  104. // CHECK:STDOUT: %x.ref: %i32 = name_ref x, %x
  105. // CHECK:STDOUT: %I.facet: %I.type = facet_value constants.%i32, (constants.%I.impl_witness) [concrete = constants.%I.facet]
  106. // CHECK:STDOUT: %.loc27: %I.type = converted constants.%i32, %I.facet [concrete = constants.%I.facet]
  107. // CHECK:STDOUT: %TestOp.specific_fn: <specific function> = specific_function %TestOp.ref, @TestOp(constants.%I.facet) [concrete = constants.%TestOp.specific_fn]
  108. // CHECK:STDOUT: %.loc22_25.1: ref %i32 = temporary_storage
  109. // CHECK:STDOUT: %impl.elem0: %.8e2 = impl_witness_access constants.%Copy.impl_witness.f17, element0 [concrete = constants.%Int.as.Copy.impl.Op.664]
  110. // CHECK:STDOUT: %bound_method.loc27_10.1: <bound method> = bound_method %x.ref, %impl.elem0
  111. // 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]
  112. // CHECK:STDOUT: %bound_method.loc27_10.2: <bound method> = bound_method %x.ref, %specific_fn
  113. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc27_10.2(%x.ref)
  114. // CHECK:STDOUT: %.loc22_25.2: ref %i32 = temporary %.loc22_25.1, %Int.as.Copy.impl.Op.call
  115. // CHECK:STDOUT: %TestOp.call: init %empty_tuple.type = call %TestOp.specific_fn(%.loc22_25.2)
  116. // CHECK:STDOUT: %Destroy.Op.bound: <bound method> = bound_method %.loc22_25.2, constants.%Destroy.Op.651ba6.2
  117. // CHECK:STDOUT: %Destroy.Op.call: init %empty_tuple.type = call %Destroy.Op.bound(%.loc22_25.2)
  118. // CHECK:STDOUT: <elided>
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: fn @Destroy.Op.loc22_25.1(%self.param: ref %i32.builtin) = "no_op";
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: fn @Destroy.Op.loc22_25.2(%self.param: ref %i32) {
  124. // CHECK:STDOUT: !entry:
  125. // CHECK:STDOUT: return
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: specific @TestOp(constants.%T.651) {
  129. // CHECK:STDOUT: %T.loc22_12.1 => constants.%T.651
  130. // CHECK:STDOUT: %T.as_type.loc22_32.1 => constants.%T.as_type.066
  131. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.f4e
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: specific @TestOp(constants.%I.facet) {
  135. // CHECK:STDOUT: %T.loc22_12.1 => constants.%I.facet
  136. // CHECK:STDOUT: %T.as_type.loc22_32.1 => constants.%i32
  137. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7ce
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: !definition:
  140. // CHECK:STDOUT: %require_complete => constants.%complete_type.f8a
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: