Commit Graph

45 Commits

Author SHA1 Message Date
Jamie
21b57f7856 [fix][Observation]: further attempts to resolve macro expansion
interaction with comments

Adds logic to insert newlines in various places to try and resolve the
fact that the current expansion produces invalid code in some cases
depending on comment location. Adds some basic tests of the expansion
output.
2025-10-25 20:39:43 -05:00
Zev Eisenberg
0d1e482cfe [Observation] fix bug where a comment in an annotation would result in invalid macro expansion. The comment was 'eating' the generated variable declaration, preventing it from being visible to the compiler. 2025-10-11 16:35:59 -05:00
Doug Gregor
fed18d58dc [Observation] Create nonisolated conformances to Observable
This is needed to make default-main-actor mode work well with
Observable. Fixes rdar://150419628.
2025-05-01 22:01:41 -07:00
Philippe Hausler
2381d394db [Observation] forward line numbers to didSet and other property observers from their spelled location to the code-generated duplicated storage location (#80661)
* [Observation] forward line numbers to didSet and other property observers from their spelled location to the code-generated duplicated storage location

* Only emit source locations for the prolog of the body and emit an empty location for the epilog

* Add missing attribute member

* Use the fixed version of the locations since swift-syntax 6.0.1 reports sub-nodes correctly in all contexts
2025-04-18 13:41:21 -07:00
Philippe Hausler
a3d699241c [Observation] Reduce the scope of the observation shouldNotifyObservers to only apply to observation and not side effects of accessors like willSet or didSet (#79518) 2025-02-21 11:32:19 -08:00
Allan Shortlidge
1675098e8c Observation: Fix warnings about unused variables. 2025-02-01 10:28:27 -08:00
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
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
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
Allan Shortlidge
5257747b1b Macros: Implement expansion(of:providingMembersOf:conformingTo:in:) on MemberMacros.
Resolves a warning about using a deprecated default implementation.
2024-10-16 16:35:54 -07:00
Allan Shortlidge
977ef19ec7 ObservationMacros: Suppress a unreachable default warning. 2024-10-16 16:33:14 -07:00
Hamish Knight
955c56c7c1 [Macros] Remove SwiftOperators dependency 2024-07-20 15:14:49 +01:00
Rintaro Ishizaki
1fb78394ce [Macros] Remove unused dependency to SwiftOperators
ObservationMacros and SwiftMacros don't use anything in SwiftOperators
2024-06-17 15:39:03 -07:00
treastrain / Tanaka Ryoga
a1c49d0139 @Observable Macro supports properties with the package access modifier (#71061)
* `@Observable` Macro supports properties with the `package` access modifier #71060

* Cherry-pick "Move the tests for package scopes to the module interface tests" 4e274ce0a5

---------

Co-authored-by: Philippe Hausler <phausler@apple.com>
2024-04-09 13:32:03 -07:00
Allan Shortlidge
28b274c6b3 Observation: Stop using deprecated SwiftSyntax APIs.
Addresses a few warnings about use of `as()`:

```
warning: 'as' is deprecated: This cast will always succeed
```
2024-03-13 10:16:49 -07: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
Stephen Celis
541716d3f0 Update ObservableMacro.swift 2023-11-03 11:19:12 -07:00
Stephen Celis
7d24379db9 Clean up formatting of Observable macro
Currently the macro preserves some trivia it shouldn't, and has inconsistent indentation.
2023-11-03 11:13:59 -07:00
Ben Barham
041691184c [CMake] Replace early swift-syntax with FetchContent
Use FetchContent to include swift-syntax directly in swift. This can be
thought of as an `add_subdirectory` for a directory outside the root.

The default build directory will be `_deps/swiftsyntax-subbuild/`, though
the modules and shared libraries will be built in `lib/swift/host` by
passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we
were doing previously.
2023-09-18 14:44:10 -07:00
Manu
02b5fa2c8e Fix some typos in the codebase 2023-08-31 18:50:10 -03:00
Alex Hoppen
8231b272ba [ASTGen/Macros] Update for the fact that syntax collections are always non-optional in SwiftSyntax now 2023-08-11 07:46:59 -07:00
Alex Hoppen
d239cac1a7 Merge pull request #67716 from ahoppen/ahoppen/swift-syntax-deprecations
[Macros/ASTGen] Fix deprecation warnings from SwiftSyntax
2023-08-04 20:47:21 -07:00
Alex Hoppen
62db3d5ad2 [Macros] Fix SwiftSyntax deprecation warnings 2023-08-03 10:44:09 -07:00
Alex Hoppen
10e7312b9f Remove a leftover print statement 2023-08-03 08:18:32 -07:00
Alex Hoppen
b92530f50b Merge pull request #67500 from ahoppen/ahoppen/accessor-refactoring
Adjustments for refactoring of representation of Accessors in SwiftSyntax
2023-08-01 06:34:24 -07:00
Alex Hoppen
4bc5fe0c6a Adjustments for refactoring of representation of Accessors in SwiftSyntax 2023-07-26 14:24:02 -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
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
Philippe Hausler
c3af373628 [Observation] Avoid using T since it is a common generic name, instead use a very specific generic return value name (#67207) 2023-07-12 15:34:42 -07:00
Pavel Yaskevich
4760b95282 Merge pull request #67183 from xedin/convert-effects-into-storageRestrictions
[AST/Sema] Implement @storageRestrictions attribute
2023-07-11 11:57:14 -07: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
Pavel Yaskevich
fe17491982 [AST] InitAccessors: Switch from init accessor effects (initializes/accesses) to @storageRestrictions 2023-07-07 10:00:36 -07: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
04ecc35d35 [Observation] Ensure type access is qualified to the module name (#66364) 2023-06-09 19:21:08 -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
Alex Hoppen
42cb41ded9 Adjustment for SwiftSyntax rename members -> memberBlock
Companion of https://github.com/apple/swift-syntax/pull/1524
2023-04-13 16:28:54 -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
Rintaro Ishizaki
f9fba6ce3e [CMake] Move add_pure_swift_host_library to a file
* Move `add_pure_swift_host_library()` from lib/CMakeLists.txt to
  AddPureSwift.cmake so that code outside `lib` can use it
* Add `add_pure_swift_host_tool()` function to make a pure Swift
  host executable target (for future usages)
* Specify depending `SwiftSyntax` modules explicitly because not all
  Swift libraries uses all SwiftSyntax libraries
2023-03-13 19:28:13 -07:00
Nate Cook
71a6c07b90 Update type name in Observable macro (#64067)
Switch macro-generated code to `TrackedProperties`.
2023-03-05 14:12:26 -08:00
Doug Gregor
6b0a0b6555 [CMake] Rework build of ASTGen and ObservationMacros
Refactor the build support for ASTGen and ObservationMacros. Both have
nearly-identical copies of a bunch of messy, workaround-laden CMake
code to build "pure" Swift host libraries using CMake's Swift support.

Instead, introduce `add_pure_swift_host_library` to centralize all of
the hacks to build a host library that's all Swift, using CMake's
support directly (rather than custom commands), and link against the
swift-syntax stack. Switch ASTGen directly over to this.

Add `add_swift_macro_library` on top of this, to make it easy to
create a macro library and install it into the appopriate plugin
directory. Switch ObservationMacros over to this.
2023-03-03 14:01:30 -08:00
Philippe Hausler
09bb89659e Ensure the install of the libObservationMacros.dylib is housed in lib/swift/host/plugins 2023-03-02 18:47:22 -08:00
Philippe Hausler
40c277b245 Observation and associated macros 2023-03-02 15:30:59 -08:00