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
74 changes: 74 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"indentation": {
"spaces": 4
},
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": true,
"lineBreakBeforeEachGenericRequirement": false,
"lineBreakBetweenDeclarationAttributes": false,
"lineLength": 120,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": true,
"reflowMultilineStringLiterals": {
"never": {}
},
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": false,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": false,
"DontRepeatTypeInStaticProperties": false,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": false,
"NoAssignmentInExpressions": true,
"NoBlockComments": false,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": false,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"spacesBeforeEndOfLineComments": 2,
"version": 1
}
2 changes: 1 addition & 1 deletion CompatibilityTesting/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ let package = Package(
.enableExperimentalFeature("Extern")
],
linkerSettings: [.linkedLibrary("swiftDemangle")]
)
),
]
)
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
platforms: [.macOS(.v26)],
products: [
.library(name: "Compute", targets: ["Compute"]),
.library(name: "_ComputeTestSupport", targets: ["_ComputeTestSupport"])
.library(name: "_ComputeTestSupport", targets: ["_ComputeTestSupport"]),
],
traits: [
.trait(name: "CompatibilityModeAttributeGraphV6")
Expand Down Expand Up @@ -100,8 +100,8 @@ let package = Package(
"-DPURE_BRIDGING_MODE",
"-isystem", "\(swiftCheckoutPath)/include",
"-isystem", "\(swiftCheckoutPath)/stdlib/include",
"-isystem", "\(swiftCheckoutPath)/stdlib/public/SwiftShims"
])
"-isystem", "\(swiftCheckoutPath)/stdlib/public/SwiftShims",
]),
]
),
.target(name: "ComputeCxxSwiftSupport"),
Expand Down
6 changes: 5 additions & 1 deletion Sources/Compute/Attribute/AnyAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import ComputeCxx
extension Graph {

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

@_extern(c, "AGGraphMutateAttribute")
static func mutateAttribute(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Compute/Attribute/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public struct Attribute<Value> {
) {
let bodyType: _AttributeBody.Type
#if CompatibilityModeAttributeGraphV6
bodyType = Body.self
bodyType = Body.self
#else
bodyType = flags.contains(.external) ? _External.self : Body.self
bodyType = flags.contains(.external) ? _External.self : Body.self
#endif
let attributeType =
_AttributeType(
Expand Down
6 changes: 3 additions & 3 deletions Sources/Compute/Attribute/AttributeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension _AttributeType {
vtable.pointee.self_destroy = { attributeType, body in
attributeType.pointee.attributeBody._destroySelf(body)
}
#if os(macOS)
#if os(macOS)
vtable.pointee.self_description = { attributeType, body in
let description: String
if let selfType = attributeType.pointee.self_id.type
Expand All @@ -68,7 +68,7 @@ extension _AttributeType {
let description = String._describing(value, of: valueType)
return Unmanaged<CFString>.passRetained(description as CFString).autorelease()
}
#else
#else
vtable.pointee.copy_self_description = { attributeType, body in
let description: String
if let selfType = attributeType.pointee.self_id.type
Expand All @@ -85,7 +85,7 @@ extension _AttributeType {
let description = String._describing(value, of: valueType)
return Unmanaged<CFString>.passRetained(description.cfString)
}
#endif
#endif
vtable.pointee.update_default = { attributeType, body in
attributeType.pointee.attributeBody._updateDefault(body)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Compute/Attribute/External.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ComputeCxx

public struct _External {

public init() {}

public static func _update(_: UnsafeMutableRawPointer, attribute: AnyAttribute) {}

}

extension _External: CustomStringConvertible {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Compute/Attribute/Indirect/IndirectAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public struct IndirectAttribute<Value> {

public var source: Attribute<Value> {
get {
return Attribute(identifier: identifier.source)
return Attribute(identifier: identifier.source)
}
nonmutating set {
identifier.source = newValue.identifier
}
}

public var attribute: Attribute<Value> {
return Attribute(identifier: identifier)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Compute/Attribute/Observed/ObservedAttribute.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public protocol ObservedAttribute: _AttributeBody {

mutating func destroy()

}

extension ObservedAttribute {
Expand Down
22 changes: 11 additions & 11 deletions Sources/Compute/Attribute/Optional/OptionalAttribute.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
@propertyWrapper
@dynamicMemberLookup
public struct OptionalAttribute<Value> {

public var base: AnyOptionalAttribute

public init(base: AnyOptionalAttribute) {
self.base = base
}

public init() {
base = AnyOptionalAttribute()
}

public init(_ weakAttribute: WeakAttribute<Value>) {
base = AnyOptionalAttribute(weakAttribute.base)
}

public init(_ attribute: Attribute<Value>) {
base = AnyOptionalAttribute(attribute.identifier)
}

public init(_ attribute: Attribute<Value>?) {
base = AnyOptionalAttribute(attribute?.identifier)
}

public var attribute: Attribute<Value>? {
get {
return base.attribute?.unsafeCast(to: Value.self)
Expand All @@ -32,7 +32,7 @@ public struct OptionalAttribute<Value> {
base.attribute = newValue?.identifier
}
}

public var value: Value? {
return attribute?.value
}
Expand All @@ -48,11 +48,11 @@ public struct OptionalAttribute<Value> {
return nil
}
}

public var wrappedValue: Value? {
return value
}

public var projectedValue: Attribute<Value>? {
get {
return attribute
Expand All @@ -64,7 +64,7 @@ public struct OptionalAttribute<Value> {
yield &attribute
}
}

public subscript<Member>(dynamicMember keyPath: KeyPath<Value, Member>) -> Attribute<Member>? {
return attribute?[dynamicMember: keyPath]
}
Expand Down
22 changes: 14 additions & 8 deletions Sources/Compute/Attribute/PointerOffset.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
public struct PointerOffset<Base, Member> {

public var byteOffset: Int

public init(byteOffset: Int) {
self.byteOffset = byteOffset
}

public static func of(_ member: inout Member) -> PointerOffset<Base, Member> {
return withUnsafePointer(to: &member) { memberPointer in
let offset = UnsafeRawPointer(memberPointer) - UnsafeRawPointer(invalidScenePointer())
return PointerOffset(byteOffset: offset)
}
}

public static func offset(_ body: (inout Base) -> PointerOffset<Base, Member>) -> PointerOffset<Base, Member> {
guard MemoryLayout<Member>.size != 0 else {
return PointerOffset(byteOffset: 0)
}
return body(&invalidScenePointer().pointee)
}

public static func invalidScenePointer() -> UnsafeMutablePointer<Base> {
return UnsafeMutablePointer(bitPattern: MemoryLayout<Base>.stride)!
}

}

extension PointerOffset where Base == Member {
Expand All @@ -36,7 +36,10 @@ extension PointerOffset where Base == Member {

extension PointerOffset {

public static func + <T>(_ lhs: PointerOffset<Base, T>, _ rhs: PointerOffset<T, Member>) -> PointerOffset<
public static func + <T>(
_ lhs: PointerOffset<Base, T>,
_ rhs: PointerOffset<T, Member>
) -> PointerOffset<
Base, Member
> {
return PointerOffset(byteOffset: lhs.byteOffset + rhs.byteOffset)
Expand All @@ -46,7 +49,10 @@ extension PointerOffset {

extension UnsafePointer {

public static func + <Member>(_ lhs: UnsafePointer<Pointee>, _ rhs: PointerOffset<Pointee, Member>)
public static func + <Member>(
_ lhs: UnsafePointer<Pointee>,
_ rhs: PointerOffset<Pointee, Member>
)
-> UnsafePointer<
Member
>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Compute/Attribute/Rule/StatefulRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension StatefulRule {
public var attribute: Attribute<Value> {
return Attribute<Value>(identifier: AnyAttribute.current!)
}

public var context: RuleContext<Value> {
return RuleContext<Value>(attribute: attribute)
}
Expand Down
10 changes: 8 additions & 2 deletions Sources/Compute/Attribute/RuleContext/AnyRuleContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public struct AnyRuleContext {
}
}

public func changedValue<Value>(of input: Attribute<Value>, options: AGValueOptions) -> (
public func changedValue<Value>(
of input: Attribute<Value>,
options: AGValueOptions
) -> (
value: Value, changed: Bool
) {
let result = __AGGraphGetInputValue(attribute, input.identifier, options, Metadata(Value.self))
Expand All @@ -36,7 +39,10 @@ public struct AnyRuleContext {
)
}

public func valueAndFlags<Value>(of input: Attribute<Value>, options: AGValueOptions) -> (
public func valueAndFlags<Value>(
of input: Attribute<Value>,
options: AGValueOptions
) -> (
value: Value, flags: AGChangedValueFlags
) {
let result = __AGGraphGetInputValue(attribute, input.identifier, options, Metadata(Value.self))
Expand Down
7 changes: 5 additions & 2 deletions Sources/Compute/Attribute/RuleContext/RuleContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public struct RuleContext<Value> {
public init(attribute: Attribute<Value>) {
self.attribute = attribute
}

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

Expand Down Expand Up @@ -42,7 +42,10 @@ public struct RuleContext<Value> {
)
}

public func valueAndFlags<InputValue>(of input: Attribute<InputValue>, options: AGValueOptions) -> (
public func valueAndFlags<InputValue>(
of input: Attribute<InputValue>,
options: AGValueOptions
) -> (
value: InputValue, flags: AGChangedValueFlags
) {
let value = __AGGraphGetInputValue(
Expand Down
4 changes: 3 additions & 1 deletion Sources/Compute/Attribute/Weak/WeakAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public struct WeakAttribute<Value> {
}

public init() {
base = AnyWeakAttribute(_details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0))
base = AnyWeakAttribute(
_details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0)
)
}

public init(_ attribute: Attribute<Value>) {
Expand Down
Loading