Skip to content

Commit c2836bf

Browse files
committed
[AST] Fix source module correction logic to support @_spiOnly imports
This logic may override the module considered as the source of a decl to ensure that only visible modules are printed in the swiftinterface. This change updates it to consider @_spiOnly imported modules from the local module as visible when printing the private swiftinterface only. rdar://103325332
1 parent e4310d7 commit c2836bf

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5851,6 +5851,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
58515851
// For the current module, consider both private and public imports.
58525852
ModuleDecl::ImportFilter Filter = ModuleDecl::ImportFilterKind::Exported;
58535853
Filter |= ModuleDecl::ImportFilterKind::Default;
5854+
5855+
// For private swiftinterfaces, also look through @_spiOnly imports.
5856+
if (Options.PrintSPIs)
5857+
Filter |= ModuleDecl::ImportFilterKind::SPIOnly;
5858+
58545859
SmallVector<ImportedModule, 4> Imports;
58555860
Options.CurrentModule->getImportedModules(Imports, Filter);
58565861

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/// Check that we correctly refer to @_spiOnly imported modules in the private
2+
/// swiftinterface and not to one of the redeclarations.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: split-file %s %t
6+
7+
// RUN: %target-swift-frontend -emit-module %t/Client.swift -I %t \
8+
// RUN: -enable-library-evolution -swift-version 5 \
9+
// RUN: -experimental-spi-only-imports \
10+
// RUN: -emit-module-interface-path %t/Client.swiftinterface \
11+
// RUN: -emit-private-module-interface-path %t/Client.private.swiftinterface
12+
13+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I %t
14+
15+
/// We print a reference to A in the private swiftinterface.
16+
// RUN: %FileCheck %s < %t/Client.private.swiftinterface
17+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) -I %t \
18+
// RUN: -module-name Client
19+
20+
//--- module.modulemap
21+
module A {
22+
header "A.h"
23+
}
24+
25+
module B {
26+
header "B.h"
27+
}
28+
29+
//--- A.h
30+
@interface MovingType
31+
@end
32+
33+
//--- B.h
34+
@class MovingType;
35+
36+
//--- Client.swift
37+
import B
38+
@_spiOnly import A
39+
40+
@_spi(_)
41+
public func foo(_ a: MovingType) {}
42+
// CHECK: A.MovingType

0 commit comments

Comments
 (0)