in_namespace.carbon 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 = @__global_init.%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: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  45. // CHECK:STDOUT: %return.patt: %C = return_slot_pattern
  46. // CHECK:STDOUT: %return.param_patt: %C = out_param_pattern %return.patt, runtime_param0
  47. // CHECK:STDOUT: } {
  48. // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  49. // CHECK:STDOUT: %a.ref: type = name_ref a, file.%a [template = constants.%C]
  50. // CHECK:STDOUT: %return.param: ref %C = out_param runtime_param0
  51. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: class @C {
  56. // CHECK:STDOUT: %.loc11: %C.elem = field_decl v, element0 [template]
  57. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.v [template = constants.%complete_type]
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: !members:
  60. // CHECK:STDOUT: .Self = constants.%C
  61. // CHECK:STDOUT: .v = %.loc11
  62. // CHECK:STDOUT: complete_type_witness = %complete_type
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @F() -> %return.param_patt: %C {
  66. // CHECK:STDOUT: !entry:
  67. // CHECK:STDOUT: %.loc19_17.1: %empty_tuple.type = tuple_literal ()
  68. // CHECK:STDOUT: %.loc19_18.1: %struct_type.v = struct_literal (%.loc19_17.1)
  69. // CHECK:STDOUT: %.loc19_18.2: ref %empty_tuple.type = class_element_access %return, element0
  70. // CHECK:STDOUT: %.loc19_17.2: init %empty_tuple.type = tuple_init () to %.loc19_18.2 [template = constants.%empty_tuple]
  71. // CHECK:STDOUT: %.loc19_18.3: init %empty_tuple.type = converted %.loc19_17.1, %.loc19_17.2 [template = constants.%empty_tuple]
  72. // CHECK:STDOUT: %.loc19_18.4: init %C = class_init (%.loc19_18.3), %return [template = constants.%C.val]
  73. // CHECK:STDOUT: %.loc19_19: init %C = converted %.loc19_18.1, %.loc19_18.4 [template = constants.%C.val]
  74. // CHECK:STDOUT: return %.loc19_19 to %return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @__global_init() {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %.loc16_22.1: %empty_tuple.type = tuple_literal ()
  80. // CHECK:STDOUT: %.loc16_23.1: %struct_type.v = struct_literal (%.loc16_22.1)
  81. // CHECK:STDOUT: %.loc16_23.2: ref %C = temporary_storage
  82. // CHECK:STDOUT: %.loc16_23.3: ref %empty_tuple.type = class_element_access %.loc16_23.2, element0
  83. // CHECK:STDOUT: %.loc16_22.2: init %empty_tuple.type = tuple_init () to %.loc16_23.3 [template = constants.%empty_tuple]
  84. // CHECK:STDOUT: %.loc16_23.4: init %empty_tuple.type = converted %.loc16_22.1, %.loc16_22.2 [template = constants.%empty_tuple]
  85. // CHECK:STDOUT: %.loc16_23.5: init %C = class_init (%.loc16_23.4), %.loc16_23.2 [template = constants.%C.val]
  86. // CHECK:STDOUT: %.loc16_23.6: ref %C = temporary %.loc16_23.2, %.loc16_23.5
  87. // CHECK:STDOUT: %.loc16_24.1: ref %C = converted %.loc16_23.1, %.loc16_23.6
  88. // CHECK:STDOUT: %.loc16_24.2: %C = bind_value %.loc16_24.1
  89. // CHECK:STDOUT: %b: %C = bind_name b, %.loc16_24.2
  90. // CHECK:STDOUT: return
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: