# SE-0444: Member import visibility

**URL:** <https://forums.swift.org/t/se-0444-member-import-visibility/74519>\
**Category:** Proposal Reviews\
**Tags:** module, import\
**Created:** [September 11, 2024, 4:37pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519 "2024-09-11T16:37:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![beccadax](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/beccadax/32/34217_2.png) [@beccadax](https://forums.swift.org/u/beccadax)\
**Post date:** [September 11, 2024, 4:37pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/1 "2024-09-11T16:37:29Z")

</div>

Hello Swift community,

The review of "Member import visibility" begins now and runs through September 23, 2024. The proposal is available here:

> [https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md)

Reviews are an important part of the Swift evolution process. All review feedback should be either on this forum thread or, if you would like to keep your feedback private, directly to the review manager by [email](mailto:beccadax@apple.com). When emailing the review manager directly, please include "SE-0444" in the subject line.

##### Trying it out

If you'd like to try this proposal out, you can [download a toolchain supporting it here](https://www.swift.org/download/#trunk-development-main). Any trunk development snapshot dated September 6, 2024 or later should do (newer snapshots may include diagnostic improvements). You will need to add `-enable-experimental-feature MemberImportVisibility` to your build flags.

##### What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

- What is your evaluation of the proposal?
- Is the problem being addressed significant enough to warrant a change to Swift?
- Does this proposal fit well with the feel and direction of Swift?
- If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
- How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

> [swift-evolution/process.md at main · apple/swift-evolution · GitHub](https://github.com/apple/swift-evolution/blob/main/process.md)

Happy reviewing,

—Becca Royal-Gordon  
SE-0444 Review Manager

---

<div class="post-metadata">

**Author:** ![Joseph\_Heck](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joseph_heck/32/22369_2.png) [@Joseph\_Heck](https://forums.swift.org/u/Joseph_Heck)\
**Post date:** [September 11, 2024, 5:09pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/2 "2024-09-11T17:09:10Z")

</div>

+1

While I haven't hit this particular confusing scenario often, I have stumbled through it a couple of times.

I think the change is useful enough to be accepted, especially with the fixit to help guide those cases where you might have been relying on a transitive import that would no longer fully compile.

I've not used this specific toolchain and tried out the proposed feature, only read through the proposal.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [September 11, 2024, 5:43pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/3 "2024-09-11T17:43:38Z")

</div>

Resounding +1.

We've invested in building tools that help users manage their imports based on what they use in their sources (à la include-what-you-use, but for Swift), and the leakiness of extensions has caused no end of special cases that we have to consider.

The proposed lookup rules are predictable and make sense. They will require users to write more `import`s than they otherwise have to today (and thus will require some migration when the feature is enabled), but that's a feature and not a bug: developers should always be aware of what they're pulling into their compilation units instead of accidentally relying on spooky-imports-at-a-distance.

---

<div class="post-metadata">

**Author:** ![rockbruno](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rockbruno/32/41051_2.png) [@rockbruno](https://forums.swift.org/u/rockbruno)\
**Post date:** [September 11, 2024, 5:44pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/4 "2024-09-11T17:44:39Z")

</div>

+1

The current "leaky" behavior is confusing and should be changed. Additionally, doing so will finally open the door for tooling / compiler features that are able to detect unused dependencies in Swift, which is something that historically couldn't be done because of the issue that this proposal addresses.

---

<div class="post-metadata">

**Author:** ![Lancelotbronner](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancelotbronner/32/22071_2.png) [@Lancelotbronner](https://forums.swift.org/u/Lancelotbronner)\
**Post date:** [September 11, 2024, 5:57pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/5 "2024-09-11T17:57:42Z")

</div>

Absolute +1.

I've encountered this many times and adjusted my entire coding style to avoid this issue. Thinking of the legacy projects I've worked on, it'll also help know if a dependency is actually used by just searching `import <Dependency>` without getting as many false negatives!

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [September 11, 2024, 8:06pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/6 "2024-09-11T20:06:55Z")

</div>

I have a background question. Let’s say framework Foo imports framework Bar. What controls whether Foo.framework emits an “autolink Bar” symbol—does this only happen if some source file in Foo contains `@exported import Foo`? And does the compiler require an `@exported import` in the same source file that uses any of Bar’s types as part of Foo’s public API? Does that depend on language mode?

---

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [September 11, 2024, 8:32pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/7 "2024-09-11T20:32:02Z")

</div>

LGTM! Would there be any edge-casey stuff to defend against once we enable the changes from [SE-0409](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md) as default (which I believe was originally planned for 6.0 but then pushed back to 6.1+)?

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [September 12, 2024, 12:08am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/8 "2024-09-12T00:08:51Z")

</div>

> [@vanvoorden](#):
>
> Would there be any edge-casey stuff to defend against once we enable the changes from [SE-0409](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md) as default

SE-0409 encourages library authors to reduce the transitive dependencies they expose to clients of their libraries (by requiring that exposed imports be explicitly marked `public`). This proposal, on the other hand, requires in more cases that clients explicitly import the dependencies that they use. Both proposals are tackling the general problem of predictable dependencies in Swift but from different angles.

I think the interaction between the proposals is generally positive, since clients directly importing the dependencies they need means that the act of removing some public dependency from a library will not be as likely to be source breaking for the clients. I haven't been able to come up with any more interesting interactions that feel relevant.

---

<div class="post-metadata">

**Author:** ![ArtemC](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/artemc/32/27369_2.png) [@ArtemC](https://forums.swift.org/u/ArtemC)\
**Post date:** [September 13, 2024, 4:09pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/9 "2024-09-13T16:09:17Z")

</div>

> [@ksluder](#):
>
> Let’s say framework Foo imports framework Bar. What controls whether Foo.framework emits an “autolink Bar” symbol—does this only happen if some source file in Foo contains `@exported import Foo`? And does the compiler require an `@exported import` in the same source file that uses any of Bar’s types as part of Foo’s public API? Does that depend on language mode?

All imported framework modules that are not `@_implementationOnly` or `internal` or `package` or `@_spiOnly`, direct and transitive, result in the compiler inserting an autolink load command, without a need for `@exported`. And this does not depend on the language mode.

One thing worth noting though is that, on Darwin, if the linker is unable to resolve to autolink load command, that alone will not constitute a link failure if all symbols are otherwise successfully resolved.

---

<div class="post-metadata">

**Author:** ![owenv](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/owenv/32/6137_2.png) [@owenv](https://forums.swift.org/u/owenv)\
**Post date:** [September 18, 2024, 12:18am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/10 "2024-09-18T00:18:41Z")

</div>

Strong +1

This proposal will go a long way towards avoiding the introduction of unexpected module dependencies in large code bases, and the resulting name lookup rules are far easier for users to reason about. The proposed diagnostics for name lookup failures should also allow for relatively easy incremental adoption.

---

<div class="post-metadata">

**Author:** ![benpious](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/benpious/32/17944_2.png) [@benpious](https://forums.swift.org/u/benpious)\
**Post date:** [September 18, 2024, 2:25am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/11 "2024-09-18T02:25:59Z")

</div>

Will static members like typealiases be subject to the same rules? For example:

```swift
import SwiftUI

extension View {

     typealias Text = CursedText 

}

```

---

<div class="post-metadata">

**Author:** ![Nobody1707](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nobody1707/32/2169_2.png) [@Nobody1707](https://forums.swift.org/u/Nobody1707)\
**Post date:** [September 18, 2024, 2:49am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/12 "2024-09-18T02:49:06Z")

</div>

Strong +1 This is really how imports should have worked from the beginning.

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [September 18, 2024, 3:58am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/13 "2024-09-18T03:58:36Z")

</div>

> [@benpious](#):
>
> Will static members like typealiases be subject to the same rules?

Yes, the proposal would affect lookup of member declarations in general. The new behavior applies equally to static and instance members. It also applies equally to all kinds of member declarations (functions, types, typealiases, etc.).

---

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [September 18, 2024, 9:16am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/14 "2024-09-18T09:16:21Z")

</div>

+1. Really looking forward to this feature. If this is approved and landed are we aware of any other outstanding hole where types/members can be used without having an appropriate import or is this the last hole that needs closing?

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [September 18, 2024, 4:38pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/15 "2024-09-18T16:38:49Z")

</div>

Yes. Retroactive conformances and operator declarations (also precedence groups?), at a minimum.

On that note, I was under the impression that this proposal _would_ cover operator function _implementations_ declared as static members, but the text does not spell that out and seems to hedge on what the behavior actually will be.

IMO, this proposal needs to either spell out that it doesn’t change the status quo in that respect, or that it does (in which case, it should work just as any other static member does), but it shouldn’t leave the effect of this proposal on a subset of static members just unspecified.

---

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [September 18, 2024, 5:25pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/16 "2024-09-18T17:25:07Z")

</div>

> [@xwu](#):
>
> Yes. Retroactive conformances and operator declarations (also precedence groups?), at a minimum.

I see. Do we have GitHub issues tracking those gaps?

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [September 19, 2024, 2:07am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/17 "2024-09-19T02:07:33Z")

</div>

> [@FranzBusch](#):
>
> If this is approved and landed are we aware of any other outstanding hole where types/members can be used without having an appropriate import or is this the last hole that needs closing?

Even in a language mode that has this proposal there are still a number of ways for a source file to have module dependencies that are unacknowledged by `import` statements. This is not an exhaustive list, but here are a few examples of how it can happen:

### Conformances

A conformance may be used without importing the module that defines the conformance:

```swift
// 'Far' module

// Do NOT copy this retroactive conformance into library code!
extension String: @retroactive Error {}

```

```swift
// 'Near' module
import Far

```

```swift
// Client
import Near

func f() throws {
  // Uses the conformance from 'Far'
  throw "Implicit use of Far's conformance of String to Error"
}

```

Conformances aren't subject to name lookup rules since you don't "name" a conformance at its point of use in Swift. The proposal mentions this in _Future directions_, specifically with respect to retroactive conformances since they create the potential for ambiguity (when the compiler can see multiple conformance declarations it's not defined how it should pick the one to use). However, it's also worth clarifying that even non-retroactive conformances can be used in a source file without explicitly importing the module that defines the conformance.

### Clang re-exports

As mentioned in the proposal, it is conventional for Clang modules to use `export *`, which has the effect of re-exporting every module that is imported by the Clang module. As a concrete example of how this can result in surprising dependencies, take this program which may be compiled successfully against Apple's SDKs:

```swift
import SwiftUI

let _ = AttributedString("...")

```

`AttributedString` comes from `Foundation`, which isn't imported in this file. SwiftUI also does not directly re-export `Foundation`. However, it does re-export a couple of other modules, which happen to transitively export some Clang modules from the SDK. Those Clang modules ultimately import Foundation and bunch of other Clang modules, and since most of the Clang modules have `export *`, the set of modules visible to name lookup becomes quite large (I counted a total of 38 visible modules from a single `import SwiftUI` when testing this using the macOS SDK shipped with Xcode 15.4).

Strictly speaking, this is all expected behavior according to the rules of re-exports, but it doesn't really feel that intentionally designed to me.

### Compiler inserted calls to value witnesses

Consider the following example, where a client program uses the APIs of an imported module to work with types from a transitively imported module:

```swift
// 'Far' module
public struct Foo {}

```

```swift
// 'Near' module
import Far

public func returnsFoo() -> Foo
public func consumesFoo(_ x: consuming Foo)

```

```swift
// Client
import Near

let x = returnsFoo()
consumesFoo(x) // semantically copies 'x'
consumesFoo(x)

```

Since type inference allows us to avoid naming `Foo` anywhere in the client source file, the compiler does not require the `Far` module to be imported. However, the code generated for the program will contain references to symbols from the `Far` library. In this specific example, the copy value witness for `Foo` would be implicitly called to satisfy the lifetime requirements for the value `x`.

---

<div class="post-metadata">

**Author:** ![maartene](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maartene/32/42076_2.png) [@maartene](https://forums.swift.org/u/maartene)\
**Post date:** [September 19, 2024, 9:00am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/18 "2024-09-19T09:00:12Z")

</div>

+1  
although I haven't encountered this very often (which in a sense actually makes it worse) it really trips you up. Being explicit is the better solution.

Does it fit well with Swift?  
I believe it does. Even if its a code breaking change, I choose being explicit over something that "typically works, until it doesnt".

---

<div class="post-metadata">

**Author:** ![FxFactory](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fxfactory/32/21398_2.png) [@FxFactory](https://forums.swift.org/u/FxFactory)\
**Post date:** [September 19, 2024, 11:32am UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/19 "2024-09-19T11:32:12Z")

</div>

+1 but if this is the first time Swift is borrowing namespace syntax from C++, why not borrow from its key path syntax instead: `"Hello"\RecipeKit.parse()`. The backslash in Swift could become synonym for identifying something within the scope of something else (in this case, a Module). And in places where the backslash is already used, you’d be able to say `\Module.Type.element`, if that makes sense.

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [September 19, 2024, 3:43pm UTC](https://forums.swift.org/t/se-0444-member-import-visibility/74519/20 "2024-09-19T15:43:33Z")

</div>

> [@xwu](#):
>
> On that note, I was under the impression that this proposal _would_ cover operator function _implementations_ declared as static members, but the text does not spell that out and seems to hedge on what the behavior actually will be.

Operator lookup is implemented using a distinct algorithm, separate from member lookup and top-level name lookup. My tests for the implementation of `MemberImportVisibility` indicate that the leaky visibility problem doesn't apply to operators declared as members. An operator declared as a member in a transitively imported module doesn't appear to be considered a candidate. I can amend the proposal to clarify that it doesn't apply to operators.

[Next page](https://forums.swift.org/t/se-0444-member-import-visibility/74519.md?page=2)
