Skip to content

Commit 011222d

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 011222d

File tree

2 files changed

+48
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)