Advanced observation tracking (#86719)
This is the implementation for
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0506-advanced-observation-tracking.md
and additionally two bug fixes around termination events.
This adds two new entry points for tracking observations. One new
one-shot api that has a new options parameter for controlling events and
one new continuous form that is a callback version of Observations.
Bug fixes:
Previously `Observations` had a very small but still present window of
opportunity during deinitialization to miss an event and leave the
AsyncSequence never emitting a final event but never finishing.
Primarily this could occur when a weakly referenced `@Observable` type
was deinitialized from another isolation than the observation itself.
This current implementation leverages the new options parameter to
account for the deinitailization.
Both `Observations` and `withObservationTracking` where susceptible to a
very small race condition where there was a window of opportunity of a
secondary isolation to mutate a tracked property while the setup of the
observation was being called. Self isolation mutation during the setup
cannot be reported since that would distinctly cause recursive failures
in both observation based code but also code like SwiftUI using it so
the same isolation must be ignored, however external isolation changes
have now been addressed by verifying the tracking lists against the
potential "dirty-ness" of a property. This fixes
https://github.com/swiftlang/swift/issues/83359.