Skip to content

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Oct 10, 2025

Update the logic finding the import to point to in diagnostics to avoid relying on the implicit import of the top-level module when importing a clang submodule. A recent change avoids duplicating the implicit imports and broke the old logic that would only match the top-level implicit import. Instead let's rely on the imports of the submodules.

rdar://162151660

@xymus xymus requested a review from hnrklssn October 10, 2025 21:50
@xymus
Copy link
Contributor Author

xymus commented Oct 10, 2025

@swift-ci Please smoke test

@hnrklssn
Copy link
Contributor

hnrklssn commented Oct 10, 2025

What happens if you have something like this, does the order matter then, or does it still find the correct submodule?

/--- Client_Clang_Submodules.swift

#if INVERT
private import ClangLib.Sub1
#endif

internal import ClangLib.Sub2

#if !INVERT
private import ClangLib.Sub1
#endif

public func dummyAPI(t2: SubType) {}

//--- module.modulemap

module ClangLib {
  header "ClangLib.h"

  explicit module Sub1 {
    header "Sub1.h"
  }

  explicit module Sub2 {
    header "Sub2.h"
  }
}

//--- ClangLib.h
struct ClangType {};

//--- Sub1.h
struct SubType {};

//--- Sub2.h
// no longer includes Sub1.h!

Just checking since now SubType is only accessible through the Sub1 import, but on the Swift side it's contained in ClangLib, which Sub2 also dumps its contents into.

Edit: also what about this case but with all imports being internal?

@xymus
Copy link
Contributor Author

xymus commented Oct 14, 2025

I would expect the same result even if it doesn't point to the right submodule (lookup wise). At this time access-level on imports looks at top-level modules only, so as far as it's concerned the different access-levels applied to submodules are transposed to the top module. This is something we may want to revisit in the future to properly track each submodule. We used to care more about the coarse grain dependencies but now we'd benefit from something more precise.

@xymus
Copy link
Contributor Author

xymus commented Oct 14, 2025

Updated the test for the newly required -verify-ignore-unrelated.

@swift-ci Please smoke test

Update logic finding the import to point in diagnostics to avoid relying
on the implicit import of the top-level module when importing a clang
submodule. A recent change avoids duplicating the implicit imports and
broke the old logic.

rdar://162151660
@xymus
Copy link
Contributor Author

xymus commented Oct 15, 2025

@swift-ci Please smoke test

@xymus xymus merged commit 5417f00 into swiftlang:main Oct 16, 2025
3 checks passed
@xymus xymus deleted the rdar162151660 branch October 16, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants