Skip to content

Conversation

@hnrklssn
Copy link
Member

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 ImportDecls. 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

Extracted from #84642

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

fix non-fatal import error
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn hnrklssn mentioned this pull request Oct 15, 2025
@hnrklssn
Copy link
Member Author

ping @egorzhdan

@hnrklssn
Copy link
Member Author

ping @egorzhdan @j-hui

@hnrklssn hnrklssn merged commit 87af553 into swiftlang:main Oct 31, 2025
3 checks passed
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