Commit Graph

21434 Commits

Author SHA1 Message Date
Alastair Houghton
d197f38226 [Concurrency] Make currentExecutor return a non-optional.
If we don't have any other executor to return, return the default
executor.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
00e7ef2d21 [Concurrency] Remove EventableExecutor, alter asSchedulable.
EventableExecutor is being removed, for now, but hopefully will
return in some form in the future.

The `asSchedulable` implementation needs to change for reasons of
ABI stability.

rdar://141348916
2025-03-13 13:37:43 +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
23d0ca7a6a [Concurrency] Update header file.
This needed an update to make things build on Linux and Windows.

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
b33666cf08 [Concurrency] Fixes from initial review.
Rename `DispatchTaskExecutor` to `DispatchGlobalTaskExecutor` as we
may want to use the former for an executor that runs things on an
arbitrary Dispatch queue.

Rename `DispatchExecutor` to `DispatchExecutorProtocol`; again, we
might want the name for something else.

Add `@Sendable` attribute to `registerEvent`.

Fix missing `extern "C" SWIFT_CC(swift)` on `_swift_exit` (merge
error).

Remove stray whitespace from `CMakeLists.txt`

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
d14b9370fb [Concurrency] Don't use blocks.
We can't use blocks, because Swift doesn't support them on Linux or
Windows.  Instead, use a C function pointer, and box up the handler.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
ef0e09d0b7 [Concurrency][Embedded] Remove MainActor/MainExecutor everywhere.
Embedded Swift doesn't have MainActor, so remove it.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
229865192f [Concurrency] Rename ExecutorJob back to PartialAsyncTask.
The rename appears to have had some kind of potentially ABI breaking
consequence.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
5ae6de288a [Concurrency] Fix potential ABI breakages.
Fix a couple of potential ABI breaks.  Also add the new functions and types
to the baseline lists.

rdar://141348916
2025-03-13 13:37:36 +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
55afa47bea [Concurrency] More work on the custom executor implementation.
Added an `-executor-factory` argument to the compiler to let you safely
specify the executors you wish to use (by naming a type that returns
them).

Also added some tests of the new functionality.

rdar://141348916
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
Konrad `ktoso` Malawski
8c4dea9802 Revert "[concurrency] Add support for HopToMainActorIfNeededThunk." (#79938)
* Revert "[concurrency] Add support for HopToMainActorIfNeededThunk."

This reverts commit 0e0665bfbd.

* remove some last bits of 0e0665b
2025-03-13 06:48:03 +09:00
Guillaume Lessard
35b851453d [gardening] update some copyright years 2025-03-12 09:56:41 -07:00
Doug Gregor
ad626f9c0e [Stdlib performance] Make integer conversion operations transparent
The integer conversion operations were inlinable, but aren't getting
inlined in debug builds, which results in unreasonably poor
performance. Mark them as transparent so we don't end up with
unspecialized generic code in the hot path.

Fixes https://github.com/swiftlang/swift/issues/78501
2025-03-12 07:40:49 -07:00
Ben Barham
a1a8bde65d [Runtime] Return ConformanceLookupResult from findConformanceWithDyld 2025-03-11 21:30:28 -07:00
Mike Ash
c7922b29af Merge pull request #79774 from mikeash/bigger-empty-va-list-storage
[Stdlib] Make alignedStorageForEmptyVaLists bigger.
2025-03-11 23:10:24 -04:00
Doug Gregor
2efa05d615 Merge pull request #79905 from DougGregor/DougGregor/concurrency-lib-6-2-fix
[Concurrency lib] Stdlib 9999 -> 6.2, where this code would land
2025-03-11 10:56:38 -07:00
Mike Ash
70e1931caa [Stdlib] Make alignedStorageForEmptyVaLists bigger.
Expand alignedStorageForEmptyVaLists to eight Doubles. This produces more predictable output for code that calls a variadic function without parameters where the function still expects them, such as passing an arbitary string to a string formatting function. It's still unsound, but this makes it more predictable.

rdar://145083971
2025-03-11 09:29:07 -04:00
Doug Gregor
733dd86c92 Merge pull request #79896 from DougGregor/strict-memory-safety-cleanups
Strict memory safety cleanups
2025-03-11 01:26:30 -07:00
Doug Gregor
0de53547e5 [Concurrency lib] Stdlib 9999 -> 6.2, where this code would land 2025-03-10 23:07:06 -07:00
Michael Gottesman
04bb69f426 Merge pull request #79727 from gottesmm/pr-025c1133954b74e7b4eda77e1a6f3bcafd4eb6cf
[concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
2025-03-10 22:35:00 -07:00
Konrad `ktoso` Malawski
e056c63c89 [Concurrency] Implement isIsolatingCurrentContext requirement and mode (#79788) 2025-03-11 09:48:38 +09:00
Michael Gottesman
f64dd5a8d5 [concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
We introduce a new macro called #SwiftSettings that can be used in conjunction
with a new stdlib type called SwiftSetting to control the default isolation at
the file level. It overrides the current default isolation whether it is the
current nonisolated state or main actor (when -enable-experimental-feature
UnspecifiedMeansMainActorIsolated is set).
2025-03-10 17:33:45 -07:00
Doug Gregor
53f14688a6 Update strict memory safety annotations for Synchronization module 2025-03-10 15:42:32 -07:00
Doug Gregor
9f2859edd8 Update Cxx library for strict memory safety 2025-03-10 15:42:29 -07:00
Doug Gregor
170845b864 Strict memory safety cleanups for the concurrency library 2025-03-10 15:42:11 -07:00
Doug Gregor
f668feaf64 [Standard library] Additional strict-memory-safety annotations 2025-03-10 15:42:05 -07:00
Guillaume Lessard
940628a23a [stdlib] add newly-required unsafe annotations 2025-03-10 15:20:51 -07:00
Guillaume Lessard
082aaecc9c [stdlib] update availability for CxxSpan (#79883) 2025-03-10 10:13:39 -07:00
Guillaume Lessard
39b4303e79 [stdlib] match KeyValuePairs’s Element type 2025-03-10 08:54:07 -07:00
Guillaume Lessard
83dc08d006 [stdlib] remove an unneeded annotation 2025-03-10 08:54:07 -07:00
Guillaume Lessard
7188d0b187 [stdlib] add span property to KeyValuePairs 2025-03-10 08:54:07 -07:00
Guillaume Lessard
d0d528521a [stdlib] add span property to InlineArray 2025-03-10 08:54:06 -07:00
Guillaume Lessard
264747ac77 [stdlib] add span property to CollectionOfOne 2025-03-10 08:51:56 -07:00
Guillaume Lessard
7bbb8348e3 [stdlib] add span properties to array types 2025-03-10 08:51:56 -07:00
Guillaume Lessard
acdfb3711a [stdlib] refactor lazy-eager-bridging for reusability 2025-03-10 08:51:56 -07:00
Guillaume Lessard
9cdd83b469 [stdlib] add span properties to UnsafeBufferPointer family 2025-03-10 08:51:56 -07:00
Guillaume Lessard
85b53bb023 [stdlib] add bytes property to Span 2025-03-10 08:51:56 -07:00
Doug Gregor
537be30f22 Merge pull request #79785 from DougGregor/isolated-conformances-metadata-runtime 2025-03-09 08:27:40 -07:00
Nate Cook
ff86a69dd7 Add a StdlibUnitTest modifier for requiring a stdlib version (#79838)
It would be great if this could also set the availability for the `code:`
block, but this at least cuts out some boilerplate.
2025-03-08 13:07:20 -06:00
Doug Gregor
d7f687619e Revert "[WebAssembly] Temporarily work around lack of __attribute__((constructor))"
This reverts commit 8ef9f7fcad.
2025-03-08 08:06:28 -08:00
Doug Gregor
8ef9f7fcad [WebAssembly] Temporarily work around lack of __attribute__((constructor))
We don't have a great way to ensure that the current-global-actor hook
will get installed by the concurrency library with WebAssembly, so
temporarily work around the issue by relying on the fact that we also
aren't doing actual concurrency with WebAssembly.
2025-03-07 23:52:25 -08:00
Doug Gregor
296e14662a Rework runtime entrypoints for isolated conformance checking
Replace the pair of global actor type/conformance we are passing around with
a general "conformance execution context" that could grow new functionality
over time. Add three external symbols to the runtime:

* swift_conformsToProtocolWithExecutionContext: a conforms-to-protocol check
  that also captures the execution context that should be checked before
  using the conformance for anything. The only execution context right now
  is for an isolated conformance.
* swift_isInConformanceExecutionContext: checks whether the function is
  being executed in the given execution context, i.e., running on the
  executor for the given global actor.
* swift_ConformanceExecutionContextSize: the size of the conformance
  execution context. Client code outside of the Swift runtime can allocate
  a pointer-aligned region of memory of this size to use with the runtime
  functions above.
2025-03-07 23:52:20 -08:00
Doug Gregor
48aa75d86f [Isolated conformances] Cache resolved global actor for conformances
In the prior implementation of runtime resolution of isolated conformances,
the runtime had to look in both the protocol conformance descriptor and
in all conditional conformance requirements (recursively) to find any
isolated conformances. If it found one, it had to demangle the global
actor type to metadata. Since swift_conformsToProtocol is a hot path through
the runtime, we can't afford this non-constant-time work in the common
case.

Instead, cache the resolved global actor and witness table as part of the
conformance cache, so that we have access to this information every time
we look up a witness table for a conformance. Propagate this up through
various callers (e.g., generic requirement checking) to the point where
we either stash it in the cache or check it at runtime. This gets us down
to a very quick check (basically, NULL-or-not) for nonisolated conformances,
and just one check for isolated conformances.
2025-03-07 23:51:46 -08:00
Doug Gregor
6dd141ad54 Replace dlsym of swift_task_isCurrentGlobalActor with a constructor hook
Following the approach taken with the concurrency-specific type
descriptors, register a hook function for the "is current global actor"
check used for isolated conformances.
2025-03-07 23:51:43 -08:00
Doug Gregor
c266a0965f [Isolated conformances] Check witness tables for conditional requirements
When establishing whether a given conformance is isolated, look through
the witness tables used to satisfy conditional requirements as well. This
is because an otherwise-nonisolated conditional conformance can become
isolated if one of its associated conformance requirements is satisfied
by an isolated conformance.

While here, make sure this code works with variadic generics, too.
2025-03-07 23:51:39 -08:00
Doug Gregor
951b535608 Metadata and runtime support for checking isolated conformances at runtime
Extend the metadata representation of protocol conformance descriptors
to include information about the global actor to which the conformance is
isolated (when there is one), as well as the conformance of that type to
the GlobalActor protocol. Emit this metadata whenever a conformance is
isolated.

When performing a conforms-to-protocol check at runtime, check whether
the conformance that was found is isolated. If so, extract the serial
executor for the global actor and check whether we are running on that
executor. If not, the conformance fails.
2025-03-07 23:51:25 -08:00
Guillaume Lessard
7214717fba Merge pull request #79708 from glessard/span-gardening
[SE-0447] Span and RawSpan tests
2025-03-07 22:00:58 -08:00