You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/0409-access-level-on-imports.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ public func publicFunc() -> DatabaseAdapter.Entry {...} // error: function canno
46
46
```
47
47
48
48
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.
50
50
The attribute `@usableFromInline` on an import allows references from inlinable code.
51
51
52
52
## Detailed design
@@ -56,7 +56,7 @@ accept access-level modifiers on import declarations to declare the visibility o
56
56
apply that information when type-checking the source file,
57
57
and determine when indirect clients can skip loading transitive dependencies.
58
58
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,
60
60
and the relationship with other attributes on imports.
61
61
62
62
### Declaring the access level of an imported module
@@ -105,6 +105,8 @@ It marks the dependency as visible to clients.
*Note: Support for @usableFromInline on imports has yet to be implemented.*
109
+
108
110
### Type-checking references to imported modules
109
111
110
112
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
202
204
The module interface associated with a hidden dependency doesn't need to be distributed to clients.
203
205
However, the binary associated to the module still needs to be distributed to execute the resulting program.
204
206
205
-
### Default import access level in Swift 5 and Swift 6
207
+
### Default import access level
206
208
207
209
The access level of a default import declaration without an explicit access-level modifier depends on the language version.
208
210
We list here the implicit access levels and reasoning behind this choice.
209
211
210
-
In Swift 5, an import is `public` by default.
212
+
In language modes up to Swift 6, an import is `public` by default.
211
213
This choice preserves source compatibility.
212
214
The only official import previously available in Swift 5 behaves like the public import proposed in this document.
213
215
214
-
In Swift 6 mode, an import is`internal` by default.
216
+
In a future language mode, an import will be`internal` by default.
215
217
This will align the behavior of imports with declarations where the implicit access level is internal.
216
218
It should help limit unintentional dependency creep as marking a dependency public will require an explicit modifier.
217
219
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:
219
221
```swift
220
222
importADependency
221
223
```
222
224
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.
224
226
A migration tool could automatically insert the `public` modifier where required.
225
227
Where the tool is unavailable, a simple script can insert a `public` modifier in front of all imports to preserve the Swift 5 behavior.
226
228
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.
228
230
229
231
### Interactions with other modifiers on imports
230
232
231
233
The `@_exported` attribute is a step above a `public` import,
232
234
as clients see the imported module declarations is if they were part of the local module.
233
235
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.
235
237
236
238
The `@testable` attribute allows the local module to reference the internal declarations of the imported module.
237
239
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
255
257
256
258
## Source compatibility
257
259
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.
259
261
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.
0 commit comments