[VtArray] Add zero-copy withUnsafeBufferPointer and single-copy buffer init#39
[VtArray] Add zero-copy withUnsafeBufferPointer and single-copy buffer init#39furbytm wants to merge 1 commit into
Conversation
e64c816 to
324687f
Compare
|
This doesn't compile on Swift 6.1 and Swift 6.2, but I think this modification should work for Swift 6.1-6.4. If it makes sense to you, could you update your PR to use this? |
…r init Add a borrowing withUnsafeBufferPointer(_:) to the VtArray protocols, backed by cdata() so the read never detaches the copy-on-write storage, and an init(_: UnsafeBufferPointer) that assigns a contiguous buffer in a single copy rather than element-by-element push_backs. The initializer is the write-side complement of cdata()'s zero-copy reads. Signed-off-by: Furby™ <furby@wabi.foundation>
324687f to
89318d1
Compare
Done! Your modification is in, tested with Swift 6.3.2. |
|
Also, to make this less of a recurring thing for you to catch... I've got SwiftUsd's Edited later, after some trial and error...It also appears that workflow explicitly runs export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw ~/Library/Developer/Toolchains/swift-6.2.4-RELEASE.xctoolchain/Info.plist)
Then I had to add a wrapper script for #!/bin/bash
if [ "$1" == "--version" ]; then
REAL_OUTPUT=$(command -p swift --version)
VERSION_NUM=$(echo "$REAL_OUTPUT" | grep -oE 'version [0-9.]+' | head -n 1 | awk '{print $2}')
echo "swift-driver version: 1.148.6 Apple Swift version $VERSION_NUM (swiftlang-$VERSION_NUM clang-2100.1.1.101)"
echo "Target: arm64-apple-macosx26.0"
else
exec command -p swift "$@"
fiLastly, it appears that the only real blocker with using Swiftly-installed toolchains are the compiler errors regarding the missing #ifndef __PXR_BASE_ARCH_SWIFT_INTEROP_H__
#define __PXR_BASE_ARCH_SWIFT_INTEROP_H__
#ifdef __APPLE__
# if __has_include(<swift/bridging>)
# include <swift/bridging> // the only time <swift/bridging> is ever included, safely guarded by __has_include
# endif // __has_include(<swift/bridging>)
#endif // __APPLE__
// Safely (re)define swift cxx interop macros if they were not already provided
// by the compiler via <swift/bridging>. This fallback also ensures that the
// interop macros are available on non-Apple platforms too (e.g., Linux).
#if defined(__has_attribute) && !defined(_CXX_INTEROP_HAS_ATTRIBUTE)
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) __has_attribute(x)
#elif !defined(_CXX_INTEROP_HAS_ATTRIBUTE)
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) 0
#endif
#if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
#if !defined(SWIFT_SELF_CONTAINED)
#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned")))
#endif // SWIFT_SELF_CONTAINED
// ...
// do this for all swift/cxx interop macros defined in swift/bridging
// ...
#else // !_CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
// Empty defines for compilers that don't support `attribute(swift_attr)`.
#if !defined(SWIFT_SELF_CONTAINED)
#define SWIFT_SELF_CONTAINED
#endif // SWIFT_SELF_CONTAINED
// ...
// do this for all swift/cxx interop empty macros defined in swift/bridging
// ...
#endif // _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
#if defined(_CXX_INTEROP_HAS_ATTRIBUTE)
#undef _CXX_INTEROP_HAS_ATTRIBUTE
#endif // _CXX_INTEROP_HAS_ATTRIBUTE
#endif // __PXR_BASE_ARCH_SWIFT_INTEROP_H__ |
Neat. It might also interest you to look at ci-at-desk, which is a custom single-machine CI system for specifically SwiftUsd's needs, inspired by GitHub Actions. ci-at-desk is now my main CI system, because it means I can kick off a huge test run on as many Xcodes, Swiftly toolchains, simulators, and physical iOS/visionOS devices as I want and immediately dig into test failures without having to download artifacts from all the distributed runners. (It also caches OpenUSD builds in a way I was never really able to do with GitHub Actions because GitHub Actions caches are scoped to branches.)
Yeah, for reasons I'll mention later, I prefer to use
Oh, interesting, I guess I made the version parser too strict. Feel free to open an issue/PR about making it flexible enough to handle both Xcode and Swiftly toolchains.
Yeah, this is the big reason I don't like having swiftly manage my toolchains for me. Xcode can find Again though, don't feel like you have to catch every last esoteric Swift-Cxx interop gotcha, if your PRs compile and the tests pass on Swift 6.3 (or 6.4, once that's officially released), that's fine, I can take on the work of fixing the obscure issues. |
Description
This PR adds a borrowing
withUnsafeBufferPointer(_:)to theVtArrayprotocols, backed bycdata()so the read never detaches the copy-on-write storage, and aninit(_: UnsafeBufferPointer)that assigns a contiguous buffer in a single copy rather than element-by-elementpush_backs. The initializer is the write-side complement ofcdata()'s zero-copy reads.Related Issues / PRs
Checklist
CONTRIBUTING.mdPackage.swift/swift-package) from the commit