Not yet, everything in a single swift file.
I made everything @inlinable but that's still COW-ing for me:
Code
public final class IntRef {
public var value: Int
@inlinable public init(_ value: Int) {
self.value = value
}
}
public struct IntVal {
public var ref: IntRef
@inlinable public init(_ value: Int = 0) {
ref = IntRef(value)
}
@inlinable public var value: Int {
@inlinable get { ref.value }
@inlinable set {
guard isKnownUniquelyReferenced(&ref) else {
print("COW")
ref = IntRef(newValue)
return
}
print("NO COW")
ref.value = newValue
}
}
@inlinable public mutating func append(_ element: Int) {
value += element
}
}
extension [Int: IntVal] {
@inlinable public subscript(newSubscript key: Key) -> IntVal {
@inlinable get { self[key]! }
@inlinable set {
self[key] = newValue
}
}
}
@inlinable public func test_subscript() {
var values: [Int: IntVal] = [0 : IntVal(1)]
var a = values[newSubscript: 0]
a.append(0) // COW 🤔
values[newSubscript: 0] = a
print("done")
}
Do you have an example of "_semantics" ?