swift-index-store icon indicating copy to clipboard operation
swift-index-store copied to clipboard

Does unused imports support `@_exported`?

Open josh-arnold-1 opened this issue 7 months ago • 1 comments

Hello,

How hard would it be for this unused imports script to support the usage of @_exported?

For example, say I have a module X that does this:

// My custom module `X`

@_exported import SwiftUI

Then in some other module, Y, we reference the exported module, but no symbols in the actual module `X:

// Inside module `Y`

import X

print(String(describing: Text("Hello world")) // usage of SwiftUI, but no usage of module `X` symbols

Would the unused imports job remove import X because it thinks its "unused", when in reality, its exported symbols/module is still referenced, therefore it shouldn't be removed?

https://github.com/MobileNativeFoundation/swift-index-store/blob/9cd7ac98b5fdc8d13b322a0d2053be34a69f6789/Sources/unused-imports/main.swift#L26

Any help or guidance would be greatly appreciated, thanks!

josh-arnold-1 avatar May 30 '25 13:05 josh-arnold-1

i looked at this at one point a few years ago but don't really recall where i ended up. we weren't using those heavily at the time so we mostly sidestepped this issue. i imagine it is possible to do by keeping the list of exported imports in some sort of graph (im not sure how transitive exported imports work) and cross checking those

keith avatar Jun 05 '25 17:06 keith