generic_empty.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: array(T, 0) = ();
  13. }
  14. fn H() {
  15. G(i32);
  16. }
  17. // CHECK:STDOUT: --- generic_empty.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  21. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  22. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  23. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  24. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  26. // CHECK:STDOUT: %array_type.281: type = array_type %int_0, %T [symbolic]
  27. // CHECK:STDOUT: %require_complete.b7f: <witness> = require_complete_type %array_type.281 [symbolic]
  28. // CHECK:STDOUT: %pattern_type.d48: type = pattern_type %array_type.281 [symbolic]
  29. // CHECK:STDOUT: %array.2ed: %array_type.281 = tuple_value () [symbolic]
  30. // CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
  31. // CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  33. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  34. // CHECK:STDOUT: %G.specific_fn: <specific function> = specific_function %G, @G(%i32) [concrete]
  35. // CHECK:STDOUT: %array_type.f5c: type = array_type %int_0, %i32 [concrete]
  36. // CHECK:STDOUT: %complete_type.cff: <witness> = complete_type_witness %array_type.f5c [concrete]
  37. // CHECK:STDOUT: %pattern_type.772: type = pattern_type %array_type.f5c [concrete]
  38. // CHECK:STDOUT: %array.812: %array_type.f5c = tuple_value () [concrete]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: imports {
  42. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  43. // CHECK:STDOUT: .Int = %Core.Int
  44. // CHECK:STDOUT: import Core//prelude
  45. // CHECK:STDOUT: import Core//prelude/...
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  51. // CHECK:STDOUT: .Core = imports.%Core
  52. // CHECK:STDOUT: .G = %G.decl
  53. // CHECK:STDOUT: .H = %H.decl
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Core.import = import Core
  56. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  57. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  58. // CHECK:STDOUT: } {
  59. // CHECK:STDOUT: %T.loc11_6.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_6.2 (constants.%T)]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: generic fn @G(%T.loc11_6.1: type) {
  65. // CHECK:STDOUT: %T.loc11_6.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_6.2 (constants.%T)]
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !definition:
  68. // CHECK:STDOUT: %array_type.loc13_22.2: type = array_type constants.%int_0, %T.loc11_6.2 [symbolic = %array_type.loc13_22.2 (constants.%array_type.281)]
  69. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %array_type.loc13_22.2 [symbolic = %require_complete (constants.%require_complete.b7f)]
  70. // CHECK:STDOUT: %pattern_type: type = pattern_type %array_type.loc13_22.2 [symbolic = %pattern_type (constants.%pattern_type.d48)]
  71. // CHECK:STDOUT: %array: @G.%array_type.loc13_22.2 (%array_type.281) = tuple_value () [symbolic = %array (constants.%array.2ed)]
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn() {
  74. // CHECK:STDOUT: !entry:
  75. // CHECK:STDOUT: name_binding_decl {
  76. // CHECK:STDOUT: %arr.patt: @G.%pattern_type (%pattern_type.d48) = binding_pattern arr [concrete]
  77. // CHECK:STDOUT: %.loc13_3.1: @G.%pattern_type (%pattern_type.d48) = var_pattern %arr.patt [concrete]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %arr.var: ref @G.%array_type.loc13_22.2 (%array_type.281) = var arr
  80. // CHECK:STDOUT: %.loc13_27.1: %empty_tuple.type = tuple_literal ()
  81. // CHECK:STDOUT: %.loc13_27.2: init @G.%array_type.loc13_22.2 (%array_type.281) = array_init () to %arr.var [symbolic = %array (constants.%array.2ed)]
  82. // CHECK:STDOUT: %.loc13_3.2: init @G.%array_type.loc13_22.2 (%array_type.281) = converted %.loc13_27.1, %.loc13_27.2 [symbolic = %array (constants.%array.2ed)]
  83. // CHECK:STDOUT: assign %arr.var, %.loc13_3.2
  84. // CHECK:STDOUT: %.loc13_22: type = splice_block %array_type.loc13_22.1 [symbolic = %array_type.loc13_22.2 (constants.%array_type.281)] {
  85. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc11_6.1 [symbolic = %T.loc11_6.2 (constants.%T)]
  86. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  87. // CHECK:STDOUT: %array_type.loc13_22.1: type = array_type %int_0, %T.ref [symbolic = %array_type.loc13_22.2 (constants.%array_type.281)]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %arr: ref @G.%array_type.loc13_22.2 (%array_type.281) = bind_name arr, %arr.var
  90. // CHECK:STDOUT: return
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @H() {
  95. // CHECK:STDOUT: !entry:
  96. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
  97. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  98. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  99. // CHECK:STDOUT: %G.specific_fn: <specific function> = specific_function %G.ref, @G(constants.%i32) [concrete = constants.%G.specific_fn]
  100. // CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.specific_fn()
  101. // CHECK:STDOUT: return
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: specific @G(constants.%T) {
  105. // CHECK:STDOUT: %T.loc11_6.2 => constants.%T
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: specific @G(constants.%i32) {
  109. // CHECK:STDOUT: %T.loc11_6.2 => constants.%i32
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: !definition:
  112. // CHECK:STDOUT: %array_type.loc13_22.2 => constants.%array_type.f5c
  113. // CHECK:STDOUT: %require_complete => constants.%complete_type.cff
  114. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.772
  115. // CHECK:STDOUT: %array => constants.%array.812
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: