Skip to content

Commit dd32f7f

Browse files
authored
Merge pull request #82081 from tshortli/implementation-only-deprecation-diagnostic-group-6.2
[6.2] AST: Add a warning group for `@_implementationOnly` deprecation diagnostics
2 parents 3a0f890 + 464c37a commit dd32f7f

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

include/swift/AST/DiagnosticGroups.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ GROUP(DynamicCallable, "dynamic-callable-requirements")
4848
GROUP(ErrorInFutureSwiftVersion, "error-in-future-swift-version")
4949
GROUP(ExistentialAny, "existential-any")
5050
GROUP(ExistentialMemberAccess, "existential-member-access-limitations")
51+
GROUP(ImplementationOnlyDeprecated, "implementation-only-deprecated")
5152
GROUP(IsolatedConformances, "isolated-conformances")
5253
GROUP(MemberImportVisibility, "member-import-visibility")
5354
GROUP(MissingModuleOnKnownPaths, "missing-module-on-known-paths")

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,11 +1220,13 @@ ERROR(module_not_compiled_with_library_evolution,none,
12201220
"module %0 was not compiled with library evolution support; "
12211221
"using it means binary compatibility for %1 can't be guaranteed",
12221222
(Identifier, Identifier))
1223-
WARNING(implementation_only_requires_library_evolution,none,
1223+
GROUPED_WARNING(implementation_only_requires_library_evolution,
1224+
ImplementationOnlyDeprecated,none,
12241225
"using '@_implementationOnly' without enabling library evolution "
12251226
"for %0 may lead to instability during execution",
12261227
(Identifier))
1227-
WARNING(implementation_only_deprecated,none,
1228+
GROUPED_WARNING(implementation_only_deprecated,
1229+
ImplementationOnlyDeprecated,none,
12281230
"'@_implementationOnly' is deprecated, use 'internal import' instead",
12291231
())
12301232

test/Sema/implementation-only-deprecated.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
// RUN: -enable-library-evolution -swift-version 5 \
1212
// RUN: -enable-upcoming-feature InternalImportsByDefault \
1313
// RUN: -verify
14+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
15+
// RUN: -enable-library-evolution -swift-version 5 \
16+
// RUN: -enable-upcoming-feature InternalImportsByDefault \
17+
// RUN: -warnings-as-errors -Wwarning ImplementationOnlyDeprecated \
18+
// RUN: -verify
19+
1420

1521
// REQUIRES: swift_feature_InternalImportsByDefault
1622

test/Sema/implementation-only-import-from-non-resilient.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
/// Build a client with and without library-evolution.
1111
// RUN: %target-swift-frontend -typecheck %t/client-non-resilient.swift -I %t -verify
12+
// RUN: %target-swift-frontend -typecheck %t/client-non-resilient.swift -I %t -verify \
13+
// RUN: -warnings-as-errors -Wwarning ImplementationOnlyDeprecated
1214
// RUN: %target-swift-frontend -typecheck %t/client-resilient.swift -I %t -verify \
1315
// RUN: -enable-library-evolution -swift-version 5
1416

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Deprecated implementation-only imports (ImplementationOnlyDeprecated)
2+
3+
Warnings that identify `import` declarations with the `@_implementationOnly` attribute.
4+
5+
## Overview
6+
7+
When applied to `import` declarations, the compiler-internal attribute `@_implementationOnly` attempts prevents declarations from the imported module from being exposed in the ABI or public interface of the dependent module. This attribute became deprecated when support for access levels on `import` declarations was introduced with [SE-0409].
8+
9+
One reason `@_implementationOnly import` is deprecated is that it is unsafe when used in modules that are built _without_ [library evolution] enabled. For example, suppose the following code were part of a library named `Foo`:
10+
11+
```swift
12+
// Library `Foo`
13+
@_implementationOnly import ImplementationDetail
14+
15+
public struct Bar {
16+
internal var x: Baz // defined in ImplementationDetail
17+
}
18+
```
19+
20+
If `Foo` is not compiled with library evolution, then the memory layout of values of `Bar` must be known at compile time in clients of `Foo`. However, the `@_implementationOnly import` of `ImplementationDetail` prevents clients from being able to look up `Baz` which is a type that contributes to the layout of `Foo`. As a result, the layout of `Foo` will be miscalculated resulting in undefined behavior.
21+
22+
[SE-0409]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
23+
[library evolution]: https://www.swift.org/blog/library-evolution/

0 commit comments

Comments
 (0)