Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ jobs:
runs-on: macos-26
strategy:
matrix:
swift: ["6.2"]
swift: ["6.3"]
steps:
- name: Set up Xcode
run: sudo xcode-select -s "/Applications/Xcode_26.4.app"
- id: swift-version
run: |
MAJOR=$(echo "${{ matrix.swift }}" | cut -d. -f1)
Expand All @@ -38,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
swift: ["6.2"]
swift: ["6.3"]
container:
image: swift:${{ matrix.swift }}-jammy
steps:
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "Checkouts/swift-runtime-headers"]
path = Checkouts/swift-runtime-headers
[submodule "Submodules/swift-runtime-headers"]
path = Submodules/swift-runtime-headers
url = https://github.com/jcmosc/swift-runtime-headers.git
branch = release/6.2
branch = release/6.3
1 change: 0 additions & 1 deletion Checkouts/swift-runtime-headers
Submodule swift-runtime-headers deleted from 42c0a0
12 changes: 6 additions & 6 deletions Compute.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 6.0;
SYSTEM_HEADER_SEARCH_PATHS = (
Checkouts/swift-runtime-headers/include,
Checkouts/swift-runtime-headers/stdlib/include,
Checkouts/swift-runtime-headers/stdlib/public/SwiftShims,
Submodules/swift-runtime-headers/include,
Submodules/swift-runtime-headers/stdlib/include,
Submodules/swift-runtime-headers/stdlib/public/SwiftShims,
);
TARGETED_DEVICE_FAMILY = "1,2,7";
USER_HEADER_SEARCH_PATHS = (
Expand Down Expand Up @@ -437,9 +437,9 @@
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 6.0;
SYSTEM_HEADER_SEARCH_PATHS = (
Checkouts/swift-runtime-headers/include,
Checkouts/swift-runtime-headers/stdlib/include,
Checkouts/swift-runtime-headers/stdlib/public/SwiftShims,
Submodules/swift-runtime-headers/include,
Submodules/swift-runtime-headers/stdlib/include,
Submodules/swift-runtime-headers/stdlib/public/SwiftShims,
);
TARGETED_DEVICE_FAMILY = "1,2,7";
USER_HEADER_SEARCH_PATHS = (
Expand Down
22 changes: 16 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// swift-tools-version: 6.2
// swift-tools-version: 6.3

import PackageDescription

let swiftCheckoutPath = "\(Context.packageDirectory)/Checkouts/swift-runtime-headers"
let swiftRuntimeHeadersPath = "\(Context.packageDirectory)/Submodules/swift-runtime-headers"

var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"),
Expand Down Expand Up @@ -60,7 +60,6 @@ let package = Package(
dependencies: [
"Compute",
"_ComputeTestSupport",
.product(name: "Algorithms", package: "swift-algorithms"),
.product(name: "Semaphore", package: "Semaphore"),
],
swiftSettings: [
Expand All @@ -78,6 +77,17 @@ let package = Package(
],
linkerSettings: [.linkedLibrary("swiftDemangle")]
),
.testTarget(
name: "ComputeSwiftTests",
dependencies: [
"Compute",
.product(name: "Algorithms", package: "swift-algorithms"),
],
swiftSettings: [
.enableExperimentalFeature("Extern")
],
linkerSettings: [.linkedLibrary("swiftDemangle")]
),
.target(
name: "ComputeCxx",
dependencies: [
Expand All @@ -94,9 +104,9 @@ let package = Package(
"-static",
"-DCOMPILED_WITH_SWIFT",
"-DPURE_BRIDGING_MODE",
"-isystem", "\(swiftCheckoutPath)/include",
"-isystem", "\(swiftCheckoutPath)/stdlib/include",
"-isystem", "\(swiftCheckoutPath)/stdlib/public/SwiftShims",
"-isystem", "\(swiftRuntimeHeadersPath)/include",
"-isystem", "\(swiftRuntimeHeadersPath)/stdlib/include",
"-isystem", "\(swiftRuntimeHeadersPath)/stdlib/public/SwiftShims",
]),
]
),
Expand Down
42 changes: 22 additions & 20 deletions Sources/Compute/Attribute/AnyAttribute.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import ComputeCxx

extension Graph {

@_extern(c, "AGGraphSearch")
static func search(
attribute: AnyAttribute,
options: SearchOptions,
predicate: @escaping (AnyAttribute) -> Bool
) -> Bool

@_extern(c, "AGGraphMutateAttribute")
static func mutateAttribute(
_ attribute: AnyAttribute,
type: Metadata,
invalidating: Bool,
modify: @escaping (UnsafeMutableRawPointer) -> Void
)

}
@_silgen_name("AGGraphMutateAttribute")
func AGGraphMutateAttribute(
_ attribute: AnyAttribute,
type: Metadata,
invalidating: Bool,
modify: (UnsafeMutableRawPointer) -> Void
)

@_silgen_name("AGGraphSearch")
func AGGraphSearch(
attribute: AnyAttribute,
options: SearchOptions,
predicate: (AnyAttribute) -> Bool
) -> Bool

extension AnyAttribute {

Expand All @@ -40,9 +36,15 @@ extension AnyAttribute {

public func mutateBody<Body>(as type: Body.Type, invalidating: Bool, _ mutator: (inout Body) -> Void) {
withoutActuallyEscaping(mutator) { escapingMutator in
Graph.mutateAttribute(self, type: Metadata(type), invalidating: invalidating) { pointer in
let modify: (UnsafeMutableRawPointer) -> Void = { pointer in
escapingMutator(&pointer.assumingMemoryBound(to: Body.self).pointee)
}
AGGraphMutateAttribute(
self,
type: Metadata(type),
invalidating: invalidating,
modify: modify
)
}
}

Expand Down Expand Up @@ -78,7 +80,7 @@ extension AnyAttribute {

public func breadthFirstSearch(options: SearchOptions, _ predicate: (AnyAttribute) -> Bool) -> Bool {
return withoutActuallyEscaping(predicate) { escapingPredicate in
return Graph.search(attribute: self, options: options, predicate: escapingPredicate)
return AGGraphSearch(attribute: self, options: options, predicate: escapingPredicate)
}
}

Expand Down
30 changes: 14 additions & 16 deletions Sources/Compute/Attribute/AttributeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ struct ProtocolConformance {
var witnessTable: UnsafeRawPointer
}

extension AGUnownedGraphContextRef {
@_silgen_name("AGGraphInternAttributeType")
func AGGraphInternAttributeType(
_ graph: UnsafeRawPointer,
type: Metadata,
makeAttributeType: () -> UnsafePointer<_AttributeType>
) -> UInt32

@_extern(c, "AGGraphInternAttributeType")
fileprivate static func internAttributeType(
_ graph: UnsafeRawPointer,
type: Metadata,
makeAttributeType: () -> UnsafePointer<_AttributeType>
)
-> UInt32
extension AGUnownedGraphContextRef {

@inline(__always)
func internAttributeType(
type: Metadata,
makeAttributeType: () -> UnsafePointer<_AttributeType>
) -> UInt32 {
return AGUnownedGraphContextRef.internAttributeType(
return AGGraphInternAttributeType(
unsafeBitCast(self, to: UnsafeRawPointer.self),
type: type,
makeAttributeType: makeAttributeType
Expand All @@ -38,6 +37,11 @@ extension String {

}

@_silgen_name("AGRetainClosure")
func AGRetainClosure(
_ closure: (UnsafeMutableRawPointer, AnyAttribute) -> Void
) -> _AGClosureStorage

extension _AttributeType {

nonisolated(unsafe) static let vtable: UnsafePointer<_AttributeVTable> = {
Expand Down Expand Up @@ -92,12 +96,6 @@ extension _AttributeType {
return UnsafePointer(vtable)
}()

@_extern(c, "AGRetainClosure")
fileprivate static func passRetainedClosure(
_ closure: (UnsafeMutableRawPointer, AnyAttribute) -> Void
)
-> _AGClosureStorage

init(
selfType: _AttributeBody.Type,
valueType: Any.Type,
Expand All @@ -111,7 +109,7 @@ extension _AttributeType {
flags.insert(.hasDestroySelf)
}

let retainedUpdate = _AttributeType.passRetainedClosure(update)
let retainedUpdate = AGRetainClosure(update)
let conformance = unsafeBitCast(
selfType as any _AttributeBody.Type,
to: ProtocolConformance.self
Expand Down
26 changes: 12 additions & 14 deletions Sources/Compute/Attribute/Rule/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,17 @@ extension Rule {

}

extension Graph {
@_extern(c, "AGGraphReadCachedAttribute")
static func readCachedAttribute(
hash: Int,
type: Metadata,
body: UnsafeRawPointer,
valueType: Metadata,
options: CachedValueOptions,
owner: AnyAttribute,
changed: UnsafeMutablePointer<Bool>?,
attributeTypeID: (AGUnownedGraphContextRef) -> UInt32
) -> UnsafeRawPointer
}
@_silgen_name("AGGraphReadCachedAttribute")
func AGGraphReadCachedAttribute(
hash: Int,
type: Metadata,
body: UnsafeRawPointer,
valueType: Metadata,
options: CachedValueOptions,
owner: AnyAttribute,
changed: UnsafeMutablePointer<Bool>?,
attributeTypeID: (AGUnownedGraphContextRef) -> UInt32
) -> UnsafeRawPointer

extension Rule where Self: Hashable {

Expand Down Expand Up @@ -103,7 +101,7 @@ extension Rule where Self: Hashable {
bodyPtr: UnsafeRawPointer,
update: () -> (UnsafeMutableRawPointer, AnyAttribute) -> Void
) -> UnsafePointer<Value> {
let value = Graph.readCachedAttribute(
let value = AGGraphReadCachedAttribute(
hash: hashValue,
type: Metadata(Self.self),
body: bodyPtr,
Expand Down
11 changes: 4 additions & 7 deletions Sources/Compute/Attribute/RuleContext/AnyRuleContext.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import ComputeCxx

@_silgen_name("AGGraphWithUpdate")
func AGGraphWithUpdate(_ attribute: AnyAttribute, body: () -> Void)

public struct AnyRuleContext {

public var attribute: AnyAttribute
Expand All @@ -16,14 +19,8 @@ public struct AnyRuleContext {
return RuleContext<Value>(attribute: Attribute(identifier: attribute))
}

@_extern(c, "AGGraphWithUpdate")
private static func withUpdate(_ attribute: AnyAttribute, body: @escaping () -> Void)

public func update(body: () -> Void) {
// TODO: double check needs to be escaping
withoutActuallyEscaping(body) { escapingBody in
AnyRuleContext.withUpdate(attribute, body: escapingBody)
}
AGGraphWithUpdate(attribute, body: body)
}

public func changedValue<Value>(
Expand Down
48 changes: 30 additions & 18 deletions Sources/Compute/Graph/Graph.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import ComputeCxx

@_silgen_name("AGGraphSetOutputValue")
@inline(__always)
@inlinable
func AGGraphSetOutputValue(_ value: UnsafeRawPointer, of type: Metadata)

extension Graph {

@_silgen_name("AGGraphSetOutputValue")
@inline(__always)
@inlinable
public static func setOutputValue<Value>(_ value: UnsafePointer<Value>)
public static func setOutputValue<Value>(_ value: UnsafePointer<Value>) {
AGGraphSetOutputValue(UnsafeRawPointer(value), of: Metadata(Value.self))
}

@_transparent
@inline(__always)
Expand All @@ -22,20 +28,33 @@ extension Graph {

}

extension Graph {
@_silgen_name("AGGraphSetUpdateCallback")
func AGGraphSetUpdateCallback(
_ graph: UnsafeRawPointer,
callback: (() -> Void)?
)

@_silgen_name("AGGraphSetInvalidationCallback")
func AGGraphSetInvalidationCallback(
_ graph: UnsafeRawPointer,
callback: ((AnyAttribute) -> Void)?
)

@_silgen_name("AGGraphWithMainThreadHandler")
func AGGraphWithMainThreadHandler(
_ graph: UnsafeRawPointer,
body: () -> Void,
mainThreadHandler: (() -> Void) -> Void
)

@_extern(c, "AGGraphSetUpdateCallback")
private static func setUpdateCallback(_ graph: UnsafeRawPointer, callback: (() -> Void)?)
extension Graph {

public func onUpdate(_ handler: @escaping () -> Void) {
Graph.setUpdateCallback(unsafeBitCast(self, to: UnsafeRawPointer.self), callback: handler)
AGGraphSetUpdateCallback(unsafeBitCast(self, to: UnsafeRawPointer.self), callback: handler)
}

@_extern(c, "AGGraphSetInvalidationCallback")
private static func setInvalidationCallback(_ graph: UnsafeRawPointer, callback: ((AnyAttribute) -> Void)?)

public func onInvalidation(_ handler: @escaping (AnyAttribute) -> Void) {
Graph.setInvalidationCallback(unsafeBitCast(self, to: UnsafeRawPointer.self), callback: handler)
AGGraphSetInvalidationCallback(unsafeBitCast(self, to: UnsafeRawPointer.self), callback: handler)
}

public func withDeadline<T>(_ deadline: UInt64, _ body: () -> T) -> T {
Expand All @@ -61,15 +80,8 @@ extension Graph {
return result
}

@_extern(c, "AGGraphWithMainThreadHandler")
private static func withMainThreadHandler(
_ graph: UnsafeRawPointer,
body: () -> Void,
mainThreadHandler: (() -> Void) -> Void
)

public func withMainThreadHandler(_ mainThreadHandler: (() -> Void) -> Void, do body: () -> Void) {
Graph.withMainThreadHandler(
AGGraphWithMainThreadHandler(
unsafeBitCast(self, to: UnsafeRawPointer.self),
body: body,
mainThreadHandler: mainThreadHandler
Expand Down
Loading
Loading