Skip to content

Commit 7754245

Browse files
committed
Update
1 parent 6a1738c commit 7754245

File tree

5 files changed

+71
-66
lines changed

5 files changed

+71
-66
lines changed

Sources/Verge/Derived/Derived.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class Derived<Value: Equatable>: Store<Value, Never>, DerivedType, @unche
121121
}
122122

123123
// TODO: Take over state.modification & state.mutation
124-
indirectSelf._receive {
124+
indirectSelf._receive_sending {
125125
$1.isDerivedFromUpstream = true
126126
$0.append(traces: value.traces)
127127
$0.replace(with: newState)

Sources/Verge/Library/InoutRef.swift

+20-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Foundation
3333
https://github.com/VergeGroup/swift-verge/pull/448
3434
*/
3535
@dynamicMemberLookup
36-
public struct InoutRef<Wrapped>: Sendable {
36+
public struct InoutRef<Wrapped> {
3737

3838
// MARK: - Nested types
3939

@@ -320,18 +320,21 @@ public struct InoutRef<Wrapped>: Sendable {
320320
*/
321321
public mutating func map<U, Result>(
322322
keyPath: WritableKeyPath<Wrapped, U>,
323-
perform: (inout sending InoutRef<U>) throws -> Result
323+
perform: (inout InoutRef<U>) throws -> Result
324324
) rethrows -> Result {
325325

326326
try map_sending(keyPath: keyPath, perform: {
327-
try perform(&$0)
327+
let r = try perform(&$0)
328+
/// https://github.com/swiftlang/swift/issues/78135
329+
let workaround = { r }
330+
return workaround()
328331
})
329332

330333
}
331334

332335
public mutating func map_sending<U, Result>(
333336
keyPath: WritableKeyPath<Wrapped, U>,
334-
perform: (inout sending InoutRef<U>) throws -> sending Result
337+
perform: (inout InoutRef<U>) throws -> sending Result
335338
) rethrows -> sending Result {
336339

337340
let result = try withUnsafeMutablePointer(to: &pointer.pointee[keyPath: keyPath]) { (pointer) in
@@ -350,22 +353,26 @@ public struct InoutRef<Wrapped>: Sendable {
350353

351354
}
352355

353-
let result = UnsafeSendableStruct(try perform(&ref))
356+
let result = try perform(&ref)
354357

355358
return result
356359
}
357360

358-
return result.send()
361+
let workaround = { result }
362+
return workaround()
359363

360364
}
361365

362366
public mutating func map<U, Result>(
363367
keyPath: WritableKeyPath<Wrapped, U?>,
364-
perform: (inout sending InoutRef<U>) throws -> Result
368+
perform: (inout InoutRef<U>) throws -> Result
365369
) rethrows -> Result? {
366370

367371
try map_sending(keyPath: keyPath, perform: {
368-
try perform(&$0)
372+
let r = try perform(&$0)
373+
/// https://github.com/swiftlang/swift/issues/78135
374+
let workaround = { r }
375+
return workaround()
369376
})
370377
}
371378

@@ -375,7 +382,7 @@ public struct InoutRef<Wrapped>: Sendable {
375382
*/
376383
public mutating func map_sending<U, Result>(
377384
keyPath: WritableKeyPath<Wrapped, U?>,
378-
perform: (inout sending InoutRef<U>) throws -> sending Result
385+
perform: (inout InoutRef<U>) throws -> sending Result
379386
) rethrows -> sending Result? {
380387

381388
guard pointer.pointee[keyPath: keyPath] != nil else {
@@ -398,12 +405,13 @@ public struct InoutRef<Wrapped>: Sendable {
398405

399406
}
400407

401-
let result = UnsafeSendableStruct(try perform(&ref))
402-
408+
let result = try perform(&ref)
409+
403410
return result
404411
}
405412

406-
return result.send()
413+
let workaround = { result }
414+
return workaround()
407415
}
408416

409417
}

Sources/Verge/Store/Store.swift

+1-10
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,13 @@ extension Store {
437437

438438
// MARK: - Internal
439439

440-
@inline(__always)
441-
func _receive<Result>(
442-
mutation: (inout InoutRef<State>, inout Transaction) throws -> Result
443-
) rethrows -> Result {
444-
try _receive_sending(mutation: {
445-
try mutation(&$0, &$1)
446-
})
447-
}
448-
449440
/// Receives mutation
450441
///
451442
/// - Parameters:
452443
/// - mutation: (`inout` attributes to prevent escaping `Inout<State>` inside the closure.)
453444
@inline(__always)
454445
func _receive_sending<Result>(
455-
mutation: (inout InoutRef<State>, inout Transaction) throws -> sending Result
446+
mutation: (inout InoutRef<State>, inout Transaction) throws -> Result
456447
) rethrows -> sending Result {
457448

458449
let signpost = VergeSignpostTransaction("Store.commit")

Sources/Verge/Store/StoreDriverType.swift

+48-42
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ extension StoreDriverType {
347347
_ file: StaticString = #file,
348348
_ function: StaticString = #function,
349349
_ line: UInt = #line,
350-
mutation: (inout sending InoutRef<Scope>) throws -> Result
350+
mutation: (inout InoutRef<Scope>) throws -> Result
351351
) rethrows -> Result {
352352

353353
let trace = MutationTrace(
@@ -357,9 +357,9 @@ extension StoreDriverType {
357357
line: line
358358
)
359359

360-
return try store.asStore()._receive(
360+
return try store.asStore()._receive_sending(
361361
mutation: { [scope] stateRef, _ -> Result in
362-
try stateRef.map(keyPath: scope) { (ref: inout sending InoutRef<Scope>) -> Result in
362+
try stateRef.map(keyPath: scope) { (ref: inout InoutRef<Scope>) -> Result in
363363
ref.append(trace: trace)
364364
return try mutation(&ref)
365365
}
@@ -376,7 +376,7 @@ extension StoreDriverType {
376376
_ file: StaticString = #file,
377377
_ function: StaticString = #function,
378378
_ line: UInt = #line,
379-
mutation: (inout sending InoutRef<Scope>, inout Transaction) throws -> Result
379+
mutation: (inout InoutRef<Scope>, inout Transaction) throws -> Result
380380
) rethrows -> Result {
381381
let trace = MutationTrace(
382382
name: name,
@@ -385,9 +385,9 @@ extension StoreDriverType {
385385
line: line
386386
)
387387

388-
return try store.asStore()._receive(
388+
return try store.asStore()._receive_sending(
389389
mutation: { [scope] state, transaction -> Result in
390-
try state.map(keyPath: scope) { (ref: inout sending InoutRef<Scope>) -> Result in
390+
try state.map(keyPath: scope) { (ref: inout InoutRef<Scope>) -> Result in
391391
ref.append(trace: trace)
392392
return try mutation(&ref, &transaction)
393393
}
@@ -403,15 +403,15 @@ extension StoreDriverType {
403403
_ file: StaticString = #file,
404404
_ function: StaticString = #function,
405405
_ line: UInt = #line,
406-
mutation: (inout sending InoutRef<Scope>) throws -> Result
406+
mutation: (inout InoutRef<Scope>) throws -> Result
407407
) rethrows -> Result where Scope == TargetStore.State {
408408
let trace = MutationTrace(
409409
name: name,
410410
file: file,
411411
function: function,
412412
line: line
413413
)
414-
return try store.asStore()._receive(
414+
return try store.asStore()._receive_sending(
415415
mutation: { ref, transaction -> Result in
416416
ref.append(trace: trace)
417417
return try mutation(&ref)
@@ -427,15 +427,15 @@ extension StoreDriverType {
427427
_ file: StaticString = #file,
428428
_ function: StaticString = #function,
429429
_ line: UInt = #line,
430-
mutation: (inout sending InoutRef<Scope>, inout Transaction) throws -> Result
430+
mutation: (inout InoutRef<Scope>, inout Transaction) throws -> Result
431431
) rethrows -> Result where Scope == TargetStore.State {
432432
let trace = MutationTrace(
433433
name: name,
434434
file: file,
435435
function: function,
436436
line: line
437437
)
438-
return try store.asStore()._receive(
438+
return try store.asStore()._receive_sending(
439439
mutation: { ref, transaction -> Result in
440440
ref.append(trace: trace)
441441
return try mutation(&ref, &transaction)
@@ -451,8 +451,8 @@ extension StoreDriverType {
451451
_ file: StaticString = #file,
452452
_ function: StaticString = #function,
453453
_ line: UInt = #line,
454-
mutation: sending (inout sending InoutRef<Scope>) throws -> sending Result
455-
) async rethrows -> sending Result {
454+
mutation: sending (inout InoutRef<Scope>) throws -> Result
455+
) async rethrows -> Result {
456456

457457
let trace = MutationTrace(
458458
name: name,
@@ -463,20 +463,21 @@ extension StoreDriverType {
463463

464464
let result = try await store.asStore().writer.perform { [store = self.store, scope] in
465465

466-
let result = try store.asStore()._receive_sending { ref, _ in
466+
let r = try store.asStore()._receive_sending { ref, _ in
467467

468-
let result = try ref.map_sending(keyPath: scope) { ref in
468+
let r = try ref.map_sending(keyPath: scope) { ref in
469469
ref.append(trace: trace)
470-
return try mutation(&ref)
470+
let r = try mutation(&ref)
471+
let workaround = { r }
472+
return workaround()
471473
}
472474

473-
let box = UnsafeSendableStruct(result)
474-
475-
return box.send()
475+
let workaround = { r }
476+
return workaround()
476477
}
477478

478-
let box = UnsafeSendableStruct(result)
479-
return box.send()
479+
let workaround = { r }
480+
return workaround()
480481
}
481482

482483
await self.waitUntilAllEventConsumed()
@@ -492,8 +493,8 @@ extension StoreDriverType {
492493
_ file: StaticString = #file,
493494
_ function: StaticString = #function,
494495
_ line: UInt = #line,
495-
mutation: sending (inout sending InoutRef<Scope>, inout Transaction) throws -> sending Result
496-
) async rethrows -> sending Result {
496+
mutation: sending (inout InoutRef<Scope>, inout Transaction) throws -> Result
497+
) async rethrows -> Result {
497498

498499
let trace = MutationTrace(
499500
name: name,
@@ -504,20 +505,21 @@ extension StoreDriverType {
504505

505506
let result = try await store.asStore().writer.perform { [store = self.store, scope] in
506507

507-
let result = try store.asStore()._receive_sending { ref, transaction in
508+
let r = try store.asStore()._receive_sending { ref, transaction in
508509

509-
let result = try ref.map_sending(keyPath: scope) { ref in
510+
let r = try ref.map_sending(keyPath: scope) { ref in
510511
ref.append(trace: trace)
511-
return try mutation(&ref, &transaction)
512+
let r = try mutation(&ref, &transaction)
513+
let workaround = { r }
514+
return workaround()
512515
}
513516

514-
let box = UnsafeSendableStruct(result)
515-
516-
return box.send()
517+
let workaround = { r }
518+
return workaround()
517519
}
518520

519-
let box = UnsafeSendableStruct(result)
520-
return box.send()
521+
let workaround = { r }
522+
return workaround()
521523
}
522524

523525
await self.waitUntilAllEventConsumed()
@@ -533,8 +535,8 @@ extension StoreDriverType {
533535
_ file: StaticString = #file,
534536
_ function: StaticString = #function,
535537
_ line: UInt = #line,
536-
mutation: sending (inout sending InoutRef<Scope>) throws -> sending Result
537-
) async rethrows -> sending Result where Scope == TargetStore.State {
538+
mutation: sending (inout InoutRef<Scope>) throws -> Result
539+
) async rethrows -> Result where Scope == TargetStore.State {
538540

539541
let trace = MutationTrace(
540542
name: name,
@@ -545,13 +547,15 @@ extension StoreDriverType {
545547

546548
let result = try await store.asStore().writer.perform { [store = self.store] in
547549

548-
let result = try store.asStore()._receive_sending { ref, _ in
550+
let r = try store.asStore()._receive_sending { ref, _ in
549551
ref.append(trace: trace)
550-
return try mutation(&ref)
552+
let r = try mutation(&ref)
553+
let workaround = { r }
554+
return workaround()
551555
}
552556

553-
let box = UnsafeSendableStruct(result)
554-
return box.send()
557+
let workaround = { r }
558+
return workaround()
555559
}
556560

557561
await self.waitUntilAllEventConsumed()
@@ -568,8 +572,8 @@ extension StoreDriverType {
568572
_ file: StaticString = #file,
569573
_ function: StaticString = #function,
570574
_ line: UInt = #line,
571-
mutation: sending (inout sending InoutRef<Scope>, inout Transaction) throws -> sending Result
572-
) async rethrows -> sending Result where Scope == TargetStore.State, Self : Sendable {
575+
mutation: sending (inout InoutRef<Scope>, inout Transaction) throws -> Result
576+
) async rethrows -> Result where Scope == TargetStore.State, Self : Sendable {
573577

574578
let trace = MutationTrace(
575579
name: name,
@@ -580,13 +584,15 @@ extension StoreDriverType {
580584

581585
let result = try await store.asStore().writer.perform { [store = self.store] in
582586

583-
let result = try store.asStore()._receive_sending { ref, transaction in
587+
let r = try store.asStore()._receive_sending { ref, transaction in
584588
ref.append(trace: trace)
585-
return try mutation(&ref, &transaction)
589+
let r = try mutation(&ref, &transaction)
590+
let workaround = { r }
591+
return workaround()
586592
}
587593

588-
let box = UnsafeSendableStruct(result)
589-
return box.send()
594+
let workaround = { r }
595+
return workaround()
590596
}
591597

592598
await self.waitUntilAllEventConsumed()

Sources/Verge/Store/StoreType+BindingDerived.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension StoreDriverType {
8686
get: BindingDerivedPipeline(backingPipeline: pipeline),
8787
set: { [weak self] state in
8888
self?.store.asStore()
89-
._receive { inoutRef, transaction in
89+
._receive_sending { inoutRef, transaction in
9090
transaction.isFromBindingDerived = true
9191
set(&inoutRef, state)
9292
}

0 commit comments

Comments
 (0)