in_namespace.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/alias/no_prelude/in_namespace.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/no_prelude/in_namespace.carbon
  10. class C { var v: (); }
  11. namespace NS;
  12. alias NS.a = C;
  13. let b: NS.a = {.v = ()};
  14. fn F() -> NS.a {
  15. return {.v = ()};
  16. }
  17. // CHECK:STDOUT: --- in_namespace.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %C: type = class_type @C [template]
  21. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  22. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %empty_tuple.type [template]
  23. // CHECK:STDOUT: %struct_type.v: type = struct_type {.v: %empty_tuple.type} [template]
  24. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.v [template]
  25. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
  26. // CHECK:STDOUT: %C.val: %C = struct_value (%empty_tuple) [template]
  27. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  28. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .C = %C.decl
  34. // CHECK:STDOUT: .NS = %NS
  35. // CHECK:STDOUT: .b = %b
  36. // CHECK:STDOUT: .F = %F.decl
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  39. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .a = %a
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  43. // CHECK:STDOUT: %a: type = bind_alias a, %C.decl [template = constants.%C]
  44. // CHECK:STDOUT: name_binding_decl {
  45. // CHECK:STDOUT: %b.patt: %C = binding_pattern b
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %.loc16_10: type = splice_block %a.ref [template = constants.%C] {
  48. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, %NS [template = %NS]
  49. // CHECK:STDOUT: %a.ref: type = name_ref a, %a [template = constants.%C]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %.loc16_23.1: ref %C = temporary_storage
  52. // CHECK:STDOUT: %.loc16_23.2: ref %empty_tuple.type = class_element_access %.loc16_23.1, element0
  53. // CHECK:STDOUT: %.loc16_22: init %empty_tuple.type = tuple_init () to %.loc16_23.2 [template = constants.%empty_tuple]
  54. // CHECK:STDOUT: %.loc16_23.3: init %empty_tuple.type = converted @__global_init.%.loc16_22, %.loc16_22 [template = constants.%empty_tuple]
  55. // CHECK:STDOUT: %.loc16_23.4: init %C = class_init (%.loc16_23.3), %.loc16_23.1 [template = constants.%C.val]
  56. // CHECK:STDOUT: %.loc16_23.5: ref %C = temporary %.loc16_23.1, %.loc16_23.4
  57. // CHECK:STDOUT: %.loc16_23.6: ref %C = converted @__global_init.%.loc16_23, %.loc16_23.5
  58. // CHECK:STDOUT: %b: ref %C = bind_name b, %.loc16_23.6
  59. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  60. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  61. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param0
  62. // CHECK:STDOUT: } {
  63. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  64. // CHECK:STDOUT: %a.ref: type = name_ref a, file.%a [template = constants.%C]
  65. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param0
  66. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @C {
  71. // CHECK:STDOUT: %.loc11_16: %C.elem = field_decl v, element0 [template]
  72. // CHECK:STDOUT: name_binding_decl {
  73. // CHECK:STDOUT: %.loc11_11: %C.elem = var_pattern %.loc11_16
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %.var: ref %C.elem = var <none>
  76. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.v [template = constants.%complete_type]
  77. // CHECK:STDOUT: complete_type_witness = %complete_type
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !members:
  80. // CHECK:STDOUT: .Self = constants.%C
  81. // CHECK:STDOUT: .v = %.loc11_16
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @F() -> %return.param_patt: %C {
  85. // CHECK:STDOUT: !entry:
  86. // CHECK:STDOUT: %.loc19_17.1: %empty_tuple.type = tuple_literal ()
  87. // CHECK:STDOUT: %.loc19_18.1: %struct_type.v = struct_literal (%.loc19_17.1)
  88. // CHECK:STDOUT: %.loc19_18.2: ref %empty_tuple.type = class_element_access %return, element0
  89. // CHECK:STDOUT: %.loc19_17.2: init %empty_tuple.type = tuple_init () to %.loc19_18.2 [template = constants.%empty_tuple]
  90. // CHECK:STDOUT: %.loc19_18.3: init %empty_tuple.type = converted %.loc19_17.1, %.loc19_17.2 [template = constants.%empty_tuple]
  91. // CHECK:STDOUT: %.loc19_18.4: init %C = class_init (%.loc19_18.3), %return [template = constants.%C.val]
  92. // CHECK:STDOUT: %.loc19_19: init %C = converted %.loc19_18.1, %.loc19_18.4 [template = constants.%C.val]
  93. // CHECK:STDOUT: return %.loc19_19 to %return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @__global_init() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %.loc16_22: %empty_tuple.type = tuple_literal ()
  99. // CHECK:STDOUT: %.loc16_23: %struct_type.v = struct_literal (%.loc16_22)
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: