Skip to content

Commit 6b256f3

Browse files
authored
Adopt MemberImportVisibility (#8525)
Adopt the experimental feature MemberImportVisibility. ### Motivation: Due to a weakness in the existing Swift language implementation, a public extension declared in a library module can be accessible to source code that doesn’t directly import that module. ### Modifications: Adopt MemberImportVisibility on all targets and adjust imports to be explicit. There were a few places where ambiguities were exposed. The most apparent one is the ambiguity between Basics.AbsolutePath and TSCBasics.AbsolutePath. In this case they're functionally equivalent since the Basics version just type aliases the TSCBasics version. There were a few others where identically named methods were defined in both a SwiftPM module and an imported dependency. ### Result: SwiftPM compiles with no code included without a corresponding explicit import.
1 parent ffdc0c0 commit 6b256f3

File tree

126 files changed

+557
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+557
-352
lines changed

Package.swift

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ if let resourceDirPath = ProcessInfo.processInfo.environment["SWIFTCI_INSTALL_RP
3535
packageLibraryLinkSettings = []
3636
}
3737

38+
// Common experimental flags to be added to all targets.
39+
let commonExperimentalFeatures: [SwiftSetting] = [
40+
.enableExperimentalFeature("MemberImportVisibility"),
41+
]
42+
43+
// Certain targets fail to compile with MemberImportVisibility enabled on 6.0.3
44+
// but work with >=6.1. These targets opt in to using `swift6CompatibleExperimentalFeatures`.
45+
#if swift(>=6.1)
46+
let swift6CompatibleExperimentalFeatures = commonExperimentalFeatures
47+
#else
48+
let swift6CompatibleExperimentalFeatures: [SwiftSetting] = []
49+
#endif
50+
3851
/** SwiftPMDataModel is the subset of SwiftPM product that includes just its data model.
3952
This allows some clients (such as IDEs) that use SwiftPM's data model but not its build system
4053
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
@@ -152,7 +165,7 @@ let package = Package(
152165
.target(
153166
name: "PackageDescription",
154167
exclude: ["CMakeLists.txt"],
155-
swiftSettings: [
168+
swiftSettings: commonExperimentalFeatures + [
156169
.define("USE_IMPL_ONLY_IMPORTS"),
157170
.unsafeFlags(["-package-description-version", "999.0"]),
158171
.unsafeFlags(["-enable-library-evolution"]),
@@ -169,7 +182,7 @@ let package = Package(
169182
// AppleProductTypes library when they import it without further
170183
// messing with the manifest loader.
171184
dependencies: ["PackageDescription"],
172-
swiftSettings: [
185+
swiftSettings: commonExperimentalFeatures + [
173186
.unsafeFlags(["-package-description-version", "999.0"]),
174187
.unsafeFlags(["-enable-library-evolution"], .when(platforms: [.macOS])),
175188
.unsafeFlags(["-Xfrontend", "-module-link-name", "-Xfrontend", "AppleProductTypes"])
@@ -181,7 +194,7 @@ let package = Package(
181194
.target(
182195
name: "PackagePlugin",
183196
exclude: ["CMakeLists.txt"],
184-
swiftSettings: [
197+
swiftSettings: commonExperimentalFeatures + [
185198
.unsafeFlags(["-package-description-version", "999.0"]),
186199
.unsafeFlags(["-enable-library-evolution"]),
187200
],
@@ -199,7 +212,7 @@ let package = Package(
199212
"SPMBuildCore",
200213
],
201214
exclude: ["CMakeLists.txt"],
202-
swiftSettings: [
215+
swiftSettings: commonExperimentalFeatures + [
203216
.enableExperimentalFeature("AccessLevelOnImport"),
204217
.unsafeFlags(["-static"]),
205218
]
@@ -215,7 +228,7 @@ let package = Package(
215228
.product(name: "SystemPackage", package: "swift-system"),
216229
],
217230
exclude: ["CMakeLists.txt"],
218-
swiftSettings: [
231+
swiftSettings: commonExperimentalFeatures + [
219232
.enableExperimentalFeature("StrictConcurrency"),
220233
.enableExperimentalFeature("AccessLevelOnImport"),
221234
.enableExperimentalFeature("InternalImportsByDefault"),
@@ -235,7 +248,7 @@ let package = Package(
235248
.product(name: "SystemPackage", package: "swift-system"),
236249
],
237250
exclude: ["CMakeLists.txt", "Vendor/README.md"],
238-
swiftSettings: [
251+
swiftSettings: swift6CompatibleExperimentalFeatures + [
239252
.enableExperimentalFeature("StrictConcurrency"),
240253
.enableExperimentalFeature("AccessLevelOnImport"),
241254
.unsafeFlags(["-static"]),
@@ -247,7 +260,7 @@ let package = Package(
247260
name: "LLBuildManifest",
248261
dependencies: ["Basics"],
249262
exclude: ["CMakeLists.txt"],
250-
swiftSettings: [
263+
swiftSettings: commonExperimentalFeatures + [
251264
.unsafeFlags(["-static"]),
252265
]
253266
),
@@ -263,7 +276,7 @@ let package = Package(
263276
"PackageSigning",
264277
],
265278
exclude: ["CMakeLists.txt"],
266-
swiftSettings: [
279+
swiftSettings: commonExperimentalFeatures + [
267280
.unsafeFlags(["-static"]),
268281
]
269282
),
@@ -276,7 +289,7 @@ let package = Package(
276289
"PackageModel",
277290
],
278291
exclude: ["CMakeLists.txt"],
279-
swiftSettings: [
292+
swiftSettings: commonExperimentalFeatures + [
280293
.unsafeFlags(["-static"]),
281294
]
282295
),
@@ -286,7 +299,7 @@ let package = Package(
286299
name: "SPMLLBuild",
287300
dependencies: ["Basics"],
288301
exclude: ["CMakeLists.txt"],
289-
swiftSettings: [
302+
swiftSettings: commonExperimentalFeatures + [
290303
.unsafeFlags(["-static"]),
291304
]
292305
),
@@ -298,7 +311,7 @@ let package = Package(
298311
name: "PackageModel",
299312
dependencies: ["Basics"],
300313
exclude: ["CMakeLists.txt", "README.md"],
301-
swiftSettings: [
314+
swiftSettings: swift6CompatibleExperimentalFeatures + [
302315
.unsafeFlags(["-static"]),
303316
]
304317
),
@@ -312,7 +325,7 @@ let package = Package(
312325
"PackageModel",
313326
] + swiftSyntaxDependencies(["SwiftBasicFormat", "SwiftDiagnostics", "SwiftIDEUtils", "SwiftParser", "SwiftSyntax", "SwiftSyntaxBuilder"]),
314327
exclude: ["CMakeLists.txt"],
315-
swiftSettings: [
328+
swiftSettings: commonExperimentalFeatures + [
316329
.unsafeFlags(["-static"]),
317330
]
318331
),
@@ -326,7 +339,7 @@ let package = Package(
326339
"SourceControl",
327340
],
328341
exclude: ["CMakeLists.txt", "README.md"],
329-
swiftSettings: [
342+
swiftSettings: commonExperimentalFeatures + [
330343
.unsafeFlags(["-static"]),
331344
]
332345
),
@@ -343,7 +356,7 @@ let package = Package(
343356
.product(name: "OrderedCollections", package: "swift-collections"),
344357
],
345358
exclude: ["CMakeLists.txt", "README.md"],
346-
swiftSettings: [
359+
swiftSettings: commonExperimentalFeatures + [
347360
.unsafeFlags(["-static"]),
348361
]
349362
),
@@ -357,7 +370,7 @@ let package = Package(
357370
exclude: [
358371
"Formats/v1.md",
359372
],
360-
swiftSettings: [
373+
swiftSettings: commonExperimentalFeatures + [
361374
.unsafeFlags(["-static"]),
362375
]
363376
),
@@ -372,7 +385,7 @@ let package = Package(
372385
"PackageModel",
373386
"SourceControl",
374387
],
375-
swiftSettings: [
388+
swiftSettings: swift6CompatibleExperimentalFeatures + [
376389
.unsafeFlags(["-static"]),
377390
]
378391
),
@@ -385,7 +398,7 @@ let package = Package(
385398
"Basics",
386399
"PackageCollectionsModel",
387400
],
388-
swiftSettings: [
401+
swiftSettings: commonExperimentalFeatures + [
389402
.unsafeFlags(["-static"]),
390403
]
391404
),
@@ -397,7 +410,7 @@ let package = Package(
397410
"PackageModel",
398411
],
399412
exclude: ["CMakeLists.txt"],
400-
swiftSettings: [
413+
swiftSettings: commonExperimentalFeatures + [
401414
.unsafeFlags(["-static"]),
402415
]
403416
),
@@ -411,7 +424,7 @@ let package = Package(
411424
"PackageModel",
412425
],
413426
exclude: ["CMakeLists.txt"],
414-
swiftSettings: [
427+
swiftSettings: commonExperimentalFeatures + [
415428
.unsafeFlags(["-static"]),
416429
]
417430
),
@@ -427,7 +440,7 @@ let package = Package(
427440
.product(name: "OrderedCollections", package: "swift-collections"),
428441
],
429442
exclude: ["CMakeLists.txt"],
430-
swiftSettings: [
443+
swiftSettings: commonExperimentalFeatures + [
431444
.unsafeFlags(["-static"]),
432445
]
433446
),
@@ -445,7 +458,7 @@ let package = Package(
445458
"DriverSupport",
446459
],
447460
exclude: ["CMakeLists.txt"],
448-
swiftSettings: [
461+
swiftSettings: commonExperimentalFeatures + [
449462
.unsafeFlags(["-static"]),
450463
]
451464
),
@@ -457,7 +470,7 @@ let package = Package(
457470
.product(name: "SwiftDriver", package: "swift-driver"),
458471
],
459472
exclude: ["CMakeLists.txt"],
460-
swiftSettings: [
473+
swiftSettings: commonExperimentalFeatures + [
461474
.unsafeFlags(["-static"]),
462475
]
463476
),
@@ -470,7 +483,7 @@ let package = Package(
470483
.product(name: "OrderedCollections", package: "swift-collections"),
471484
],
472485
exclude: ["CMakeLists.txt"],
473-
swiftSettings: [
486+
swiftSettings: commonExperimentalFeatures + [
474487
.unsafeFlags(["-static"]),
475488
]
476489
),
@@ -480,7 +493,8 @@ let package = Package(
480493
"SPMBuildCore",
481494
"PackageGraph",
482495
],
483-
exclude: ["CMakeLists.txt", "README.md"]
496+
exclude: ["CMakeLists.txt", "README.md"],
497+
swiftSettings: commonExperimentalFeatures
484498
),
485499
.target(
486500
/** High level functionality */
@@ -497,7 +511,7 @@ let package = Package(
497511
.product(name: "OrderedCollections", package: "swift-collections"),
498512
],
499513
exclude: ["CMakeLists.txt"],
500-
swiftSettings: [
514+
swiftSettings: commonExperimentalFeatures + [
501515
.unsafeFlags(["-static"]),
502516
]
503517
),
@@ -511,7 +525,7 @@ let package = Package(
511525
"PackageRegistry",
512526
"PackageSigning",
513527
],
514-
swiftSettings: [
528+
swiftSettings: commonExperimentalFeatures + [
515529
.unsafeFlags(["-static"]),
516530
]
517531
),
@@ -533,7 +547,7 @@ let package = Package(
533547
"SwiftBuildSupport",
534548
],
535549
exclude: ["CMakeLists.txt"],
536-
swiftSettings: [
550+
swiftSettings: commonExperimentalFeatures + [
537551
.unsafeFlags(["-static"]),
538552
]
539553
),
@@ -555,7 +569,7 @@ let package = Package(
555569
"SwiftBuildSupport",
556570
] + swiftSyntaxDependencies(["SwiftIDEUtils"]),
557571
exclude: ["CMakeLists.txt", "README.md"],
558-
swiftSettings: [
572+
swiftSettings: swift6CompatibleExperimentalFeatures + [
559573
.unsafeFlags(["-static"]),
560574
]
561575
),
@@ -571,7 +585,7 @@ let package = Package(
571585
"PackageModel",
572586
],
573587
exclude: ["CMakeLists.txt", "README.md"],
574-
swiftSettings: [
588+
swiftSettings: commonExperimentalFeatures + [
575589
.unsafeFlags(["-static"]),
576590
]
577591
),
@@ -587,7 +601,7 @@ let package = Package(
587601
"PackageCollections",
588602
"PackageModel",
589603
],
590-
swiftSettings: [
604+
swiftSettings: commonExperimentalFeatures + [
591605
.unsafeFlags(["-static"]),
592606
]
593607
),
@@ -609,7 +623,7 @@ let package = Package(
609623
"SPMBuildCore",
610624
"Workspace",
611625
],
612-
swiftSettings: [
626+
swiftSettings: commonExperimentalFeatures + [
613627
.unsafeFlags(["-static"]),
614628
]
615629
),
@@ -717,7 +731,7 @@ let package = Package(
717731
name: "CompilerPluginSupport",
718732
dependencies: ["PackageDescription"],
719733
exclude: ["CMakeLists.txt"],
720-
swiftSettings: [
734+
swiftSettings: commonExperimentalFeatures + [
721735
.unsafeFlags(["-package-description-version", "999.0"]),
722736
.unsafeFlags(["-enable-library-evolution"]),
723737
]
@@ -840,7 +854,8 @@ let package = Package(
840854
),
841855
.testTarget(
842856
name: "PackageGraphTests",
843-
dependencies: ["PackageGraph", "_InternalTestSupport"]
857+
dependencies: ["PackageGraph", "_InternalTestSupport"],
858+
swiftSettings: commonExperimentalFeatures
844859
),
845860
.testTarget(
846861
name: "PackageGraphPerformanceTests",

Sources/Basics/AuthorizationProvider.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import TSCBasic
1314
import struct Foundation.Data
1415
import struct Foundation.Date
1516
import struct Foundation.URL

Sources/Basics/Collections/Dictionary+Extensions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import TSCBasic
14+
1315
extension Dictionary {
1416
@inlinable
1517
@discardableResult

Sources/Basics/ProgressAnimation/ThrottledProgressAnimation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import _Concurrency
14+
import TSCUtility
1415

1516
/// A progress animation wrapper that throttles updates to a given interval.
1617
final class ThrottledProgressAnimation: ProgressAnimationProtocol {

Sources/Basics/SQLite.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import TSCBasic
1314
import Foundation
1415

1516
#if SWIFT_PACKAGE && (os(Windows) || os(Android))

Sources/Basics/Triple+Basics.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import TSCUtility
1314
import enum TSCBasic.JSON
1415

1516
extension Triple {

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import PackageModel
1818

1919
import OrderedCollections
2020
import SPMBuildCore
21+
import TSCUtility
2122

2223
import struct TSCBasic.SortedArray
2324

@@ -434,7 +435,7 @@ extension SortedArray where Element == AbsolutePath {
434435
}
435436
}
436437

437-
extension Triple {
438+
extension Basics.Triple {
438439
var supportsFrameworks: Bool {
439440
return self.isDarwin()
440441
}

Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Basics
1515
import Foundation
1616
import PackageGraph
1717
import PackageLoading
18+
import TSCUtility
1819

1920
@_spi(SwiftPMInternal)
2021
import PackageModel

Sources/Build/BuildManifest/LLBuildManifestBuilder+Clang.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import struct Basics.InternalError
1616
import class Basics.ObservabilityScope
1717
import struct PackageGraph.ResolvedModule
1818
import PackageModel
19+
import SPMBuildCore
1920

2021
extension LLBuildManifestBuilder {
2122
/// Create a llbuild target for a Clang target description.

0 commit comments

Comments
 (0)