Skip to content

Commit f3166b3

Browse files
authored
Merge pull request swiftlang#68672 from artemcm/NoInheritSearchPathsInSwift6
Do not inherit search paths from loaded binary Swift module dependencies in Swift 6
2 parents e15a7e9 + cc35289 commit f3166b3

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,10 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
271271
}
272272

273273
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
274-
if (SDKPath.empty() ||
275-
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
274+
// In Swift 6 mode, we do not inherit search paths from loaded non-SDK modules.
275+
if (!ctx.LangOpts.isSwiftVersionAtLeast(6) &&
276+
(SDKPath.empty() ||
277+
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath))) {
276278
for (const auto &searchPath : Core->SearchPaths) {
277279
ctx.addSearchPath(
278280
ctx.SearchPathOpts.SearchPathRemapper.remapPath(searchPath.Path),

test/Serialization/search-paths-relative.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// REQUIRES: asserts
12
// RUN: %empty-directory(%t)
23
// RUN: %empty-directory(%t/secret)
34
// RUN: %target-swift-frontend -emit-module -o %t/secret %S/Inputs/struct_with_operators.swift
@@ -7,6 +8,11 @@
78
// RUN: cd %t/secret && %target-swiftc_driver -emit-module -o %t/has_xref.swiftmodule -I . -F ../Frameworks -parse-as-library %S/Inputs/has_xref.swift %S/../Inputs/empty.swift -Xfrontend -serialize-debugging-options -Xcc -ivfsoverlay -Xcc %S/../Inputs/unextended-module-overlay.yaml -Xcc -DDUMMY
89
// RUN: %target-swift-frontend %s -typecheck -I %t
910

11+
// Ensure that in Swift 6 mode we do not read out search paths, thus are no longer able to
12+
// locate transitive dependencies with them
13+
// RUN: not %target-swift-frontend %s -typecheck -I %t -swift-version 6 &> %t/swift_6_output.txt
14+
// RUN: %FileCheck -check-prefix=SWIFT6 %s < %t/swift_6_output.txt
15+
1016
// Check the actual serialized search paths.
1117
// RUN: llvm-bcanalyzer -dump %t/has_xref.swiftmodule > %t/has_xref.swiftmodule.txt
1218
// RUN: %FileCheck %s < %t/has_xref.swiftmodule.txt
@@ -31,3 +37,5 @@ numeric(42)
3137
// NEGATIVE-NOT: '../Frameworks'
3238
// This should be filtered out.
3339
// NEGATIVE-NOT: -ivfsoverlay{{.*}}unextended-module-overlay.yaml
40+
41+
// SWIFT6: error: missing required modules: 'has_alias', 'struct_with_operators'

test/Serialization/search-paths-sdk.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// REQUIRES: VENDOR=apple
2+
// REQUIRES: asserts
23
// RUN: %empty-directory(%t)
34
// RUN: %empty-directory(%t/mock-sdk/usr/lib/swift/SystemLibrary.swiftmodule)
45
// RUN: %empty-directory(%t/secret)
@@ -9,6 +10,9 @@
910
// We pick up search paths from normal imports...
1011
// RUN: %target-swift-frontend -typecheck %s -I %t/mock-sdk/usr/lib/swift/
1112

13+
// We do not pick up search paths from any imports in Swift 6 mode
14+
// RUN: %target-swift-frontend -typecheck %s -I %t/mock-sdk/usr/lib/swift/ -verify -show-diagnostics-after-fatal -swift-version 6
15+
1216
// ...but not from content in the SDK.
1317
// RUN: %target-swift-frontend -typecheck %s -sdk %t/mock-sdk -verify -show-diagnostics-after-fatal
1418

0 commit comments

Comments
 (0)