I'm trying to make GitHub - simdutf/simdutf: Unicode routines (UTF8, UTF16, UTF32) and Base64: billions of characters per second using SSE2, AVX2, NEON, AVX-512, RISC-V Vector Extension, LoongArch64, POWER. Part of Node.js, WebKit/Safari, Ladybird, Chromium, Cloudflare Workers and Bun. seamlessly interoperate with Swift, and considering my insufficient knowledge of C/C++ and the fact that C++ interop is new, I need your help
.
The related Pull Request is this one:
I also tried to look around in apple / swiftlang orgs to find some examples of C++ Span interop, with no luck.
I'll be happy if you know and let me know of some good-quality projects that are similar to this situation, so I can take a look at them.
The maintainer is rightfully asking some questions, and I myself also have some questions:
-
- Is a modulemap required for things to work, or can I reasonably get rid of it?
- The maintainer is fine with the modulemap so I'd just let it be if it's too problematic to remove.
-
- Swift wasn't synthesizing Swift Span types from
std::spaneven after the__noescapeattributes I applied. Are there known issues/quirks around this?
- The library guards the Span support behind
SIMDUTF_SPANand claims it'll be enabled if on C++ 20, and I have also declaredcxxLanguageStandard: .gnucxx20in myPackage.swifts. - Could it be some kind of issue with the library correctly detecting and enabling its Span support? The related code is here.
- Swift wasn't synthesizing Swift Span types from
-
- Is it required to use Swift 6.2?
- Optimally we can have Swift synthesize function using
Spanon Swift 6.2, and for Swift 6.1 and 6.0 it can just only synthesize the functions via theUnsafePointertypes.
-
- How is the Package.swift file that I put together looking?
- Any issues/sub-optimalities there?
The following questions from a maintainer of the library are viewable in the PR as well:
-
- The maintainer asks (link):
-
Would it be implementable by adding a SIMDUTF_COUNTED_BY() macro that expands to the needed attributes?
- The maintainer asks (link):
-
Can this be solved in an easier way by instead providing a separate auto generated header file, where you can use all the attributes and swift specific code you wish?
- I think not? Because like in the WWDC 2025 video C++ interop, we need source file changes as well, other than header files changes?
-
-
- About
#include <lifetimebound.h>, the maintainer says (link):
-
this is not a standard header, where is it defined? I can find it on my system using clang 21 and gcc 15.
- I suspect he meant to write "I can_'t_ find it on my system".
- About
-
- The maintainer asks (link):
looks like the __noescape could be expressed as a C++ attribute instead, can you use that instead?
Attributes in Clang — Clang 22.0.0git documentationwould that be useful outside of swift compatibility?
regarding the __counted_by, the only info I can find is that it is used on struct members. the gcc manual https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc.pdf says:
In C++ this attribute is ignored
are there alternative ways of specifying the "counted by" property?
I realize these might be one too many questions. I still appreciate any answers to any of them.