Skip to content

Commit 38209be

Browse files
committed
Update syncMain implementation
1 parent 4c855cf commit 38209be

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Sources/OpenSwiftUICore/Data/Update.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ package enum Update {
133133
defer { unlock() }
134134
return try body()
135135
}
136-
136+
137+
// 6.5.4
137138
package static func syncMain(_ body: () -> Void) {
138139
#if os(WASI)
139140
// FIXME: See #76
@@ -143,9 +144,25 @@ package enum Update {
143144
body()
144145
} else {
145146
withoutActuallyEscaping(body) { escapableBody in
146-
let context = AnyRuleContext(attribute: AnyOptionalAttribute.current.identifier)
147-
MovableLock.syncMain(lock: _lock) {
148-
context.update(body: escapableBody)
147+
struct Context {
148+
let body: () -> Void
149+
let subgraph: Subgraph?
150+
let context: AnyRuleContext
151+
}
152+
withUnsafePointer(
153+
to: Context(
154+
body: escapableBody,
155+
subgraph: Subgraph.current,
156+
context: AnyRuleContext(attribute: AnyOptionalAttribute.current.identifier)
157+
)
158+
) { context in
159+
_lock.syncMain(.init(context)) { pointer in
160+
let pointer = pointer.assumingMemoryBound(to: Context.self).self
161+
let current = Subgraph.current
162+
defer { Subgraph.current = current }
163+
Subgraph.current = pointer.pointee.subgraph
164+
pointer.pointee.context.update(body: pointer.pointee.body)
165+
}
149166
}
150167
}
151168
}
@@ -206,9 +223,3 @@ package enum Update {
206223
return body()
207224
}
208225
}
209-
210-
// FIXME: migrate to use @_extern(c, "xx") in Swift 6
211-
extension MovableLock {
212-
@_silgen_name("_MovableLockSyncMain")
213-
static func syncMain(lock: MovableLock, body: @escaping () -> Void)
214-
}

0 commit comments

Comments
 (0)