Skip to content

Conversation

hnrklssn
Copy link
Contributor

@hnrklssn hnrklssn commented Oct 2, 2025

This fixes some bugs related to implicitly inherited imports that block enabling safe interop wrappers by default.

rdar://161795145
rdar://161795429
rdar://161795673
rdar://161795793

@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 2, 2025

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 2, 2025

@swift-ci please smoke test

ImportPath::Builder builder;
while (M) {
if (!M->isSubModule() && isCxxStdModule(M))
if (!M->isSubModule() && M->Name == "std")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this still accept std_core, which acts as a top-level module in recent libc++?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is specifically done to exclude top-level libc++ modules other than std. The issue is that while you could specify submodules to CxxStdlib, there was no way to inherit imports to other libc++ submodules. E.g. a clang module importing std_core.math.abs would become an import of CxxStdlib.math.abs on the Swift side, which would then be translated back to std.math.abs (which doesn't exist) when looking up the module.

@hnrklssn hnrklssn force-pushed the implicit-import-fixes branch from 77e67bf to 25b189d Compare October 2, 2025 22:59
@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 2, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 6, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 7, 2025

@swift-ci please smoke test

@hnrklssn hnrklssn force-pushed the implicit-import-fixes branch from 52a3df3 to 851d5cc Compare October 7, 2025 05:13
@hnrklssn hnrklssn force-pushed the implicit-import-fixes branch from 9c1a8a9 to 58ca618 Compare October 7, 2025 06:13
@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 7, 2025

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 8, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented Oct 8, 2025

This is finally ready for review now

Inheriting a clang import marked `requires: !swift` will always result
in an error. This skips such imports, which *may* result in name lookup
errors instead, but also may not, depending on the module.

rdar://161795145
When expanding a Swift macro in a clang module where the original clang
module imported a submodule in a C++ standard library module other than
`std`, e.g. a submodule to `std_core`, this would result in an error.
This is because `std_core.math.abs` would be imported as
`CxxStdlib.math.abs`, which would later be translated back as
`std.math.abs` which doesn’t exist.

This changes the mapping to only map `std` to `CxxStdlib`. To prevent
errors when importing modules starting with `std_`, this error is moved
from the late-stage module import to the earlier processing of
`ImportDecl`s. This results in these module names still being forbidden
in explicit imports (i.e. naming them in source code), while still being
allowed in implicit imports inherited from clang modules.

This also fixes a fix-it bug where only the first 3 characters would be
selected for replacing with `CxxStdlib` when importing `std_core`.

This also fixes a diagnostic bug where aliased modules would refer to
the module name in the source code rather than the real module name, and
adds a note clarifying the situation.

rdar://161795429
rdar://161795673
rdar://161795793
The _SwiftifyImport macro is emitted into an unnamed buffer and then
parsed, pretending it was in the header all along. This makes it hard to
add `expected-note` comments for `diag::in_macro_expansion` when they
point here. That's okay, because the macro expansion has already been
pointed out by `expected-expansion` directives. But
-verify-ignore-unrelated is too blunt of a tool, so this adds
-verify-ignore-macro-note to ignore these specific diagnostics.
@hnrklssn hnrklssn force-pushed the implicit-import-fixes branch from 7656009 to 6ebb5e4 Compare October 11, 2025 01:50
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

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.

3 participants