Commit Graph

27 Commits

Author SHA1 Message Date
Guillaume Lessard
b661ff8288 [concurrency] fix availability of new Clock symbols 2025-10-16 19:16:19 -07:00
Alastair Houghton
d6224d16d9 [Concurrency] Fix minimal stdlib build again.
Some mentions of `ExecutorJob` were not guarded by the required
`SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY` condition.
2025-08-26 09:38:14 +01:00
Alastair Houghton
871a062002 [Concurrency] Remove canonicalization code.
I don't think we actually need this.  If you have a non-canonical
(i.e. derived) clock, you can just implement `enqueue` and/or `run`
and call those methods on the clock you're wrapping.
2025-08-26 09:38:13 +01:00
Alastair Houghton
6046286b58 [Concurrency] Updates after second SE pitch.
We no longer attempt to convert timestamps from the passed-in `Clock`
in order to allow any clock to work with any executor.  Instead,
executors that do not recognise a clock should call the `enqueue`
function on that `Clock`, which lets the `Clock` itself decide how
to proceed.

Additionally, rename `SchedulableExecutor` to `SchedulingExecutor`.
2025-08-26 09:38:11 +01:00
Alastair Houghton
42ca1b1cc8 Rename SwiftStdlibCurrentOS to StdlibDeploymentTarget.
`StdlibDeploymentTarget` seems to be a better name.

rdar://152498657
2025-06-04 10:40:19 +01:00
Alastair Houghton
28f96e64ab [Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
If you use SwiftStdlibCurrentOS availability, you will be able to
use new types and functions from within the implementation. This
works by, when appropriate, building with the CurrentOS availability
set to the current deployment target.

rdar://150944675
2025-05-12 12:07:24 +01:00
Alastair Houghton
b1c345f1be Merge pull request #80266 from al45tair/custom-executors-take2
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-31 09:53:48 +01:00
Alastair Houghton
47fa71787f Revert "Merge pull request #80224 from glessard/revert-79789-custom-executors"
This reverts commit 06f6358067, reversing
changes made to 033f6679e8.
2025-03-28 10:15:07 +00:00
Allan Shortlidge
2f78ba8828 Sema: Extend _unsafeInheritExecutor_ hack to Clock.measure().
Fixes the bug in `swift::introduceUnsafeInheritExecutorReplacements()` that
prevented the hack from working with `Clock.measure()`. It isn't sufficient to
just check whether the nominal for the type base of a qualified lookup belongs
to the Concurrency module because that type may reference multiple types.
Instead, check all of the directly referenced types to match the behavior of
qualified lookup.

Resolves rdar://132581483.
2025-03-26 21:12:58 -07:00
Alastair Houghton
8b15b05c63 Revert "[Concurrency] Provide a Swift interface for custom main and global executors." 2025-03-22 02:38:11 -07:00
Alastair Houghton
f0defd83bd [Concurrency] Add CooperativeExecutor, use it.
Also tweak the sleep implementations to let the hooks run if there
isn't a `SchedulableExecutor` (for hooked mode).

rdar://141348916
2025-03-17 13:10:35 +00:00
Alastair Houghton
8caa5c5c0d [Concurrency] Add a missing public.
The default implementation of `traits` on `Clock` needs to be `public`.

rdar://141348916
2025-03-14 10:01:37 +00:00
Alastair Houghton
444bbd5b00 [Concurrency] Update following pitch comments.
Remove `supportsScheduling` in favour of a type-based approach.

Update the storage for `ClockTraits` to `UInt32`.

Adjust ordering of executors for `currentExecutor`.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
fc67cc3b60 [Concurrency] Mark expressions as unsafe.
Also fix a missing availability annotation.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
d89ea190bb [Concurrency] Add clock traits.
Remove the hacky support for mapping clocks to a Dispatch clock ID,
in favour of clocks publishing traits and having the Dispatch
executor select the clock on the basis of those traits.
2025-03-13 13:34:41 +00:00
Alastair Houghton
090c375b7b [Concurrency] Swift interface for custom main and global executors.
Reorganise the Concurrency code so that it's possible to completely
implement executors (both main and global) in Swift.

Provide API to choose the desired executors for your application.

Also make `Task.Sleep` wait using the current executor, not the global
executor, and expose APIs on `Clock` to allow for conversion between
time bases.

rdar://141348916
2025-03-13 13:34:41 +00:00
Allan Shortlidge
b85da32707 AST: Promote OptionalIsolatedParameters feature to baseline. 2024-07-09 14:28:29 -07:00
Konrad `ktoso` Malawski
58c5a76836 [Concurrency] TaskGroup.with... APIs using #isolation
move tests to existing actor_withCancellationHandler.swift file
2024-06-24 11:44:44 +09:00
Holly Borla
70d998a1bb [Concurrency] Make OptionalIsolatedParameters a conditionally suppressible
language feature, and suppress it for `Clock.measure`.

This allows the _Concurrency swiftinterface file to continue building with
compilers that do not support `OptionalIsolatedParameters`. The feature
suppression drops the `isolated` keyword and replaces `#isolation` with
`nil`.
2024-03-12 22:56:16 -07:00
Holly Borla
dfa7b866c7 [Concurrency] Clock.measure should inherit actor isolation. 2024-03-12 22:55:34 -07:00
Brandon Williams
e7fc16013e Add Clock.sleep(for:). (#61222) 2023-01-04 20:04:23 -05:00
Nate Chandler
cbaa1b14c8 [Freestanding] Disable Task.sleep. 2022-10-18 11:25:10 -07:00
Karoy Lorentey
6d09bb0613 [stdlib] Adopt primary associated types in _Concurrency 2022-05-09 18:07:09 -07:00
Karoy Lorentey
3136a4abd8 [stdlib] Fix warning on Clock.Duration
rdar://92306564
2022-04-25 18:29:10 -07:00
Karoy Lorentey
0aadfb0444 [stdlib] Add Clock.Duration as an associated type requirement
As [discussed on the forum][forum], we'll likely want to use
`Duration` as the primary associated type on `protocol Clock`;
however, that protocol currently only has `Instant`.

[forum]: https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426/39

To support declaring it as the primary associated type,
`protocol Clock` needs to have `Duration` as an associated type
requirement:

```
@available(SwiftStdlib 5.7, *)
public protocol Clock: Sendable {
  associatedtype Duration: DurationProtocol
  associatedtype Instant: InstantProtocol where Instant.Duration == Duration

  var now: Instant { get }
  var minimumResolution: Instant.Duration { get }

  func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws
}
```

This setup is reminiscent of `Sequence.Element` vs.
`Sequence.Iterator.Element`.

SE-0329 has not yet shipped in an ABI stable release, so we still have
the opportunity to address this.

rdar://91591545
2022-04-11 15:15:26 -07:00
Karoy Lorentey
e0a411ab52 [stdlib] Standard clocks: Fix .now and .minimumResolution implementations
These used to set the clock id incorrectly, leading to zero results. Fix that and also make the underlying entry point abort if it gets an invalid ID, preventing this from reoccurring.
2022-02-19 18:43:32 -08:00
Philippe Hausler
e675b310f8 [SE-0329] Clock/Instant/Duration (#40609)
* [WIP] Initial draft at v2 Clock/Instant/Duration

* Ensure the literal types for _DoubleWide are able to be at least 64 bits on 32 bit platforms

* static cast timespec members to long

* Remove runtime exports from clock functions

* Export clock functions in implementations as they are in headers

* Clean up internal properties by adding leading underscores, refine availability to a TBD marker macro, and break at 80 lines to match style

* Shift operators to concrete Instant types to avoid complexity in solver resolution

* Adjust diagnostic note and error expectation of ambiguities to reflect new potential solver (perhaps incorrect) solutions

* Update stdlib/public/Concurrency/TaskSleep.swift

Co-authored-by: Karoy Lorentey <klorentey@apple.com>

* [stdlib][NFC] Remove trailing whitespace

* [stdlib] Remove _DoubleWidth from stdlib's ABI

* [stdlib] Strip downd _DoubleWidth to _[U]Int128

* Additional adjustments to diagnostic notes and errors expectation of ambiguities to reflect new potential solver (perhaps incorrect) solutions

* Disable type checker performance validation for operator overload inferences (rdar://33958047)

* Decorate Duration, DurationProtocol, Instant and clocks with @available(SwiftStdlib 9999, *)

* Restore diagnostic ambiguity test assertion (due to availability)

* Add a rough attempt at implementing time accessors on win32

* Remove unused clock id, rename SPI for swift clock ids and correct a few more missing availabilities

* remove obsolete case of realtime clock for dispatch after callout

* Use the default implementation of ~ for Int128 and UInt128

* Ensure diagnostic ambiguitiy applies evenly to all platforms and their resolved types

* Restore the simd vector build modifications (merge damage)

* Update to latest naming results for Instant.Duration

* Updates to latest proposal initializers and accessors and adjust encoding/decoding to string based serialization

* Update availability for Clock/Instant/Duration methods and types to be 5.7

* Correct *Clock.now to report via the correct runtime API

* Ensure the hashing of Duration is based upon the attoseconds hashing

* Avoid string based encoding and resort back to high and low bit encoding/decoding but as unkeyed

* Adjust naming of component initializer to use suffixes on parameters

* Duration decoding should use a mutable container for decoding

* fix up components initializer and decode access

* Add platform base initializers for timespec and tiemval to and from Duration

* Add some first draft documentation for standard library types Duration, DurationProtocol and InstantProtocol

* Another round of documentation prose and some drive-by availability fixes

* InstantProtocol availability should be 5.7

* Correct linux timeval creation to be Int and not Int32

Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2022-02-17 09:32:46 -08:00