Skip to content

Commit be34921

Browse files
authored
Merge pull request #67970 from xymus/spi-only-printer
[AST] Update source module correction logic to support @_spiOnly imports
2 parents 39a47a0 + 011222d commit be34921

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
@@ -5842,6 +5842,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
58425842
// For the current module, consider both private and public imports.
58435843
ModuleDecl::ImportFilter Filter = ModuleDecl::ImportFilterKind::Exported;
58445844
Filter |= ModuleDecl::ImportFilterKind::Default;
5845+
5846+
// For private swiftinterfaces, also look through @_spiOnly imports.
5847+
if (Options.PrintSPIs)
5848+
Filter |= ModuleDecl::ImportFilterKind::SPIOnly;
5849+
58455850
SmallVector<ImportedModule, 4> Imports;
58465851
Options.CurrentModule->getImportedModules(Imports, Filter);
58475852

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)