Commit Graph

39 Commits

Author SHA1 Message Date
Philippe Hausler
854fa5c4e3 [Observation] Disable caching of KeyPaths (#78853)
* [Observation] Disable caching of KeyPaths

* Remove the cached keypath annottion for the ObservationTracked peer macro
2025-01-31 13:50:05 -08:00
Philippe Hausler
8462f5c90b [Observation] Optimize the storage of registrar entries, provide KeyPath caching, and uniqueness notification (#78151) 2024-12-16 13:13:19 -08:00
Philippe Hausler
54b3a9b64a [Observation] Optimize cancellation path to avoid excessive copies (#73288) 2024-04-30 14:40:02 -07:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Philippe Hausler
bd3c15e64d Add a utility method for identifying which property changed for tracking events (#71223) 2024-02-01 09:48:31 -08:00
Eric Miotto
28e2f079b5 CMake: on Darwin be explicit about inclusion in the dyld shared cache (#70856)
This entails passing a linker flags to Apple linkers when the standard
library is not meant for inclusion in such cache.

For this to have effect on every library, propagate link flags when
building _Concurrency and Observation.

This is needed for Apple internal configurations.

Addresses rdar://120653968
2024-01-29 09:42:38 -08:00
Philippe Hausler
ed23973e89 [Observation] Add generation for _modify to fields such that we avoid extra CoW (#71122) 2024-01-25 22:51:38 -08:00
Kirby Turner
73ded0f8c4 Update documentation links to the Observable macro and protocol. 2023-07-26 09:52:29 -04:00
Nate Cook
5b9d68b023 Merge branch 'main' into observation_peer_macros 2023-07-19 16:05:43 -05:00
Philippe Hausler
7d37cdf982 [Observation] Tracking adjustments for stability and correctness (#67233)
* [Observation] Correct tracking such that recursive but disperate changes can be tracked without crashing

* [Observation] Adjust the SPI interface for tracking to support deferred cancellation of events and handle both willSet and didSet events
2023-07-18 11:06:43 -07:00
Nate Cook
c5fbb4210e [Obs] Switch to peer instead of arbitrary macros
This adopts `@attached(peer)` for generating an observable type's
underscored storage when expanding the `@ObservationTracked` macro,
instead of using `arbitrary` with the member macro on the
observable type.
2023-07-13 14:30:33 -05:00
Nate Cook
003b335351 [Observation] Switch Observable to be a non-marker protocol (#66993)
With support for redundant conformance declarations via macros,
the `Observable` protocol can be a non-marker protocol, which
provides more flexibility for evolution in the future.

rdar://111463883

This change also switches to the new ExtensionMacro protocol,
the requirement for which includes information about whether the
conformance to the Observable protocol has already been added, either
in the declaration or in a superclass to the macro-attributed type.
This allows the @Observable macro to be applied to subclasses of
observable types without redundant-conformance errors.
2023-07-09 13:09:14 -05:00
Nate Cook
40a7396b03 Make the @Observable macro class only (#67033)
* Make ObservationRegistrar Codable/Hashable

These conformances enable automatic Codable synthesis for Observable
types, and smooth the runway for structs being supported by the
Observable macro in the future.

* Limit Observable macro to classes

This removes the ability for the Observable macro to apply to structs,
and adds diagnostic tests for the three disallowed declaration kinds.
2023-07-06 15:01:01 -05:00
Doug Gregor
6265f0c542 [SE-0395] Rename _Observation module to Observation
The review of SE-0395 is down to small details at this point that won't
affect the overall shape of the API much. Rename the model in
anticipation of that.
2023-06-30 11:01:02 -07:00
Philippe Hausler
c5018f32c1 [Observation] Ensure lock storage rounding works for non-integral lock types (#66832) 2023-06-22 09:19:00 -07:00
Kirby Turner
367a7f6453 Replace fenced code blocks with indentions. 2023-06-14 17:50:57 -04:00
Kirby Turner
837f6e0999 Fix typo. 2023-06-14 17:40:57 -04:00
Kirby Turner
410b77024a Apply suggested coding style. 2023-06-14 16:37:50 -04:00
Kirby Turner
37e6741dd2 Apply review feedback. 2023-06-14 13:53:59 -04:00
Kirby Turner
bf5ecf00ce Add reference documentation to Observation symbols. 2023-06-14 13:26:48 -04:00
Doug Gregor
1209ef89ec Ensure that macros within init accessors are expanded early enough
Now that we've made accessor macro expansion more lazy, ensure that
when querying for init accessors (e.g., to build a memberwise
initializer), we also expand any accessor macros that might produce an
init accessor.

This is a partial step toward the real goal, which is that
`AbstractStorageDecl::getAccessor()` should lazily expand macros if
needed.

Update the Observable macro to document that it produces an `init`
accessor.
2023-06-11 08:48:43 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Philippe Hausler
4d1d8a9de5 [Observation] Add property definite initialization support (#65984)
* [Observation] Transition to peer macros instead of arbitrary members

* [Observation] Lift the initializer requirement by utilizing init accessors for fully formed definite initialization

* [Observation] Gate enabling of peer macros by flag

* [Observation] Enable feature for InitAccessors in the observation tests

* [Observation] Add tests to validate memberwise and definite initialization
2023-06-09 15:15:39 -07:00
Philippe Hausler
d37b6bc074 [Observation] Reduce observation scope to only apply to tracking cases and re-work the macro to utilize more robust emissions (#65528) 2023-05-09 09:28:25 -07:00
Philippe Hausler
7fd2f52af8 [Observation] Refactor for state machine (and behavior robustness) and adjust protocol requirement names (#64414)
* [Observation] Change visibility of observation runtime functions to be hidden

* [Observation] Update API requirements for Observable AsyncSequence names and alter the behavior of value emissions to be based upon transactionality

* [Observation] Slight naming alteration of isolation -> isolatedTo

Note: This re-enables the previously disabled tests since the implementation should be considerably more robust to hangs.
2023-03-16 22:11:23 -07:00
Philippe Hausler
1e4e7f7655 [Observation] Update the SPI entries for SwiftUI for direct tracking access (#64198) 2023-03-08 09:04:54 -08:00
Philippe Hausler
81aa9b51ff [Observation] Add some behaviroal tests for changes, transactions, and tracking (#64179)
* [Observation] Add some behaviroal tests for changes, transactions, and tracking

* Correct transactions to properly suspend when awaiting for changes
2023-03-08 09:04:08 -08:00
Doug Gregor
72357c7aea Disable the _StringProcessing import in the Observation module
Fixes rdar://106374161
2023-03-07 12:39:55 -08:00
Philippe Hausler
bbe45fceb1 [Observation] Correct potential alignment of locks to ensure that os_unfair_lock is properly at an aligned address (#64153) 2023-03-07 09:19:10 -08:00
Doug Gregor
2ac6aba256 Use proper feature check style for this 2023-03-06 12:29:20 -08:00
Doug Gregor
56249ccd47 Enable "Macros" feature in stdlib/Observation for older compilers 2023-03-06 08:50:30 -08:00
Doug Gregor
3321100c23 [Macros] Add #ifs around macro declarations in standard library
Older toolchain compilers don't have macros enabled by default, so we
need to keep these around longer.
2023-03-06 08:15:30 -08:00
Philippe Hausler
d8f552fee8 [Observation] Add names for attached member names for Observable macro (#64069) 2023-03-05 14:11:59 -08:00
Doug Gregor
342184e37d [CMake] Pass C flags through to swiftObservation build. 2023-03-03 16:50:52 -08:00
Doug Gregor
d6962f3db8 We don't need to check SWIFT_OBSERVATION_MACROS 2023-03-03 16:49:09 -08:00
Doug Gregor
72434ac830 The Observation library doesn't depend on swift-syntax any more 2023-03-03 14:59:27 -08:00
Doug Gregor
5786cbd602 [Macros] Make the compiler frontend depend on the macro plugin libraries
The dependency of the Observation library on the observation macro
plugin introduces a direct dependency of a target library on a host
library, (lib -> stdlib) that we'd like to avoid. Instead, make the
Swift frontend binary depend on the macro plugin libraries that we
build, so that it's the complete host-side stack.
2023-03-03 14:58:42 -08:00
Philippe Hausler
40c277b245 Observation and associated macros 2023-03-02 15:30:59 -08:00
Philippe Hausler
8a7f6009b9 Initial draft of observation 2023-02-27 17:09:00 -08:00