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
Change actor destruction to call swift_deallocClassInstance instead of swift_deallocObject. When ObjC interop is enabled, swift_deallocClassInstance will check the "pure swift deallocation" bit and call into the ObjC runtime to destruct the instance when needed. This is what clears weak references and associated objects.
rdar://91270492
Not all targets have a 16-byte type alignment guarantee. For the types
which are not naturally aligned, provide a type specific `operator new`
overload to ensure that we are properly aligning the type on allocation
as we run the risk of under-aligned allocations otherwise.
This should no longer be needed with C++17 and newer which do a two
phase `operator new` lookup preferring
`operator new(std::size, std::align_val_t)` if needed. The base type
would be fully pre-processed away. The empty base class optimization
should help ensure that we do not pay any extra size costs for the
alignment fixes.
As we are a C++14 codebase, we must locally implement some of the
standard type_traits utilities, namely `void_t`. We take the minimal
definition here, assuming that the compiler is up-to-date with C++14 DR
reports which fixed an issue in SFINAE. We use the SFINAE for detecting
the presence of the `operator new` overload to guide the over-alignment,
which is inherited through the new `swift::overaligned_type<>` base
type.
Annotate the known classes which request explicit alignment which is
non-pointer alignment. This list was identified by
`git grep ' alignas(.*) '`.
We don't necessarily have environment variables, which is why we have
SWIFT_STDLIB_HAS_ENVIRON. Calling getenv() outside of a check of this
means Concurrency won't work in environments where getenv() cannot
be used.
rdar://91050064
Reading SE-0329 and this module, two clock types are broadly defined,
"continuous", which advances during suspension, and "suspending", which
does not.
SE-0329 notes the behavior of the clock types on "Darwin and BSD" is
that `CLOCK_MONOTONIC` is "continuous" and `CLOCK_UPTIME` is
"suspending". This is also true for OpenBSD (see
https://man.openbsd.org/clock_gettime).
Update code to match. This buildfixes this platform.
Since the `Actor` type is now `Sendable` via `AnyActor`:
```
/Users/ktoso/code/swift-project/swift/stdlib/public/Concurrency/Actor.swift:38:34: warning: redundant conformance constraint 'Self' : 'Sendable'
public protocol Actor: AnyActor, Sendable {
^
/Users/ktoso/code/swift-project/swift/stdlib/public/Concurrency/Actor.swift:38:24: note: conformance constraint 'Self' : 'Sendable' implied here
public protocol Actor: AnyActor, Sendable {
^
```
I'm making two cleanups here. First, the closure going into
`_runAsyncMain` needs to be `@Sendable` or passing it to the task is not
safe. This will also result in a warning being emitted.
Second, I'm making this @usableFromInline and `internal`. This function
is around for legacy reasons, but it's part of the ABI, so we can't pull
it out entirely, but we don't want folks using it.
When possible, decode the DrainLock/ExecutionLock fields of tasks and actors in concurrency runtimes built with priority escalation, and show the corresponding thread info in swift-inspect output.
We weren't properly decoding actor flags previously, so fix that up as well and have Remote Mirror split them out into separate fields so clients don't have to. We were missing the Job Storage field from the definition of DefaultActorImpl in RuntimeInternals.h, fix that so we actually read the right data.
rdar://88598003
The back-deployed Swift Concurrency library should not contain anything
based on clocks or durations, which aren't always available in the
underlying system. Move that functionality to separate files that are
excluded from the back-deployed concurrency libraries.
This is a partial step to better approximate the back-deployment
libraries. At some point, we'll stop building the back-deployment
libraries entirely and instead use the binaries provided by the
toolchain.
Fixes rdar://89237163.
Have RemoteMirror internally decode these flags fields and return them as separate fields in the task/actor info. Handle the structures both with and without task escalation support.
Also show when a task is the current task on a thread in swift-inspect's task listing.
rdar://88598003
Decode all fields from the various flags values, pass each field as a separate argument to the various signposts. We were just passing the raw value of the flags and requiring the signpost client to decode them, which was ugly and required the client to know details they shouldn't need to know.
Strip ptrauth bits from the task resume function when signposting, when ptrauth is supported.
Add signpost events for continuation init/await/resume events.
We also make task_wait into an interval, rather than a single event. The interval ends when the task resumes. As part of this change, we also skip emitting the interval when the wait completed immediately and the task didn't have to suspend.
While we're in there, clean up a few SWIFT_TASK_DEBUG_LOG lines that emitted warnings when built with the logging enabled.
rdar://88658803
Concurrency tracing was enabled depending on the presence of a header
file, but if a similarly named header was found somewhere in the path
that didn't do the same thing, that might cause problems.
Instead, we should have a build time configuration option.
rdar://89787540
* Audit and correct AsyncSequence Sendability
* Annotate availability on Sendable conformances for AsyncSequences
* Fix typo of Sendable.Iterator
* Correct tests to use sendable builders
* Add @preconcurrency annotations and fixup one remaining missing @Sendable case
* Move preconcurrency to correct syntactical position
* Use unchecked Sendable conditional conformance instead of marking all internals as preconcurrency and sendable
* Use unchecked Sendable conditional conformance instead of marking all internals as preconcurrency and sendable for dropWhile
* claim ABI changes for marking of @preconcurrency as expected
Generated code has never actually initialized this field, so we
might as well remove it. Doing so mostly doesn't impact the ABI
since we don't store anything for arguments or results in the
context as part of the normal call sequence. We do need to adjust
some of the hard-coded contexts, however, such as continuation
contexts and the statically-sized context for special runtime
async functions.
We cannot access the executed job after it has finished executing:
- If it's a non-task job, it is always invalidated; such jobs are
self-owning, and they are expected to destroy themselves after
execution.
- If it's a task, and it completes during execution, it will invalidate
itself synchronously, e.g. by releasing itself. At this point, it
must be assumed that the task memory has been releaed.
- If it's a task, and it hasn't completed during execution, we are
now racing with whatever event *does* complete the task.
Any information we want to log about the job must be recorded when it
starts to run.
rdar://88817560
preprocessing is due to running into a concurrent enqueuer while
draining. However, sometimes we can go into this code path because
compare_exchange_weak failed spuriously. We need to account the fact
that compare_exchange_weak can fail spuriously. Also add more asserts.
Radar-Id: rdar://problem/89236911
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.
* [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>