generic_empty.carbon 4.9 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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/array/generic_empty.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/array/generic_empty.carbon
  10. fn G(T:! type) {
  11. // We can initialize this without knowing T.
  12. var arr: [T; 0] = ();
  13. }
  14. // CHECK:STDOUT: --- generic_empty.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  18. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  19. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  20. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  21. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  22. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  23. // CHECK:STDOUT: %array_type: type = array_type %int_0, %T [symbolic]
  24. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %array_type [symbolic]
  25. // CHECK:STDOUT: %array: %array_type = tuple_value () [symbolic]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: imports {
  29. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/...
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: file {
  36. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  37. // CHECK:STDOUT: .Core = imports.%Core
  38. // CHECK:STDOUT: .G = %G.decl
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.import = import Core
  41. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  42. // CHECK:STDOUT: %T.patt.loc11_6.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc11_6.2 (constants.%T.patt)]
  43. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc11_6.1, runtime_param<invalid> [symbolic = %T.patt.loc11_6.2 (constants.%T.patt)]
  44. // CHECK:STDOUT: } {
  45. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  46. // CHECK:STDOUT: %T.loc11_6.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc11_6.2 (constants.%T)]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: generic fn @G(%T.loc11_6.1: type) {
  51. // CHECK:STDOUT: %T.loc11_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_6.2 (constants.%T)]
  52. // CHECK:STDOUT: %T.patt.loc11_6.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc11_6.2 (constants.%T.patt)]
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: !definition:
  55. // CHECK:STDOUT: %array_type.loc13_17.2: type = array_type constants.%int_0, @G.%T.loc11_6.2 (%T) [symbolic = %array_type.loc13_17.2 (constants.%array_type)]
  56. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @G.%array_type.loc13_17.2 (%array_type) [symbolic = %require_complete (constants.%require_complete)]
  57. // CHECK:STDOUT: %array: @G.%array_type.loc13_17.2 (%array_type) = tuple_value () [symbolic = %array (constants.%array)]
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn(%T.param_patt: type) {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: name_binding_decl {
  62. // CHECK:STDOUT: %arr.patt: @G.%array_type.loc13_17.2 (%array_type) = binding_pattern arr
  63. // CHECK:STDOUT: %.loc13_3.1: @G.%array_type.loc13_17.2 (%array_type) = var_pattern %arr.patt
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %arr.var: ref @G.%array_type.loc13_17.2 (%array_type) = var arr
  66. // CHECK:STDOUT: %.loc13_22.1: %empty_tuple.type = tuple_literal ()
  67. // CHECK:STDOUT: %.loc13_22.2: init @G.%array_type.loc13_17.2 (%array_type) = array_init () to %arr.var [symbolic = %array (constants.%array)]
  68. // CHECK:STDOUT: %.loc13_3.2: init @G.%array_type.loc13_17.2 (%array_type) = converted %.loc13_22.1, %.loc13_22.2 [symbolic = %array (constants.%array)]
  69. // CHECK:STDOUT: assign %arr.var, %.loc13_3.2
  70. // CHECK:STDOUT: %.loc13_17: type = splice_block %array_type.loc13_17.1 [symbolic = %array_type.loc13_17.2 (constants.%array_type)] {
  71. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc11_6.1 [symbolic = %T.loc11_6.2 (constants.%T)]
  72. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  73. // CHECK:STDOUT: %array_type.loc13_17.1: type = array_type %int_0, %T [symbolic = %array_type.loc13_17.2 (constants.%array_type)]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %arr: ref @G.%array_type.loc13_17.2 (%array_type) = bind_name arr, %arr.var
  76. // CHECK:STDOUT: return
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: specific @G(constants.%T) {
  81. // CHECK:STDOUT: %T.loc11_6.2 => constants.%T
  82. // CHECK:STDOUT: %T.patt.loc11_6.2 => constants.%T
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: