Skip to content

C++ Interop should not require "type alias"es for std::span <-> Span conversions #86339

@MahdiBM

Description

@MahdiBM

Motivation

See this forums thread for how I found out about this: https://forums.swift.org/t/making-simdutf-c-c-seamlessly-interoperate-with-swift/83940/4

The issue is, you are REQUIRED to use a "typealias" for std::span and Span to work seamlessly.
So this works:

using char16_span = std::span<const char16_t>;

bool validate_utf16_as_ascii(char16_span input __noescape);

But this doesn't

bool validate_utf16_as_ascii(std::span<const char16_t> input __noescape);

This is suboptimal as it means the libraries adopting Swift's C++ interop might need some more changes for Swift to synthesize Swift-Span functions.

So 1- you need to adopt __noescape, and 2- you need to use "typealias"es.

This makes it harder for C++ libraries to just "plug in" Swift support.

Proposed solution

I think Optimally Swift just creates those "type alias"es by iteself.

Like if it sees a std::span<const char16_t>, it automatically creates a using std_span_of_const_char16_t = std::span<const char16_t> for it.
But then it'll need to always do this to ensure backward compat will not break if the library adopts using using by itself.

Or maybe the compiler can simply just synthesize functions that use Spans if it sees a C++ function using std::span __noescape.

Also the docs / the WWDC video could have been more clear about the fact that this is required, not optional.

Alternatives considered

No response

Additional information

No response

Metadata

Metadata

Assignees

Labels

c++ interopFeature: Interoperability with C++featureA feature request or implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions