Commit Graph

3245 Commits

Author SHA1 Message Date
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
Mike Ash
e89de6e7e0 Merge pull request #67252 from mikeash/remove-foundation-tests
[Test] Remove stdlib/NSStringAPI.swift and some supporting code.
2023-07-17 11:45:49 -04: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
Mike Ash
ea6a2e26f2 [Test] Remove stdlib/NSStringAPI.swift and some supporting code.
This is testing the Foundation overlay, which is no longer part of the Swift project.
2023-07-12 12:18:58 -04: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
Max Desiatov
bc783c4601 test/stdlib: cover wasm32 in FloatingPointIR.swift (#67138)
This makes sure that floating point IR doesn't regress when targeting wasm32.
2023-07-06 10:17:16 +01: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
Yuta Saito
cadc20cf3a [test] Make KeyPath test pointer-size agnostic part 2 2023-06-29 06:02:48 +00:00
Alejandro Alonso
0bb142f1fc Merge pull request #66870 from Azoy/keypath-offset-spi-fix
[stdlib] Add support for classes in _createOffsetBasedKeyPath
2023-06-26 11:24:45 -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
Alejandro Alonso
d9d26eec9d Add support for classes in _createOffsetBasedKeyPath 2023-06-22 14:07:41 -07:00
Doug Gregor
814e5205e9 [Observable] Test macro through the plugin server 2023-06-21 13:43:10 -07:00
Yuta Saito
5cf10f29e0 [test] Make KeyPath test pointer-size agnostic
The field offset of the `age` property is 16 bytes on 64-bit platforms
but not on other pointer-sized platforms.
2023-06-20 17:45:15 +00: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
Stephen Canon
185820a148 Fix sign of fractional units in Duration initializers from Double. (#66582)
* Fix sign of fractional units in Duration initializers from Double.

When separating a double duration into integral and fractional parts, we got the sign wrong. This fixes that bug.

* Fixup variable name.
2023-06-13 08:46:46 -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
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
Hamish Knight
7a137d6756 [CS] Allow ExprPatterns to be type-checked in the solver
Previously we would wait until CSApply, which
would trigger their type-checking in
`coercePatternToType`. This caused a number of
bugs, and hampered solver-based completion, which
does not run CSApply. Instead, form a conjunction
of all the ExprPatterns present, which preserves
some of the previous isolation behavior (though
does not provide complete isolation).

We can then modify `coercePatternToType` to accept
a closure, which allows the solver to take over
rewriting the ExprPatterns it has already solved.

This then sets the stage for the complete removal
of `coercePatternToType`, and doing all pattern
type-checking in the solver.
2023-06-07 00:35:01 +01:00
Mike Ash
01300a6f86 [Runtime] Fix memory leak in -[__SwiftNativeNSError description] for large error values.
Balance the call to allocateBufferIn with a call to deallocateBufferIn. When an error value is small, the missing deallocateBufferIn doesn't do anything. But when the error value is a larger struct that doesn't fit inline, we need deallocateBufferIn to avoid leaking the allocation.

rdar://109933822
2023-06-01 12:54:19 -04:00
Stephen Canon
db0a7287a5 Rework the .seconds, .milliseconds, and .microseconds constructors to preserve exact values (#66111)
When constructing a Duration from Double, we should do it in such a way that exact integer inputs are preserved exactly, so long as they are represented as a Duration. This was not previously the case. Now it is.
2023-05-24 23:07:17 -04: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
Pavel Yaskevich
a987861d1c Merge pull request #65806 from xedin/rdar-108977234
[CSSimplify] Detect and diagnose conformance failures related to AnyHashable conversion
2023-05-16 09:56:41 -07:00
Pavel Yaskevich
58ffca8f74 [ConstraintSystem] Don't produce partially matching note if none of the overloads matched 2023-05-09 14:11:38 -07:00
Nate Cook
89b9e48eae [stdlib] Implement Never conformance to Codable (#64899)
Proposed as SE-0396: Conform Never to Codable;
approved on 5/5/2023.
2023-05-09 13:10:10 -05: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
Alejandro Alonso
73e749d985 Merge pull request #65594 from Azoy/identitycastthing
[stdlib] Add a conditional identity cast
2023-05-03 16:17:45 -07:00
Alejandro Alonso
4c8c828889 Rename to _specialize 2023-05-03 09:41:09 -07:00
Mike Ash
a6bab7332d [Reflection] Handle -disable-reflection-names in _forEachField.
Invoke our callback with an empty name string when reflection names are disabled, rather than throwing a fatal error.

rdar://108709009
2023-05-03 08:55:28 -04:00
Alejandro Alonso
e381815580 Add a conditional identity cast 2023-05-02 13:37:08 -07:00
Karoy Lorentey
32811bac9f Merge pull request #65471 from lorentey/adopt-pointerBitwidth
[stdlib] Adopt _pointerBitWidth conditional
2023-04-28 13:58:28 -07:00
Doug Gregor
10027fbab1 [Macros] Add test that triggered a reference cycle.
Fixes rdar://108565923.
2023-04-28 08:36:05 -07:00
Karoy Lorentey
b82ce9c3be [stdlib] Adopt _pointerBitWidth conditional 2023-04-27 13:33:24 -07:00
Alejandro Alonso
3360e41c9c Add SPI to reroot a keypath for a given superclass 2023-04-24 17:15:28 -07:00
Egor Zhdan
a785ea18d6 Fix symbol-visibility-linux.test-sh on CentOS
rdar://108041802
2023-04-15 00:31:27 +01:00
Doug Gregor
2bcef82eb5 Merge pull request #65032 from DougGregor/attached-macro-mangle-without-cycles 2023-04-12 12:58:35 -04:00
Alejandro Alonso
6ec8a8c60f Merge pull request #64904 from Azoy/keypath-create-spi
[stdlib] Create an offset based keypath at runtime
2023-04-12 09:24:40 -07:00
Doug Gregor
fb82b8f711 Fix Linux flaky test completely 2023-04-11 23:40:32 -04:00
Doug Gregor
097ecfd545 Fix fragile test 2023-04-11 23:40:32 -04:00
Karoy Lorentey
a1dae65528 [stdlib] Adjust availability of _CharacterRecognizer conformances
These never made it to 5.8, so their availability needs to be bumped to 5.9.
2023-04-11 16:43:06 -07:00
Nate Chandler
68a35726ce [Test] Simplified two test cases.
Now that Array is eagerMove, a different type needs to be used to test
the behavior of `consume` regarding uniqueness.  Used a class and
otherwise restored the test case to its previous usage of consume,
replacing `._buffer.isUniquelyReferenced()` with `_isUnique_native`.

rdar://107642615
2023-04-05 08:15:27 -07:00
Nate Chandler
90f7af22c9 [SILOpt] Run DestroyAddrHoisting in mandatory.
Run DestroyAddrHoisting in the pipeline where DestroyHoisting was
previously running.  Avoid extra ARC traffic that having no form of
destroy hoisting in the mandatory pipeline results in.

rdar://90495704
2023-04-04 11:11:34 -07:00
Alejandro Alonso
3522a338a2 Create function to create an offset based keypath at runtime 2023-04-04 09:44:18 -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
swift-ci
9a55a9d1b6 Merge pull request #64782 from phausler/pr/observation_test_supported_targets
[Observation] Restrict tests for observation to only use built stdlib's and not test in back-deployment
2023-03-30 17:33:34 -07:00
nate-chandler
5e0267b9b7 Merge pull request #64553 from nate-chandler/eagermove_collections
[stdlib] Collection types are eagerMove.
2023-03-30 16:16:26 -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
Nate Chandler
cda365ca8d [stdlib] Collection types are eagerMove.
Types that have "value semantics" should not have lexical lifetimes.
Value types are not expected to have custom deinits. Are not expected to
expose unsafe interior pointers. And cannot have weak references because
they are structs. Therefore, deinitialization barriers are irrelevant.

rdar://107076869
2023-03-30 11:04:47 -07:00