template_param.carbon 3.7 KB

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