Skip to content

Commit 0692200

Browse files
authored
Merge pull request #2483 from xymus/access-level-imports-4
Update SE-0409 to reflect change in the expected Swift 6 behavior
2 parents a60ff28 + 81f7ffe commit 0692200

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

proposals/0409-access-level-on-imports.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public func publicFunc() -> DatabaseAdapter.Entry {...} // error: function canno
4646
```
4747

4848
Additionally, this proposal uses the access level declared on each import declaration in all source files composing a module to determine when clients of a library need to load the library's dependencies or when they can be skipped.
49-
To balance source compatibility and best practices, the proposed default import has an implicit access level of public in Swift 5 and of internal in Swift 6 mode.
49+
To balance source compatibility and best practices, an import without explicit access level has an implicit access level of `public` in Swift 5 and Swift 6. It will be `internal` in a future language mode.
5050
The attribute `@usableFromInline` on an import allows references from inlinable code.
5151

5252
## Detailed design
@@ -56,7 +56,7 @@ accept access-level modifiers on import declarations to declare the visibility o
5656
apply that information when type-checking the source file,
5757
and determine when indirect clients can skip loading transitive dependencies.
5858
We then cover other concerns addressed by this proposal:
59-
the different default access levels of imports in Swift 5 and Swift 6,
59+
the different default access levels of imports in different language modes,
6060
and the relationship with other attributes on imports.
6161

6262
### Declaring the access level of an imported module
@@ -105,6 +105,8 @@ It marks the dependency as visible to clients.
105105
@usableFromInline internal import UsableFromInlineInternalDependency
106106
```
107107

108+
*Note: Support for @usableFromInline on imports has yet to be implemented.*
109+
108110
### Type-checking references to imported modules
109111

110112
Current type-checking enforces that declaration respect their respective access levels.
@@ -202,36 +204,36 @@ Note that a dependency hidden on one import path may still need to be loaded bec
202204
The module interface associated with a hidden dependency doesn't need to be distributed to clients.
203205
However, the binary associated to the module still needs to be distributed to execute the resulting program.
204206

205-
### Default import access level in Swift 5 and Swift 6
207+
### Default import access level
206208

207209
The access level of a default import declaration without an explicit access-level modifier depends on the language version.
208210
We list here the implicit access levels and reasoning behind this choice.
209211

210-
In Swift 5, an import is `public` by default.
212+
In language modes up to Swift 6, an import is `public` by default.
211213
This choice preserves source compatibility.
212214
The only official import previously available in Swift 5 behaves like the public import proposed in this document.
213215

214-
In Swift 6 mode, an import is `internal` by default.
216+
In a future language mode, an import will be `internal` by default.
215217
This will align the behavior of imports with declarations where the implicit access level is internal.
216218
It should help limit unintentional dependency creep as marking a dependency public will require an explicit modifier.
217219

218-
As a result, the following import is `public` in Swift 5 and `internal` in Swift 6 mode:
220+
As a result, the following import is `public` in language modes up to Swift 6, but it will be `internal` in a future language mode:
219221
```swift
220222
import ADependency
221223
```
222224

223-
The Swift 6 change will likely break source compatibility for libraries.
225+
The future language change will likely require source changes in code that adopts the new language mode. It will not break source compatibility for code that remains on current language modes.
224226
A migration tool could automatically insert the `public` modifier where required.
225227
Where the tool is unavailable, a simple script can insert a `public` modifier in front of all imports to preserve the Swift 5 behavior.
226228

227-
The upcoming feature flag `InternalImportsByDefault` will enable the Swift 6 behavior even when using Swift 5.
229+
The upcoming feature flag `InternalImportsByDefault` will enable the future language behavior even when using Swift 5 or 6.
228230

229231
### Interactions with other modifiers on imports
230232

231233
The `@_exported` attribute is a step above a `public` import,
232234
as clients see the imported module declarations is if they were part of the local module.
233235
With this proposal, `@_exported` is accepted only on public import declarations,
234-
both with the modifier or the default public visibility in Swift 5 mode.
236+
both with the modifier or the default `public` visibility in current language modes.
235237

236238
The `@testable` attribute allows the local module to reference the internal declarations of the imported module.
237239
The current design even allows to use an imported internal or package type in a public declaration.
@@ -255,9 +257,9 @@ public import struct Foo.Bar
255257

256258
## Source compatibility
257259

258-
To preserve source compatibility, imports are public by default in Swift 5.
260+
To preserve source compatibility, imports are public by default in current language modes, including Swift 6.
259261
This will preserve the current behavior of imports in Swift 5.
260-
As discussed previously, the Swift 6 behavior changes the default value and will require code changes.
262+
As discussed previously, the future language mode behavior changes the default value and will require code changes.
261263

262264
## ABI compatibility
263265

0 commit comments

Comments
 (0)