nested_name.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/nested_name.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/nested_name.carbon
  14. class Outer {
  15. class Inner {
  16. var n: i32;
  17. }
  18. }
  19. fn F(oi: Outer.Inner) -> i32 {
  20. return oi.n;
  21. }
  22. fn G(o: Outer) {
  23. var i: o.Inner;
  24. }
  25. // CHECK:STDOUT: --- nested_name.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %Outer: type = class_type @Outer [concrete]
  29. // CHECK:STDOUT: %Inner: type = class_type @Inner [concrete]
  30. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  31. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  32. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  33. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  34. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  35. // CHECK:STDOUT: %Inner.elem: type = unbound_element_type %Inner, %i32 [concrete]
  36. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  37. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  38. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  39. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  40. // CHECK:STDOUT: %pattern_type.906: type = pattern_type %Inner [concrete]
  41. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  42. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  44. // CHECK:STDOUT: %pattern_type.e74: type = pattern_type %Outer [concrete]
  45. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  46. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  47. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  48. // CHECK:STDOUT: %Op.type.9bc: type = fn_type @Op.2, @Destroy.impl(%Inner) [concrete]
  49. // CHECK:STDOUT: %Op.754: %Op.type.9bc = struct_value () [concrete]
  50. // CHECK:STDOUT: %ptr.36a: type = ptr_type %Inner [concrete]
  51. // CHECK:STDOUT: %Op.specific_fn: <specific function> = specific_function %Op.754, @Op.2(%Inner) [concrete]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  56. // CHECK:STDOUT: .Int = %Core.Int
  57. // CHECK:STDOUT: .Destroy = %Core.Destroy
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/...
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  62. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: file {
  66. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  67. // CHECK:STDOUT: .Core = imports.%Core
  68. // CHECK:STDOUT: .Outer = %Outer.decl
  69. // CHECK:STDOUT: .F = %F.decl
  70. // CHECK:STDOUT: .G = %G.decl
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %Outer.decl: type = class_decl @Outer [concrete = constants.%Outer] {} {}
  74. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  75. // CHECK:STDOUT: %oi.patt: %pattern_type.906 = binding_pattern oi [concrete]
  76. // CHECK:STDOUT: %oi.param_patt: %pattern_type.906 = value_param_pattern %oi.patt, call_param0 [concrete]
  77. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  78. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  81. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  82. // CHECK:STDOUT: %oi.param: %Inner = value_param call_param0
  83. // CHECK:STDOUT: %.loc21: type = splice_block %Inner.ref [concrete = constants.%Inner] {
  84. // CHECK:STDOUT: %Outer.ref: type = name_ref Outer, file.%Outer.decl [concrete = constants.%Outer]
  85. // CHECK:STDOUT: %Inner.ref: type = name_ref Inner, @Outer.%Inner.decl [concrete = constants.%Inner]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %oi: %Inner = bind_name oi, %oi.param
  88. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  89. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  92. // CHECK:STDOUT: %o.patt: %pattern_type.e74 = binding_pattern o [concrete]
  93. // CHECK:STDOUT: %o.param_patt: %pattern_type.e74 = value_param_pattern %o.patt, call_param0 [concrete]
  94. // CHECK:STDOUT: } {
  95. // CHECK:STDOUT: %o.param: %Outer = value_param call_param0
  96. // CHECK:STDOUT: %Outer.ref: type = name_ref Outer, file.%Outer.decl [concrete = constants.%Outer]
  97. // CHECK:STDOUT: %o: %Outer = bind_name o, %o.param
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: class @Outer {
  102. // CHECK:STDOUT: %Inner.decl: type = class_decl @Inner [concrete = constants.%Inner] {} {}
  103. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  104. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  105. // CHECK:STDOUT: complete_type_witness = %complete_type
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !members:
  108. // CHECK:STDOUT: .Self = constants.%Outer
  109. // CHECK:STDOUT: .Inner = %Inner.decl
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: class @Inner {
  113. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  114. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  115. // CHECK:STDOUT: %.loc17: %Inner.elem = field_decl n, element0 [concrete]
  116. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete = constants.%struct_type.n]
  117. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  118. // CHECK:STDOUT: complete_type_witness = %complete_type
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: !members:
  121. // CHECK:STDOUT: .Self = constants.%Inner
  122. // CHECK:STDOUT: .n = %.loc17
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: fn @F(%oi.param: %Inner) -> %i32 {
  126. // CHECK:STDOUT: !entry:
  127. // CHECK:STDOUT: %oi.ref: %Inner = name_ref oi, %oi
  128. // CHECK:STDOUT: %n.ref: %Inner.elem = name_ref n, @Inner.%.loc17 [concrete = @Inner.%.loc17]
  129. // CHECK:STDOUT: %.loc22_12.1: ref %i32 = class_element_access %oi.ref, element0
  130. // CHECK:STDOUT: %.loc22_12.2: %i32 = bind_value %.loc22_12.1
  131. // CHECK:STDOUT: return %.loc22_12.2
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: fn @G(%o.param: %Outer) {
  135. // CHECK:STDOUT: !entry:
  136. // CHECK:STDOUT: name_binding_decl {
  137. // CHECK:STDOUT: %i.patt: %pattern_type.906 = binding_pattern i [concrete]
  138. // CHECK:STDOUT: %i.var_patt: %pattern_type.906 = var_pattern %i.patt [concrete]
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: %i.var: ref %Inner = var %i.var_patt
  141. // CHECK:STDOUT: %.loc26: type = splice_block %Inner.ref [concrete = constants.%Inner] {
  142. // CHECK:STDOUT: %o.ref: %Outer = name_ref o, %o
  143. // CHECK:STDOUT: %Inner.ref: type = name_ref Inner, @Outer.%Inner.decl [concrete = constants.%Inner]
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: %i: ref %Inner = bind_name i, %i.var
  146. // CHECK:STDOUT: %Op.bound: <bound method> = bound_method %i.var, constants.%Op.754
  147. // CHECK:STDOUT: %Op.specific_fn: <specific function> = specific_function constants.%Op.754, @Op.2(constants.%Inner) [concrete = constants.%Op.specific_fn]
  148. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %i.var, %Op.specific_fn
  149. // CHECK:STDOUT: %addr: %ptr.36a = addr_of %i.var
  150. // CHECK:STDOUT: %no_op: init %empty_tuple.type = call %bound_method(%addr)
  151. // CHECK:STDOUT: return
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: