Commit Graph

17049 Commits

Author SHA1 Message Date
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
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
082aaecc9c [stdlib] update availability for CxxSpan (#79883) 2025-03-10 10:13:39 -07: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
nate-chandler
c0ba520fac Merge pull request #79781 from nate-chandler/general-coro/20250227/1
[CoroutineAccessors] Dispatch and PtrAuth.
2025-03-07 20:08:42 -08:00
Ben Rimmington
e5487d86f0 Merge pull request #79800 from benrimmington/inline-array
[stdlib] Update `InlineArray`
2025-03-08 02:32:44 +00:00
Konrad `ktoso` Malawski
fda7f539fb Reapply "Task names" (#79562) (#79600) 2025-03-08 10:58:49 +09:00
Guillaume Lessard
4ec8c6e345 [stdlib] document unsafe behaviour for empty spans 2025-03-07 13:23:25 -08:00
Guillaume Lessard
3bd04acadb Apply suggestions from code review 2025-03-07 13:23:25 -08:00
Guillaume Lessard
5f24c66ea7 [stdlib] define properties also for ~Escapable elements
These should be available for any type of element `Span` can have in the future, including non-escapable elements. Making this change now avoids future churn.

Addresses rdar://146130842
2025-03-07 13:23:24 -08:00
Evan Wilde
28f96411c9 Merge pull request #79778 from etcwilde/ewilde/yo-dawg-heard-you-liked-swift
CMake: option to disable swift in swift
2025-03-07 13:12:00 -08:00
Ben Rimmington
aa64816b98 Merge branch 'main' into inline-array 2025-03-07 20:31:04 +00:00
Guillaume Lessard
077a01f807 Merge pull request #79813 from glessard/unchecked-bounds-are-unsafe
[stdlib] Unchecked bounds are unsafe
2025-03-07 12:20:05 -08:00
Nate Chandler
6581fec9e1 [CoroutineAccessors] PtrAuth. 2025-03-07 11:46:51 -08:00
Nate Chandler
35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Evan Wilde
ddaf003c56 Get stdlib building again
PR 79186 (https://github.com/swiftlang/swift/pull/79186) moved one of
the mandatory passes from the C++ implementation to the Swift
implementation resulting in a compiler that is unable to build the
standard library. The pass used to ensure that inaccessible control-flow
positions after an infinite loop was marked with `unreachable` in SIL.
Since the pass is no longer running, any function that returns a value
that also has an infinite loop internally must place a fatalError after
the infinite loop or it will fail to compile as the compiler will
determine that the function does not return from all control flow paths
even though some of the paths are unreachable.
2025-03-06 13:32:54 -08:00
Doug Gregor
0ec13f9a90 Build compiler and runtimes without Swift
Remove dependency on macros from compiler and stdlib build when
bootstrapping the compiler without Swift available.
2025-03-06 13:32:52 -08:00
Ben Rimmington
30e167b499 [stdlib] Add unchecked subscript to InlineArray 2025-03-06 19:25:50 +00:00
Ben Rimmington
d0bab4082d [stdlib] Add isEmpty property to InlineArray 2025-03-06 19:25:50 +00:00
Ben Rimmington
428d269a18 [stdlib] Use Index typealias of InlineArray 2025-03-06 19:25:50 +00:00
Ben Rimmington
23e1741978 [stdlib] Update doc comments of InlineArray
- Write an overview of the type.
- Amend summaries of the initializers.
- Remove inapplicable example code.
- Add "Complexity: O(*n*)" to initializers.
- Add "Complexity: O(1)" to indexing APIs.
- Add FIXME comments.
2025-03-06 19:25:50 +00:00
Guillaume Lessard
dfb2e2f12e [stdlib] annotate uses of Range.init(_uncheckedBounds:) 2025-03-05 18:52:11 -08:00
Guillaume Lessard
eed9c46116 [stdlib] mark _uncheckedBounds range inits as unsafe 2025-03-05 18:51:27 -08:00
Guillaume Lessard
66adb21502 [stdlib] annotate Span and RawSpan unsafe initializers 2025-03-05 17:15:03 -08:00
Guillaume Lessard
bd32aa5f6e [stdlib] remove an extracting overload
- `RangeExpression` implicitly involves bounds checking, so this was misleading.
2025-03-05 17:15:03 -08:00
Guillaume Lessard
712c79c711 [gardening] 80-column vigilance 2025-03-05 16:28:11 -08:00
Guillaume Lessard
1c1a845d67 [stdlib] fix withUnsafe[BufferPointer,Bytes] impls 2025-03-05 16:28:11 -08:00
Guillaume Lessard
10a0ee212e [stdlib] add an _extracting() overload for ClosedRange 2025-03-05 16:28:11 -08:00
Guillaume Lessard
928cbeac43 [stdlib] adjust failure messages (and spellings) 2025-03-05 16:28:11 -08:00
Guillaume Lessard
89956e71ec [stdlib] use the Index typealias in Span
- these were missed in a previous code change
2025-03-05 16:28:11 -08:00
Guillaume Lessard
6802d22dc3 [stdlib] Update availability annotations for Span 2025-03-05 16:28:11 -08:00
Kuba (Brecka) Mracek
7710a97ccb Merge pull request #79698 from kubamracek/embedded-more-traps-stringinterp
[embedded] Allow string-interpolatings in assert, assertionFailure, precondition, preconditionFailure
2025-03-05 09:22:09 -08:00
Yuta Saito
4aeaab4921 Merge pull request #79762 from kateinoigakukun/yt/fix-task-escalate-sig
stdlib: Fix the signature of `_taskEscalate` to return a priority
2025-03-05 12:29:35 +09:00
Holly Borla
f0446d0271 Merge pull request #79729 from hborla/concurrency-sugar
[Concurrency] Add an experimental macro for wrapping a function body in a new task.
2025-03-04 06:14:15 -08:00
Yuta Saito
f06d2f04f9 stdlib: Fix the signature of _taskEscalate to return a priority
The `swift_task_escalate` is defined to return the new priority of the
task after the escalation but the silgen_name'd function did not have
the return type specified.

Follow up to 18c25845d6
2025-03-04 11:44:13 +00:00