From e8436b72a8c3381ea2c1bb375930b8a909f57229 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 17:03:56 +0100 Subject: [PATCH 1/7] Make closure passed to AGGraphMutateAttribute escaping --- Sources/Compute/Attribute/AnyAttribute.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Compute/Attribute/AnyAttribute.swift b/Sources/Compute/Attribute/AnyAttribute.swift index f552712..1c9e32f 100644 --- a/Sources/Compute/Attribute/AnyAttribute.swift +++ b/Sources/Compute/Attribute/AnyAttribute.swift @@ -10,7 +10,7 @@ extension Graph { _ attribute: AnyAttribute, type: Metadata, invalidating: Bool, - modify: (UnsafeMutableRawPointer) -> Void + modify: @escaping (UnsafeMutableRawPointer) -> Void ) } @@ -35,8 +35,10 @@ extension AnyAttribute { } public func mutateBody(as type: Body.Type, invalidating: Bool, _ mutator: (inout Body) -> Void) { - Graph.mutateAttribute(self, type: Metadata(type), invalidating: invalidating) { pointer in - mutator(&pointer.assumingMemoryBound(to: Body.self).pointee) + withoutActuallyEscaping(mutator) { escapingMutator in + Graph.mutateAttribute(self, type: Metadata(type), invalidating: invalidating) { pointer in + escapingMutator(&pointer.assumingMemoryBound(to: Body.self).pointee) + } } } From 64169f08bc0b538782b6ff848b699843b2c0d139 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 17:04:04 +0100 Subject: [PATCH 2/7] Fix warning --- Sources/ComputeCxx/Graph/Graph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ComputeCxx/Graph/Graph.cpp b/Sources/ComputeCxx/Graph/Graph.cpp index c629df8..a562962 100644 --- a/Sources/ComputeCxx/Graph/Graph.cpp +++ b/Sources/ComputeCxx/Graph/Graph.cpp @@ -801,7 +801,7 @@ void Graph::indirect_attribute_set(data::ptr indirect_node, Attrib } uint64_t source_subgraph_id = source && !source.is_nil() ? source.subgraph()->subgraph_id() : 0; - indirect_node->modify(WeakAttributeID(source, source_subgraph_id), resolved_source.offset()); + indirect_node->modify(WeakAttributeID(source, uint32_t(source_subgraph_id)), resolved_source.offset()); indirect_node->set_traverses_contexts(AttributeID(indirect_node).subgraph()->context_id() != source.subgraph()->context_id()); From f45102abed9f925eb5f0a09cf731a145ac85ade7 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 17:04:17 +0100 Subject: [PATCH 3/7] Ensure try is before await --- Tests/ComputeTests/Shared/Graph/GraphTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ComputeTests/Shared/Graph/GraphTests.swift b/Tests/ComputeTests/Shared/Graph/GraphTests.swift index 0a39792..c27f60d 100644 --- a/Tests/ComputeTests/Shared/Graph/GraphTests.swift +++ b/Tests/ComputeTests/Shared/Graph/GraphTests.swift @@ -301,7 +301,7 @@ struct GraphTests { @Test func initialDescription() async throws { - await try #require(processExitsWith: .success) { + try await #require(processExitsWith: .success) { let description = try #require( Graph.description(nil, options: [DescriptionOption.format: "graph/dict"] as NSDictionary) @@ -336,7 +336,7 @@ struct GraphTests { // which we can't predict deterministically. @Test func graphDescription() async throws { - await try #require(processExitsWith: .success) { + try await #require(processExitsWith: .success) { let graph = Graph() let subgraph = Subgraph(graph: graph) From 7be169142222365ed216b90f4cf0c4abe5127832 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 17:13:07 +0100 Subject: [PATCH 4/7] Add CompatibilityModeAttributeGraphV6 --- Package.swift | 3 ++ Sources/Compute/Attribute/Attribute.swift | 8 +++- .../Shared/Attribute/AttributeTests.swift | 42 ++++++++++++++----- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Package.swift b/Package.swift index a66f1a3..c62f9e6 100644 --- a/Package.swift +++ b/Package.swift @@ -73,6 +73,9 @@ let package = Package( products: [ .library(name: "Compute", targets: ["Compute"]) ], + traits: [ + .trait(name: "CompatibilityModeAttributeGraphV6") + ], dependencies: dependencies, targets: [ .target( diff --git a/Sources/Compute/Attribute/Attribute.swift b/Sources/Compute/Attribute/Attribute.swift index 10b5895..443ea44 100644 --- a/Sources/Compute/Attribute/Attribute.swift +++ b/Sources/Compute/Attribute/Attribute.swift @@ -45,9 +45,15 @@ public struct Attribute { let typeID = graphContext.internAttributeType( type: Metadata(Body.self) ) { + let bodyType: _AttributeBody.Type + #if CompatibilityModeAttributeGraphV6 + bodyType = Body.self + #else + bodyType = flags.contains(.external) ? _External.self : Body.self + #endif let attributeType = _AttributeType( - selfType: flags.contains(.external) ? _External.self : Body.self, + selfType: bodyType, valueType: Value.self, flags: flags, update: update() diff --git a/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift b/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift index c75f50f..db8ec0c 100644 --- a/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift +++ b/Tests/ComputeTests/Shared/Attribute/AttributeTests.swift @@ -34,17 +34,28 @@ struct AttributeTests { ) let attributeType = attribute.identifier.info.type.pointee - #expect(attributeType.self_id == Metadata(_External.self)) + #if CompatibilityModeAttributeGraphV6 + #expect(attributeType.self_id == Metadata(External.self)) + #else + #expect(attributeType.self_id == Metadata(_External.self)) + #endif #expect(attributeType.value_id == Metadata(Int.self)) #expect(attributeType.flags == [.external, .comparisonModeEquatableAlways]) #expect(attributeType.internal_offset == 28) #expect(attributeType.value_layout == expectedlayout) - let attributeBody = unsafeBitCast( - _External.self as any _AttributeBody.Type, - to: (type: Metadata, witnessTable: UnsafeRawPointer).self - ) + #if CompatibilityModeAttributeGraphV6 + let attributeBody = unsafeBitCast( + External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) + #else + let attributeBody = unsafeBitCast( + _External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) + #endif #expect(attributeType.body_conformance.type_id == attributeBody.type) #expect(attributeType.body_conformance.witness_table == attributeBody.witnessTable) } @@ -69,17 +80,28 @@ struct AttributeTests { ) let attributeType = attribute.identifier.info.type.pointee - #expect(attributeType.self_id == Metadata(_External.self)) + #if CompatibilityModeAttributeGraphV6 + #expect(attributeType.self_id == Metadata(External.self)) + #else + #expect(attributeType.self_id == Metadata(_External.self)) + #endif #expect(attributeType.value_id == Metadata(Int.self)) #expect(attributeType.flags == [.external, .comparisonModeEquatableAlways]) #expect(attributeType.internal_offset == 28) #expect(attributeType.value_layout == expectedlayout) - let attributeBody = unsafeBitCast( - _External.self as any _AttributeBody.Type, - to: (type: Metadata, witnessTable: UnsafeRawPointer).self - ) + #if CompatibilityModeAttributeGraphV6 + let attributeBody = unsafeBitCast( + External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) + #else + let attributeBody = unsafeBitCast( + _External.self as any _AttributeBody.Type, + to: (type: Metadata, witnessTable: UnsafeRawPointer).self + ) + #endif #expect(attributeType.body_conformance.type_id == attributeBody.type) #expect(attributeType.body_conformance.witness_table == attributeBody.witnessTable) } From c413d0e5cb139651ec75b4c0f34289f70c3a6b76 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 17:18:36 +0100 Subject: [PATCH 5/7] Add test step to CI --- .github/workflows/swift.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index d6f4a43..5a788c7 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -23,3 +23,9 @@ jobs: - name: Build run: swift build working-directory: ./Compute + - name: Test + run: | + swift test --filter UtilitiesTests + swift test --filter ComputeLayoutDescriptorTests + swift test --filter ComputeTests + working-directory: ./Compute From 2063c439e310e3d5d97231ba501c6afd96daeec0 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 19:01:28 +0100 Subject: [PATCH 6/7] Depend on fork of DarwinPrivateFrameworks --- Package.resolved | 8 ++++---- Package.swift | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Package.resolved b/Package.resolved index cdce0b4..e7df565 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "4cf189cb4efdb66c68fe77b7823a66ab1b93e0017d80eccbae8ac327811f76ec", + "originHash" : "0db1a6cf7f89646c902e1f765ceeda44383c8f1ec559ce4abfbe1fb3bc963fad", "pins" : [ { "identity" : "darwinprivateframeworks", "kind" : "remoteSourceControl", - "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks", + "location" : "https://github.com/jcmosc/DarwinPrivateFrameworks", "state" : { - "revision" : "5eb0f26ea5a5bbd5068f6b3daf3a97dd3682b234", - "version" : "0.0.4" + "branch" : "main", + "revision" : "add872df66b139bbb26b44f1dc272199b9f7da6a" } }, { diff --git a/Package.swift b/Package.swift index c62f9e6..eb7bce4 100644 --- a/Package.swift +++ b/Package.swift @@ -27,8 +27,8 @@ if let useLocalDepsEnv = Context.environment["COMPUTE_USE_LOCAL_DEPS"], !useLoca dependencies += [ .package( - url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks", - from: "0.0.4" + url: "https://github.com/jcmosc/DarwinPrivateFrameworks", + branch: "main" ) ] } From 8c816d787234826ff6e68cfacec20a58d6e09abf Mon Sep 17 00:00:00 2001 From: James Moschou Date: Mon, 24 Nov 2025 20:23:44 +0100 Subject: [PATCH 7/7] Build and test with CompatibilityModeAttributeGraphV6 trait in CI --- .github/workflows/swift.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 5a788c7..da85cc1 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -21,11 +21,11 @@ jobs: with: checkout-scheme: release/6.2 - name: Build - run: swift build + run: swift build --traits CompatibilityModeAttributeGraphV6 working-directory: ./Compute - name: Test run: | - swift test --filter UtilitiesTests - swift test --filter ComputeLayoutDescriptorTests - swift test --filter ComputeTests + swift test --traits CompatibilityModeAttributeGraphV6 --filter UtilitiesTests + swift test --traits CompatibilityModeAttributeGraphV6 --filter ComputeLayoutDescriptorTests + swift test --traits CompatibilityModeAttributeGraphV6 --filter ComputeTests working-directory: ./Compute