You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/0371-isolated-synchronous-deinit.md
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,9 +326,16 @@ Ad-hoc job created for isolated synchronous deinit is executed outside a task, s
326
326
327
327
### Task-local values
328
328
329
-
This proposal does not define how Swift runtime should behave when running isolated deinit. It may use task-local values as seen at the point of the last release, reset them to default values, or use some other set of values. Behavior is allowed to change without notice. But future proposals may change specification by defining a specific behavior.
329
+
Task-local values set by the task/thread that performed last release are blocked inside isolated deinit.
330
+
Attempting to read such task-local inside isolated deinit will return a default value without any runtime warnings.
331
+
Task-local values set inside the body of the isolated deinit are visible for the corresponding scope.
330
332
331
-
Client code should not depend on behavior of particular implementation of the Swift runtime. Inside isolated `deinit` it is safe to read only the task-local values that were also set inside the `deinit`.
333
+
This behavior ensures that isolated deinit behaves the same way both when running inline and when hopping, without high runtime costs for copying task-local values.
334
+
335
+
The point of the last release of the object can be hard to predict and can be changed by optimizations, leading to different behavior between debug and release builds.
336
+
Because of this, developers are discouraged from depending on the set of task-local values available at the point of the last release.
337
+
Instead of using task-local values, developers are advised to inject dependencies into deinit using the object's stored properties.
338
+
This advice applies to non-isolated deinit as well, but this proposal does not change the behavior of the non-isolated deinit.
332
339
333
340
Note that any existing hopping in overridden `retain`/`release` for UIKit classes is unlikely to be aware of task-local values.
334
341
@@ -513,6 +520,10 @@ a.enqueue { aIsolated in
513
520
This comes with a performance cost, which is unlikely to be beneficial to most of the users.
514
521
Leaving behavior of the task-locals undefined allows to potentially change it in the future, after getting more feedback from the users.
515
522
523
+
### Keeping behavior of task-local values undefined
524
+
525
+
Approach of 'make no promises' is likely to result in users inadvertently relying on implementation details which would turn out to be difficult to change later.
526
+
516
527
### Implicitly propagate isolation to synchronous `deinit`.
0 commit comments