in_template.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/interop/cpp/function/in_template.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/in_template.carbon
  12. // --- class_template.h
  13. template<typename T> struct X {
  14. static void f(T t);
  15. };
  16. // TODO: We should be able to instantiate the class when needed.
  17. template struct X<int>;
  18. using Y = X<int>;
  19. // --- use_class_template.carbon
  20. library "[[@TEST_NAME]]";
  21. import Cpp library "class_template.h";
  22. fn F() {
  23. //@dump-sem-ir-begin
  24. Cpp.Y.f(42);
  25. //@dump-sem-ir-end
  26. }
  27. // CHECK:STDOUT: --- use_class_template.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  31. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  32. // CHECK:STDOUT: %.034: type = cpp_overload_set_type @X.f [concrete]
  33. // CHECK:STDOUT: %empty_struct: %.034 = struct_value () [concrete]
  34. // CHECK:STDOUT: %int_42.20e: Core.IntLiteral = int_value 42 [concrete]
  35. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  36. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  37. // CHECK:STDOUT: %X.f.type: type = fn_type @X.f [concrete]
  38. // CHECK:STDOUT: %X.f: %X.f.type = struct_value () [concrete]
  39. // CHECK:STDOUT: %ImplicitAs.type.d14: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  40. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  41. // CHECK:STDOUT: %To: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  42. // 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]
  43. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.1c0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.340 = struct_value () [symbolic]
  44. // CHECK:STDOUT: %ImplicitAs.impl_witness.204: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.9e9, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  45. // 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]
  46. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.584 = struct_value () [concrete]
  47. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.d14 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.204) [concrete]
  48. // CHECK:STDOUT: %.1df: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  49. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_42.20e, %Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0 [concrete]
  50. // 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]
  51. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_42.20e, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  52. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: imports {
  56. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  57. // CHECK:STDOUT: .Y = %X.decl
  58. // CHECK:STDOUT: import Cpp//...
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  61. // CHECK:STDOUT: %.a8d: %.034 = cpp_overload_set_value @X.f [concrete = constants.%empty_struct]
  62. // CHECK:STDOUT: %X.f.decl: %X.f.type = fn_decl @X.f [concrete = constants.%X.f] {
  63. // CHECK:STDOUT: <elided>
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: <elided>
  66. // CHECK:STDOUT: }
  67. // 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)]
  68. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.9e9 = impl_witness_table (%Core.import_ref.ee7), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @F() {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  74. // CHECK:STDOUT: %Y.ref: type = name_ref Y, imports.%X.decl [concrete = constants.%X]
  75. // CHECK:STDOUT: %f.ref: %.034 = name_ref f, imports.%.a8d [concrete = constants.%empty_struct]
  76. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42.20e]
  77. // CHECK:STDOUT: %impl.elem0: %.1df = impl_witness_access constants.%ImplicitAs.impl_witness.204, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.0f0]
  78. // CHECK:STDOUT: %bound_method.loc8_11.1: <bound method> = bound_method %int_42, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  79. // 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]
  80. // CHECK:STDOUT: %bound_method.loc8_11.2: <bound method> = bound_method %int_42, %specific_fn [concrete = constants.%bound_method]
  81. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc8_11.2(%int_42) [concrete = constants.%int_42.c68]
  82. // CHECK:STDOUT: %.loc8_11.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_42.c68]
  83. // CHECK:STDOUT: %.loc8_11.2: %i32 = converted %int_42, %.loc8_11.1 [concrete = constants.%int_42.c68]
  84. // CHECK:STDOUT: %X.f.call: init %empty_tuple.type = call imports.%X.f.decl(%.loc8_11.2)
  85. // CHECK:STDOUT: <elided>
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: