Skip to content

Commit 510f2c8

Browse files
Updated description of behavior of the task-locals, according to modifications requested during review (#2605)
1 parent 2768756 commit 510f2c8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

proposals/0371-isolated-synchronous-deinit.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,16 @@ Ad-hoc job created for isolated synchronous deinit is executed outside a task, s
326326
327327
### Task-local values
328328
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.
330332
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.
332339
333340
Note that any existing hopping in overridden `retain`/`release` for UIKit classes is unlikely to be aware of task-local values.
334341
@@ -513,6 +520,10 @@ a.enqueue { aIsolated in
513520
This comes with a performance cost, which is unlikely to be beneficial to most of the users.
514521
Leaving behavior of the task-locals undefined allows to potentially change it in the future, after getting more feedback from the users.
515522

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+
516527
### Implicitly propagate isolation to synchronous `deinit`.
517528

518529
This would be a source-breaking change.

0 commit comments

Comments
 (0)