Skip to content

Commit a530f93

Browse files
committed
Revert "[Observation] ensure event triggers on deinitialization passes as if all properties that are being observed have changed (for weak storage) (swiftlang#79823)"
This reverts commit 9d1d917.
1 parent 918eaa4 commit a530f93

File tree

2 files changed

+4
-49
lines changed

2 files changed

+4
-49
lines changed

stdlib/public/Observation/Sources/Observation/ObservationRegistrar.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,9 @@ public struct ObservationRegistrar: Sendable {
110110
}
111111
}
112112

113-
internal mutating func deinitialize() -> [@Sendable () -> Void] {
114-
var trackers = [@Sendable () -> Void]()
115-
for (keyPath, ids) in lookups {
116-
for id in ids {
117-
if let tracker = observations[id]?.willSetTracker {
118-
trackers.append({
119-
tracker(keyPath)
120-
})
121-
}
122-
}
123-
}
113+
internal mutating func cancelAll() {
124114
observations.removeAll()
125115
lookups.removeAll()
126-
return trackers
127116
}
128117

129118
internal mutating func willSet(keyPath: AnyKeyPath) -> [@Sendable (AnyKeyPath) -> Void] {
@@ -168,11 +157,8 @@ public struct ObservationRegistrar: Sendable {
168157
state.withCriticalRegion { $0.cancel(id) }
169158
}
170159

171-
internal func deinitialize() {
172-
let tracking = state.withCriticalRegion { $0.deinitialize() }
173-
for action in tracking {
174-
action()
175-
}
160+
internal func cancelAll() {
161+
state.withCriticalRegion { $0.cancelAll() }
176162
}
177163

178164
internal func willSet<Subject: Observable, Member>(
@@ -203,7 +189,7 @@ public struct ObservationRegistrar: Sendable {
203189
}
204190

205191
deinit {
206-
context.deinitialize()
192+
context.cancelAll()
207193
}
208194
}
209195

test/stdlib/Observation/Observable.swift

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,6 @@ final class CowTest {
287287
var container = CowContainer()
288288
}
289289

290-
@Observable
291-
final class DeinitTriggeredObserver {
292-
var property: Int = 3
293-
let deinitTrigger: () -> Void
294-
295-
init(_ deinitTrigger: @escaping () -> Void) {
296-
self.deinitTrigger = deinitTrigger
297-
}
298-
299-
deinit {
300-
deinitTrigger()
301-
}
302-
}
303-
304-
305290
@main
306291
struct Validator {
307292
@MainActor
@@ -526,22 +511,6 @@ struct Validator {
526511
expectEqual(subject.container.id, startId)
527512
}
528513

529-
suite.test("weak container observation") {
530-
let changed = CapturedState(state: false)
531-
let deinitialized = CapturedState(state: false)
532-
var test = DeinitTriggeredObserver {
533-
deinitialized.state = true
534-
}
535-
withObservationTracking { [weak test] in
536-
_blackHole(test?.property)
537-
} onChange: {
538-
changed.state = true
539-
}
540-
test = DeinitTriggeredObserver { }
541-
expectEqual(deinitialized.state, true)
542-
expectEqual(changed.state, true)
543-
}
544-
545514
runAllTests()
546515
}
547516
}

0 commit comments

Comments
 (0)