Skip to content

Conversation

@hnrklssn
Copy link
Member

@hnrklssn hnrklssn commented May 30, 2025

Since the _SwiftifyImport peer macro expansion reuses the function signature of the original imported function, it needs to import the same modules as the module where the original clang node resides, to ensure visibility of any symbols that may appear in the signature.

rdar://151611573

@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 4, 2025

@swift-ci please smoke test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DougGregor I don't fully get why only the module's imports that themselves are top-level modules show up in the dump. It seems to work regardless, but it seems a bit off. Do you know if this is intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat fixed by a568102
@bnbarham I think this affects IDE stuff, so I didn't dare make it actually print every module even though it would've been kinda nice if this reflected the full imports. Do you have more context for why this is the way it is?

@hnrklssn hnrklssn force-pushed the swiftify-inherit-imports branch from 7d2431e to e5c5c6e Compare June 4, 2025 04:35
@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 4, 2025

@swift-ci please smoke test

@hnrklssn hnrklssn force-pushed the swiftify-inherit-imports branch from e5c5c6e to 229280f Compare June 5, 2025 01:17
@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 5, 2025

@swift-ci please smoke test

@hnrklssn hnrklssn requested a review from CodaFi June 5, 2025 01:18
@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 5, 2025

@swift-ci please smoke test windows

@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 5, 2025

@swift-ci please smoke test

@hnrklssn hnrklssn force-pushed the swiftify-inherit-imports branch from 1b8ba84 to 7c794aa Compare June 7, 2025 21:56
@hnrklssn hnrklssn requested a review from xymus as a code owner June 7, 2025 21:56
@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 7, 2025

@swift-ci please smoke test macos

@hnrklssn hnrklssn force-pushed the swiftify-inherit-imports branch from 7c794aa to 726d7b3 Compare June 8, 2025 01:04
@hnrklssn
Copy link
Member Author

hnrklssn commented Jun 8, 2025

@swift-ci please smoke test macos

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

2 similar comments
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

This flag dumps all imports for each SourceFile after it's gone through
import resolution. It is only intended for testing purposes.
There are other ways to print imports, but they don't correspond 1:1 to
the imports actually resolved, which is a bit problematic when testing
implicit clang module imports.
This prints all imports instead of just exported imports, for testing
purposes.
The imported top-level module inherits the imports of all its
(transitive) submodules. Since multiple submodules can import the same
modules these need to be deduplicated to avoid redundant work.
Since only top-level Swift modules ever contain code, setting imports
for submodule wrappers has no effect.
Non-explicit submodules don't need to be explicitly added to the list of
imports to be visible, since their decls are implicitly exported. Skip
these modules even when present in the list of imports. Explicit
submodules are imported *regardless* of whether another module
imports them however.
Importing clang submodules results in an implicit import of the
top-level module as well. This can result in the same TLM being imported
many different times, if multiple submodules are imported from the same
module. This deduplicates these imports.

Other imports are not expected to be duplicated, so care is taken to
only deduplicate clang TLM imports.
Import resolution now adds the Swift module to the list of imports, so
we no longer need to add it manually.
There's only one caller to performImportResolutionForClangMacroBuffer,
which always passes a newly allocated SourceFile. This removes a
redundant check for whether its imports have been resolved, and instead
asserts that they haven't.
This fixes a few tests that were failing because scoped imports were
counted as having imported the module already, leading to later imports
of the same module being skipped. Since the scoped imports don't import
the full module, this would result in syntactically imported symbols not
being found by the compiler.
Contents in namespaces are imported to the bridging header module
`__ObjC`. When macros attached to a decl imported from a namespace are
expanded, they also end up in `__ObjC`. This prevents them from
inheriting imports from the module they originated in. This patch
implements a workaround by adding an alternative constructor to
`ImportResolver` that takes an explicit origin module as input,
overriding which module counts as the "parent" module.
A previous commit resulted in the swift interface for CxxStdlib
containing an `import CxxStdlib` for each submodule. This restores the
submodule names to `CxxStdlib.vector` etc.
libc++ v17-19 was split into multiple top-level modules, while versions
earlier and later had one TLM with submodules.
@hnrklssn hnrklssn force-pushed the swiftify-inherit-imports branch from c72dae7 to 0276feb Compare September 17, 2025 04:10
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test linux

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test linux macos

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

An assert checking the invariant of the module passed to
alreadyImportedTLM being a top-level module would dereference a null
pointer in the case where the clang module contained syntax errors,
since findUnderlyingClangModule would return null. Instead call the
bespoke isSubmodule function that already performs this null check.

This fixes the lldb test
lldb/test/API/lang/swift/clangimporter/expr_import/TestSwiftExprImport.py.
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn hnrklssn merged commit 7fcc72f into main Sep 20, 2025
3 checks passed
@hnrklssn hnrklssn deleted the swiftify-inherit-imports branch September 20, 2025 04:21
@AnthonyLatsis
Copy link
Collaborator

This seems to have broken rebranch: https://ci.swift.org/view/Swift%20rebranch/job/oss-swift-rebranch-incremental-RA-macos/7016. Confirming in #81190.

@AnthonyLatsis
Copy link
Collaborator

Confirmed reverting this PR makes the tests pass.

hnrklssn added a commit that referenced this pull request Sep 23, 2025
[Interop] Fix tests relying on transitive module imports (NFC)

This fixes test failures introduced by #81859

rdar://160994365
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.

5 participants