// Part of the Carbon Language project, under the Apache License v2.0 with LLVM // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // AUTOUPDATE // TIP: To test this file alone, run: // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/namespace/merging_with_indirections.carbon // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/merging_with_indirections.carbon // --- a.carbon package Other library "[[@TEST_NAME]]"; namespace NS1; class NS1.A {} // --- b.carbon package Other library "[[@TEST_NAME]]"; import library "a"; namespace NS1; class NS1.B {} fn F() -> NS1.A { return {}; } // --- main.carbon import Other library "b"; import Other library "a"; fn Run() { // Note `Other.NS.A` is part of the return type here. Other.F(); // Use `Other.NS.A` directly. var a: Other.NS1.A; // Ensure the type is equivalent. a = Other.F(); } // CHECK:STDOUT: --- a.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %A: type = class_type @A [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .NS1 = %NS1 // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %NS1: = namespace [template] { // CHECK:STDOUT: .A = %A.decl // CHECK:STDOUT: } // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @A { // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template = constants.%complete_type] // CHECK:STDOUT: complete_type_witness = %complete_type // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = constants.%A // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- b.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %B: type = class_type @B [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: %A: type = class_type @A [template] // CHECK:STDOUT: %F.type: type = fn_type @F [template] // CHECK:STDOUT: %F: %F.type = struct_value () [template] // CHECK:STDOUT: %A.val: %A = struct_value () [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Other.NS1: = import_ref Other//a, NS1, loaded // CHECK:STDOUT: %NS1: = namespace %Other.NS1, [template] { // CHECK:STDOUT: .A = %Other.A // CHECK:STDOUT: .B = file.%B.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Other.A: type = import_ref Other//a, A, loaded [template = constants.%A] // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Other.import_ref.8f2: = import_ref Other//a, loc5_14, loaded [template = constants.%complete_type] // CHECK:STDOUT: %Other.import_ref.ca8 = import_ref Other//a, inst17 [no loc], unloaded // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .NS1 = imports.%NS1 // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .F = %F.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %default.import = import // CHECK:STDOUT: %NS1: = namespace [template] { // CHECK:STDOUT: .A = imports.%Other.A // CHECK:STDOUT: .B = %B.decl // CHECK:STDOUT: } // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {} // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] { // CHECK:STDOUT: %return.patt: %A = return_slot_pattern // CHECK:STDOUT: %return.param_patt: %A = out_param_pattern %return.patt, runtime_param0 // CHECK:STDOUT: } { // CHECK:STDOUT: %NS1.ref: = name_ref NS1, imports.%NS1 [template = imports.%NS1] // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%Other.A [template = constants.%A] // CHECK:STDOUT: %return.param: ref %A = out_param runtime_param0 // CHECK:STDOUT: %return: ref %A = return_slot %return.param // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @B { // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template = constants.%complete_type] // CHECK:STDOUT: complete_type_witness = %complete_type // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = constants.%B // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @A [from "a.carbon"] { // CHECK:STDOUT: complete_type_witness = imports.%Other.import_ref.8f2 // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = imports.%Other.import_ref.ca8 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @F() -> %return.param_patt: %A { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %.loc8_27.1: %empty_struct_type = struct_literal () // CHECK:STDOUT: %.loc8_27.2: init %A = class_init (), %return [template = constants.%A.val] // CHECK:STDOUT: %.loc8_28: init %A = converted %.loc8_27.1, %.loc8_27.2 [template = constants.%A.val] // CHECK:STDOUT: return %.loc8_28 to %return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- main.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %Run.type: type = fn_type @Run [template] // CHECK:STDOUT: %Run: %Run.type = struct_value () [template] // CHECK:STDOUT: %F.type: type = fn_type @F [template] // CHECK:STDOUT: %F: %F.type = struct_value () [template] // CHECK:STDOUT: %A: type = class_type @A [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Other: = namespace file.%Other.import, [template] { // CHECK:STDOUT: .F = %Other.F // CHECK:STDOUT: .NS1 = %NS1 // CHECK:STDOUT: import Other//b // CHECK:STDOUT: import Other//a // CHECK:STDOUT: } // CHECK:STDOUT: %Other.F: %F.type = import_ref Other//b, F, loaded [template = constants.%F] // CHECK:STDOUT: %Other.import_ref.8db: = import_ref Other//b, inst28 [indirect], loaded [template = constants.%complete_type] // CHECK:STDOUT: %Other.import_ref.bbd = import_ref Other//b, inst29 [indirect], unloaded // CHECK:STDOUT: %Other.NS1: = import_ref Other//b, NS1, loaded // CHECK:STDOUT: %NS1: = namespace %Other.NS1, [template] { // CHECK:STDOUT: .A = %Other.A // CHECK:STDOUT: import Other//b // CHECK:STDOUT: import Other//a // CHECK:STDOUT: } // CHECK:STDOUT: %Other.A: type = import_ref Other//a, A, loaded [template = constants.%A] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Other = imports.%Other // CHECK:STDOUT: .Run = %Run.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Other.import = import Other // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @A [from "b.carbon"] { // CHECK:STDOUT: complete_type_witness = imports.%Other.import_ref.8db // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = imports.%Other.import_ref.bbd // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @Run() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %Other.ref.loc7: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %F.ref.loc7: %F.type = name_ref F, imports.%Other.F [template = constants.%F] // CHECK:STDOUT: %.loc7_11.1: ref %A = temporary_storage // CHECK:STDOUT: %F.call.loc7: init %A = call %F.ref.loc7() to %.loc7_11.1 // CHECK:STDOUT: %.loc7_11.2: ref %A = temporary %.loc7_11.1, %F.call.loc7 // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %a.patt: %A = binding_pattern a // CHECK:STDOUT: %.loc10_3: %A = var_pattern %a.patt // CHECK:STDOUT: } // CHECK:STDOUT: %a.var: ref %A = var a // CHECK:STDOUT: %.loc10_19: type = splice_block %A.ref [template = constants.%A] { // CHECK:STDOUT: %Other.ref.loc10: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %NS1.ref: = name_ref NS1, imports.%NS1 [template = imports.%NS1] // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%Other.A [template = constants.%A] // CHECK:STDOUT: } // CHECK:STDOUT: %a: ref %A = bind_name a, %a.var // CHECK:STDOUT: %a.ref: ref %A = name_ref a, %a // CHECK:STDOUT: %Other.ref.loc13: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %F.ref.loc13: %F.type = name_ref F, imports.%Other.F [template = constants.%F] // CHECK:STDOUT: %.loc13: ref %A = splice_block %a.ref {} // CHECK:STDOUT: %F.call.loc13: init %A = call %F.ref.loc13() to %.loc13 // CHECK:STDOUT: assign %a.ref, %F.call.loc13 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @F() -> %A [from "b.carbon"]; // CHECK:STDOUT: