in_namespace.carbon 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %.2: type = unbound_element_type %C, %.1 [template]
  23. // CHECK:STDOUT: %.3: type = struct_type {.v: %.1} [template]
  24. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  25. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  26. // CHECK:STDOUT: %struct: %C = struct_value (%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: %NS.ref.loc16: <namespace> = name_ref NS, %NS [template = %NS]
  45. // CHECK:STDOUT: %a.ref.loc16: type = name_ref a, %a [template = constants.%C]
  46. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  47. // CHECK:STDOUT: %NS.ref.loc18: <namespace> = name_ref NS, %NS [template = %NS]
  48. // CHECK:STDOUT: %a.ref.loc18: type = name_ref a, %a [template = constants.%C]
  49. // CHECK:STDOUT: @F.%return: ref %C = var <return slot>
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: class @C {
  54. // CHECK:STDOUT: %.loc11_19.1: %.1 = tuple_literal ()
  55. // CHECK:STDOUT: %.loc11_19.2: type = converted %.loc11_19.1, constants.%.1 [template = constants.%.1]
  56. // CHECK:STDOUT: %.loc11_16: %.2 = field_decl v, element0 [template]
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: !members:
  59. // CHECK:STDOUT: .Self = constants.%C
  60. // CHECK:STDOUT: .v = %.loc11_16
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @F() -> %return: %C {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: %.loc19_17.1: %.1 = tuple_literal ()
  66. // CHECK:STDOUT: %.loc19_18.1: %.3 = struct_literal (%.loc19_17.1)
  67. // CHECK:STDOUT: %.loc19_18.2: ref %.1 = class_element_access %return, element0
  68. // CHECK:STDOUT: %.loc19_17.2: init %.1 = tuple_init () to %.loc19_18.2 [template = constants.%tuple]
  69. // CHECK:STDOUT: %.loc19_18.3: init %.1 = converted %.loc19_17.1, %.loc19_17.2 [template = constants.%tuple]
  70. // CHECK:STDOUT: %.loc19_18.4: init %C = class_init (%.loc19_18.3), %return [template = constants.%struct]
  71. // CHECK:STDOUT: %.loc19_19: init %C = converted %.loc19_18.1, %.loc19_18.4 [template = constants.%struct]
  72. // CHECK:STDOUT: return %.loc19_19 to %return
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @__global_init() {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %.loc16_22.1: %.1 = tuple_literal ()
  78. // CHECK:STDOUT: %.loc16_23.1: %.3 = struct_literal (%.loc16_22.1)
  79. // CHECK:STDOUT: %.loc16_23.2: ref %C = temporary_storage
  80. // CHECK:STDOUT: %.loc16_23.3: ref %.1 = class_element_access %.loc16_23.2, element0
  81. // CHECK:STDOUT: %.loc16_22.2: init %.1 = tuple_init () to %.loc16_23.3 [template = constants.%tuple]
  82. // CHECK:STDOUT: %.loc16_23.4: init %.1 = converted %.loc16_22.1, %.loc16_22.2 [template = constants.%tuple]
  83. // CHECK:STDOUT: %.loc16_23.5: init %C = class_init (%.loc16_23.4), %.loc16_23.2 [template = constants.%struct]
  84. // CHECK:STDOUT: %.loc16_23.6: ref %C = temporary %.loc16_23.2, %.loc16_23.5
  85. // CHECK:STDOUT: %.loc16_24.1: ref %C = converted %.loc16_23.1, %.loc16_23.6
  86. // CHECK:STDOUT: %.loc16_24.2: %C = bind_value %.loc16_24.1
  87. // CHECK:STDOUT: %b: %C = bind_name b, %.loc16_24.2
  88. // CHECK:STDOUT: return
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: