Skip to content

[Swiftify] enable safe wrappers for std::span without typedef#88621

Open
hnrklssn wants to merge 4 commits intoswiftlang:mainfrom
hnrklssn:swiftify-span-typedefless
Open

[Swiftify] enable safe wrappers for std::span without typedef#88621
hnrklssn wants to merge 4 commits intoswiftlang:mainfrom
hnrklssn:swiftify-span-typedefless

Conversation

@hnrklssn
Copy link
Copy Markdown
Member

  • Explanation:
    We previously prevented generating safe wrappers on functions with
    template instantiations in the signature, unless those instantiations
    were hidden behind a typedef. This is because those template
    instantiations cannot be expressed in Swift syntax, so the macro
    would expand to a function with invalid syntax.

For the std::span parameter itself however, that type is replaced with a
Swift Span in the safe wrapper, so it's not an issue in the type
signature. We would previously use the std::span type name from the
original signature to cast from Span to std::span, which does not work
with the raw std::span type. This uses .init instead when this is the
case, which avoids spelling out the type. When possible, we still use
the concrete type name, for clarity and by providing information we have
accessible the typechecker needs to do less work.

  • Scope:
    This expands the scope of safe interop wrappers a bit: previously it was limited to std::span parameters where the type was hidden behind a typedef, which people don't typically do unless to deliberately support Swift interop. This is no longer needed. However the parameter still needs a __noescape annotation, which is also not very widespread outside of Swift interop, since upstream currently Clang emits an error for __noescape on std::span. But __noescape is expected to see more widespread use in the future, and we are working with upstream Clang to support it on std::span, so it'll be more realistic for future code that didn't intentionally go out of its way to support safe Swift interop to end up with safe wrappers.
  • Issues:
    rdar://167712240
    C++ Interop should not require "type alias"es for std::span <-> Span conversions #86339
  • Risk:
    The risk of breaking current code is low: current macro expansions are not changed, and it's unlikely for existing code to accidentally get safe wrappers. But going forward it does expand the exposure surface for safe interop, increasing the impact of regressions in safe interop wrappers.
  • Testing:
    Lit regression tests. Will run a SWB and include these changes in a sweep of OSS code before merging, but I have not done that yet.

This test was missing matcher for one safe wrapper. Add
--implicit-check-not to prevent this going forward.
When safe interop was stabilized, lifetimebound deliberately not
stabilized. The check for lifetimebound on the implicit "this" parameter
was accidentally not gated behind the experimental feature check,
however. Now lifetimebound on implicit "this" is no longer in the stable
feature set.

rdar://175396896
We previously prevented generating safe wrappers on functions with
template instantiations in the signature, unless those instantiations
were hidden behind a typedef. This is because those template
instantiations cannot be expressed in Swift syntax, so the macro
would expand to a function with invalid syntax.

For the std::span parameter itself however, that type is replaced with a
Swift Span in the safe wrapper, so it's not an issue in the type
signature. We would previously use the std::span type name from the
original signature to cast from Span to std::span, which does not work
with the raw std::span type. This uses `.init` instead when this is the
case, which avoids spelling out the type. When possible, we still use
the concrete type name, for clarity and by providing information we have
accessible the typechecker needs to do less work.

Resolves swiftlang#86339

rdar://167712240
These tests never use bridging headers or define BRIDGING_HEADER, so
there's not reason for them to check for this define.
@hnrklssn hnrklssn requested a review from a team as a code owner April 23, 2026 06:13
@hnrklssn hnrklssn changed the title Swiftify span typedefless [Swiftify] enable safe wrappers for std::span without typedef Apr 23, 2026
@hnrklssn
Copy link
Copy Markdown
Member Author

@swift-ci please test

1 similar comment
@Xazax-hun
Copy link
Copy Markdown
Contributor

@swift-ci please test

@hnrklssn
Copy link
Copy Markdown
Member Author

Oh I forgot to mention: this PR is based on top of #88620

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