diff --git a/Package.swift b/Package.swift index 775157b3..45fb5537 100644 --- a/Package.swift +++ b/Package.swift @@ -74,10 +74,13 @@ let package = Package( cSettings: [.define("SWIFT_OPT", .when(configuration: .release))]), .target( name: "PenguinStructures", - dependencies: []), + dependencies: ["PenguinPointers"]), .testTarget( name: "PenguinStructuresTests", dependencies: ["PenguinStructures"]), + .target( + name: "PenguinPointers", + dependencies: []), .target( name: "Benchmarks", dependencies: [ diff --git a/Sources/PenguinGraphs/VertexParallelProtocols.swift b/Sources/PenguinGraphs/VertexParallelProtocols.swift index cc87124b..91dc197a 100644 --- a/Sources/PenguinGraphs/VertexParallelProtocols.swift +++ b/Sources/PenguinGraphs/VertexParallelProtocols.swift @@ -14,6 +14,7 @@ import PenguinParallel import PenguinStructures +@_implementationOnly import PenguinPointers // MARK: - Mailboxes @@ -178,10 +179,10 @@ public class PerThreadMailboxes< header.hasMessages = true withUnsafeMutablePointerToElements { buff in let ptr = buff.advanced(by: vertex.index) - if ptr.pointee == nil { - ptr.pointee = message + if ptr* == nil { + ptr.pointee = message // :-( } else { - ptr.pointee!.merge(message) + ptr.pointee!.merge(message) // :-( } } } @@ -260,11 +261,11 @@ public class PerThreadMailboxes< var i = inboxP var o = outboxP for _ in 0.. Pointee { + ptr.pointee + } +} + +extension UnsafeMutablePointer { + public static postfix func * (_ ptr: UnsafeMutablePointer) -> Pointee { + ptr.pointee + } + + public static func *= (_ ptr: UnsafeMutablePointer, _ pointee: Pointee) { + ptr.pointee = pointee + } +} diff --git a/Sources/PenguinStructures/ArrayStorage.swift b/Sources/PenguinStructures/ArrayStorage.swift index 0a6f7917..0b221255 100644 --- a/Sources/PenguinStructures/ArrayStorage.swift +++ b/Sources/PenguinStructures/ArrayStorage.swift @@ -14,6 +14,8 @@ // limitations under the License. // +@_implementationOnly import PenguinPointers + //****************************************************************************** // This file exposes reference-counted buffer types similar to the storage for // `Array`, but designed to be (potentially) handled through type-erased APIs @@ -92,7 +94,7 @@ extension ArrayStorageImplementation { /// The number of elements stored in `self`. public var count: Int { - _read { yield access.withUnsafeMutablePointerToHeader { $0.pointee.count } } + _read { yield access.withUnsafeMutablePointerToHeader { $0*.count } } _modify { defer { _fixLifetime(self) } yield &access.withUnsafeMutablePointerToHeader { $0 }.pointee.count @@ -103,7 +105,7 @@ extension ArrayStorageImplementation { public var capacity: Int { _read { yield access.withUnsafeMutablePointerToHeader { - $0.pointee.capacity } + $0*.capacity } } _modify { defer { _fixLifetime(self) } @@ -118,7 +120,7 @@ extension ArrayStorageImplementation { if r == capacity { return nil } access.withUnsafeMutablePointers { h, e in (e + r).initialize(to: x) - h[0].count = r + 1 + h[0].count = r + 1 // TODO: THIS CAN'T BE SUPPORTED! } return r } @@ -128,7 +130,7 @@ extension ArrayStorageImplementation { _ body: (inout UnsafeMutableBufferPointer) -> R ) -> R { access.withUnsafeMutablePointers { h, e in - var b = UnsafeMutableBufferPointer(start: e, count: h[0].count) + var b = UnsafeMutableBufferPointer(start: e, count: h*.count) return body(&b) } } @@ -152,7 +154,7 @@ extension ArrayStorageImplementation { /// returning the index of the appended element, or `nil` if there was /// insufficient capacity remaining public func appendValue_(at p: UnsafeRawPointer) -> Int? { - append(p.assumingMemoryBound(to: Element.self)[0]) + append(p.assumingMemoryBound(to: Element.self)*) } /// Invokes `body` with the memory occupied by initialized elements. @@ -168,7 +170,7 @@ extension ArrayStorageImplementation { /// Deinitialize stored data. Models should call this from their `deinit`. public func deinitialize() { access.withUnsafeMutablePointers { h, e in - e.deinitialize(count: h[0].count) + e.deinitialize(count: h*.count) h.deinitialize(count: 1) } }