template_param.carbon 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/generic/no_prelude/template_param.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/generic/no_prelude/template_param.carbon
  10. // --- fn.carbon
  11. library "[[@TEST_NAME]]";
  12. fn F(template T:! type) {
  13. }
  14. fn G() {
  15. F({});
  16. }
  17. // CHECK:STDOUT: --- fn.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, template [template]
  21. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0, template [template]
  22. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  23. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  24. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  26. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  27. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  28. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F, @F(%empty_struct_type) [concrete]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  33. // CHECK:STDOUT: .F = %F.decl
  34. // CHECK:STDOUT: .G = %G.decl
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  37. // CHECK:STDOUT: %T.patt.loc4_15.1: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  38. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc4_15.1, runtime_param<none> [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  39. // CHECK:STDOUT: } {
  40. // CHECK:STDOUT: %T.param: type = value_param runtime_param<none>
  41. // CHECK:STDOUT: %T.loc4_15.1: type = bind_symbolic_name T, 0, template, %T.param [template = %T.loc4_15.2 (constants.%T)]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: generic fn @F(%T.loc4_15.1: type) {
  47. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  48. // CHECK:STDOUT: %T.patt.loc4_15.2: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: !definition:
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn(%T.param_patt: type) {
  53. // CHECK:STDOUT: !entry:
  54. // CHECK:STDOUT: return
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @G() {
  59. // CHECK:STDOUT: !entry:
  60. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  61. // CHECK:STDOUT: %.loc8_6: %empty_struct_type = struct_literal ()
  62. // CHECK:STDOUT: %.loc8_7: type = converted %.loc8_6, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  63. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%empty_struct_type) [concrete = constants.%F.specific_fn]
  64. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.specific_fn()
  65. // CHECK:STDOUT: return
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: specific @F(constants.%T) {
  69. // CHECK:STDOUT: %T.loc4_15.2 => constants.%T
  70. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: specific @F(constants.%empty_struct_type) {
  74. // CHECK:STDOUT: %T.loc4_15.2 => constants.%empty_struct_type
  75. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%empty_struct_type
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !definition:
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: