Commit Graph

40 Commits

Author SHA1 Message Date
Philippe Hausler
c6a2437a10 [Observation] Exclude generic class types from pre-caching their keypaths (#78790)
* [Observation] Exclude generic class types from pre-caching their keypaths

* Account for multiple nesting levels of generics for observation cached keypaths
2025-01-21 23:49:37 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Holly Borla
48eb4b7714 [Availability] Lazily expand type refinement contexts for extensions. 2024-02-02 17:34:40 -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
Holly Borla
8c9eeb2edd [ASTScope] In the isBeforeInSource predicate, use the end location of the
original source location of a macro expansion when walking up the ancestor
list.

The original source range of a macro expansion buffer contains the entire
range of the code that is replaced by the expansion. In some cases, the
original code is type checked, so ASTScope needs to represent both the
original code and the macro-expanded code in the scope tree.

For accessor macros, the original code -- the initializer expression of
the property -- is type checked, but not before macro expansion, so
unqualified lookup must deal with the scope tree for the initializer and
the expanded accessors. The accessors are inserted in the tree after the
initializer scope, but the `isBeforeInSource` was using the start location
of the original source range for macro expansions, so the accessor scopes
were incorrectly considered to be ordered before a source location in the
initializer expression, which caused unqualified lookup of local variables
within the initializer to fail.
2023-12-20 15:53:02 -08:00
Allan Shortlidge
2730c19891 Macros: Stop explicitly enabling accepted ExtensionMacros feature in tests.
NFC.
2023-12-10 10:10:15 -08:00
Slava Pestov
d579a76581 Sema: Break request cycle when building TypeRefinementContexts
This fixes a recent regression introduced in the changes to make
TRC construction lazier in b33a71d64f.

Calling VarDecl::hasInitialValue() can ask for attached property
wrappers, which can trigger macro expansion. However, macro
expansion can result in TRC construction, causing a cycle.

Instead, just always build a lazy TRC for the initializer. It
might not be needed, but it's safest to not ask anything of the
VarDecl at all.

Fixes rdar://118452948.
2023-12-01 22:49:20 -05:00
Saleem Abdulrasool
99453fc2e8 test: introduce a new %swift-plugin-dir macro
Use this to define the macro location rather than the "host" dir (which
is actually for the build and not the host).  Furthermore, on Windows,
the build dir is /usr/lib/swift as the host content is in the SDK.

This prepares the tests for Windows.
2023-09-04 13:04:18 -07:00
Doug Gregor
5d6746d974 Improve checking of macro-generated accessors against documented names
The checking of the accessors generated by a macro against the
documented set of accessors for the macro is slightly too strict and
produces misleading error messages. Make the check slightly looser in
the case where an observer-producing macro (such as
`@ObservationIgnored`) is applied to a computed property. Here, we
would diagnose that the observer did not in fact produce any
observers, even though it couldn't have: computed properties don't get
observers. Remove the diagnostic in this case.

While here, add some tests and improve the wording of diagnostics a
bit.

Fixes rdar://113710199.
2023-08-17 16:59:42 -07:00
Doug Gregor
5edfc26156 Remove unnecessary --enable-experimental-feature InitAccessors from tests
This feature was accepted, so we no longer need to pass this flag. Worse,
it triggers errors in non-Asserts compilers. Fixes rdar://113708096.
2023-08-16 09:00:39 -07:00
Allan Shortlidge
024ed957cd NFC: Re-enable ObservableAvailabilityCycle.swift test. 2023-08-08 15:58:08 -07:00
Slava Pestov
c9225db156 Disable test/stdlib/Observation/ObservableAvailabilityCycle.swift 2023-08-04 10:20:04 -04:00
Doug Gregor
c098175059 Add test case involving circular references with @Observable
Add a test case for Observable types that are extended from other
source files. Prior to the recent changes to make
`TypeRefinementContext` more lazy, this would trigger circular
references through the `TypeRefinementContextBuilder`.

Finishes rdar://112079160.
2023-08-02 15:07:09 -07:00
Pavel Yaskevich
2a0651e8b0 [Frontend/NFC] SE-0400: Enable InitAccessors feature by default 2023-07-31 13:18:59 -07:00
Philippe Hausler
0fca5199e7 [Observation] Forward availability and defines to extensions (#67412)
* [Observation] Forward availability and defines to extensions

* Simplify availability slightly from review feedback

* Simplify availability for extensions to use `.with`
2023-07-26 08:46:57 -07:00
Nate Cook
e68395c923 Disable diagnostic test again for now 2023-07-21 09:29:20 -05:00
Nate Cook
90d341421e Remove dump-macro flag in test 2023-07-19 16:07:13 -05: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
e36e316b05 Add diagnostic test for @Observable macro (#67250)
This adds a diagnostic test that validates errors for putting
the `@Observable` macro on a struct, enum, or actor.
2023-07-13 11:27:52 -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
Doug Gregor
606db016e6 Merge pull request #66730 from DougGregor/observable-willset-didset
[Macros] Add test using observer accessors (didSet/willSet) with Observable
2023-06-23 14:18:44 -07:00
Doug Gregor
814e5205e9 [Observable] Test macro through the plugin server 2023-06-21 13:43:10 -07:00
Doug Gregor
504b76a7ab [Macros] Add test using observer accessors (didSet/willSet) with Observable
At one point this gave us trouble, but it's since been fixed. Add the
test to make sure we don't regress. Covers rdar://109231047.
2023-06-16 22:53:27 -07:00
Hamish Knight
3f401fb134 [test] Require asserts for a couple of tests 2023-06-15 12:28:55 +01: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
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
ddbab22d88 [Observation] Member properties that have visibility attributes should rename using trailing trivia (#65812) 2023-05-18 11:36:47 -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
Doug Gregor
10027fbab1 [Macros] Add test that triggered a reference cycle.
Fixes rdar://108565923.
2023-04-28 08:36:05 -07:00
Ben Barham
e5a28caa9a [Test] Fix swift_swift_parser feature and use in tests
The macro tests were all using "REQUIRES: OS=macosx" as a proxy for
"have the Swift Swift parser". There was an existing feature for this,
but it was just checking whether the path was passed through. Fix that
to use the same variable as in CMake.

Also remove all extraneous `-I` and `-L` to the host libs in the target
invocations.
2023-04-03 09:25:03 -07:00
Philippe Hausler
ddeb10e53c [Observation] Restrict tests for observation to only use built stdlib's and not test in back-deployment 2023-03-30 12:41:32 -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
5c8b2ea30c [Observation] Disable some of the tests for now 2023-03-14 09:28:57 -07: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
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