Commit Graph

141 Commits

Author SHA1 Message Date
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
Rintaro Ishizaki
de4370bba6 Merge pull request #68225 from rintaro/cmake-macroplugins-disabled
[CMake] Handle cases where Swift parser integration is disabled in Linux
2023-08-30 22:32:13 -07:00
Rintaro Ishizaki
ad2dacd404 [CMake] Handle cases where Swift parser integration is disabled in Linux
When Swift parser integration is disabled (i.e. NOT SWIFT_SWIFT_PARSER),
macro plugins targets are not created. So CMake should bail out.
2023-08-30 14:05:41 -07:00
Rintaro Ishizaki
8049922861 [CMake] Update host platform check for macro support
"Support Macros in Linux" patches was inconsistent with checking
platforms. Some only checked 'LINUX' but some matches
'LINUX|ANDROID|OPENBSD|FREEBSD'. Although I don't have tested other
platoforms than Linux at all, there's no reason to limit it to Linux.
So use the consistent check to match 'LINUX|ANDROID|OPENBSD|FREEBSD'
2023-08-30 13:52:37 -07:00
Rintaro Ishizaki
2a2787b2d0 Avoid adding redundant temporary RUNPATH to builder's stdlib
Many shared libs and executables are only run after stdlib/runtime are
built. They don't need to link with builders stdlib at all.
2023-08-24 23:10:20 +00:00
Rintaro Ishizaki
9c9010e5b7 [CMake] Support Macros in Linux
For compiling codes required for macro support, we now need swiftc
compiler in the build machine.

Unlike Darwin OSes, where swiftCore runtime is guaranteed to be present
in /usr/lib, Linux doesn't have ABI stability and the stdlib of the
build machine is not at the specific location. So the built compiler
cannot relies on the shared object in the toolchain.
2023-08-24 17:04:15 +00: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
Holly Borla
d03ef5ad99 [Macros] Replace all uses of the ConformanceMacro protocol with ExtensionMacro. 2023-08-04 22:32:30 -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
5be3dee066 Drop the fancy functional stuff 2023-03-03 21:39:19 -08:00
Doug Gregor
d841369d7b [OptionSet] Try harder to appease older compilers 2023-03-03 21:39:19 -08:00
Doug Gregor
6310204e1a Make OptionSetMacro build with older Swift compilers.
My, how the language has grown.
2023-03-03 21:39:19 -08:00
Doug Gregor
0e9c3eff8a [Macros] Add OptionSet and plumb it through 2023-03-03 21:39:16 -08:00
Doug Gregor
e9ebcba6af Fix install path for macro plugin libraries 2023-03-03 17:26:35 -08:00
Doug Gregor
8a16c8b18c [CMake] Don't try to modify a macro target when it wasn't built 2023-03-03 15:01:00 -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
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