Commit Graph

21665 Commits

Author SHA1 Message Date
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
Slava Pestov
51face17da Merge pull request #80282 from Steelskin/fabrice/define-swift-stdlib-build-types-missing
Disable CompatibilitySpans outside of stdlib build
2025-03-26 20:08:09 -04:00
Ben Rimmington
2f9f5ffd85 [stdlib] Update element constraints of Span 2025-03-26 22:32:08 +00:00
Pavel Yaskevich
d656f74652 [TypeChecker] Avoid dropping pre-check diagnostics in typeCheckParameterDefault
`typeCheck{Expression, Target}` has a pre-check phase which would
replace some invalid AST nodes (i.e. name references that are not
available in the given declaration context) with `ErrorExpr`s and
emit a diagnostic. Such diagnostics were then dropped by `abort()`
call to a diagnostic transaction. This results in invalid code being
accepted by Sema and forwarded to SILGen.

Resolves: https://github.com/swiftlang/swift/issues/73986
Resolves: rdar://131732245
2025-03-26 14:22:32 -07:00
Max Desiatov
eb1a2960b6 Enable _Concurrency for Embedded Swift with WASI (#79292)
WASI with Embedded Swift provides WASI-libc and libc++ headers necessary to build the `_Concurrency` module for Wasm. We now add `wasm32-unknown-wasip1-wasm` triple to `EMBEDDED_STDLIB_TARGET_TRIPLES` when `SWIFT_WASI_SYSROOT_PATH` is set, which builds the necessary stdlib slice.

---------

Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
2025-03-26 21:14:05 +00:00
Mike Ash
7c3b06dc4f [Concurrency] Avoid de-escalating a task when racing to escalate.
Reload oldPriority each time through the compare_exchange loop. Without this, we might race with another escalating thread and end up trying to set a priority that's lower or equal to the priority set by the other thread. This results in an assertion failure when asserts are enabled, or attempt to lower the priority of the task when asserts are not enabled.

rdar://147888768
2025-03-26 15:44:57 -04:00
Mike Ash
6397e30856 [Concurrency] Eliminate StatusRecordLockRecord.
Move to a recursive lock inline in the Task. This avoids the need to allocate a lock record and simplifies the code somewhat.

Change Task's OpaquePrivateStorage to compute its size at build time based on the sizes of its components, rather than having it be a fixed size. It appears that the fixed size was intended to be part of the ABI, but that didn't happen and we're free to change this size. We need to expand it slightly when using pthread_mutex as the recursive lock, as pthread_mutex is pretty big. Other recursive locks allow it to shrink slightly.

We don't have a recursive mutex in our Threading support code, so add a RecursiveMutex type.

rdar://113898653
2025-03-26 14:52:37 -04:00
Nate Chandler
0c2a38b10b [CoroutineAccessors] Directly reference allocators
Replace the call to a runtime function that looks up the allocator with
a direct reference to a just-emittedd sought-after global allocator.
2025-03-26 08:35:35 -07:00
Dario Rexin
c89cb49a14 [Concurrency] Properly set task create flags in TaskGroup.startTaskSynchronously (#80299)
rdar://147907609

When starting tasks synchronously on task groups, the task create flags for isSynchronousStart and isDiscardingTask were always set to `false`. With this change the former will always be `true` and the latter conditionally `true` for discarding task groups.
2025-03-26 22:00:33 +09:00
Doug Gregor
97de71be40 Merge pull request #80279 from DougGregor/stdlib-remaining-memory-safety-warnings
[Standard library] Address remaining memory-safety warnings
2025-03-25 15:44:27 -07:00
Mike Ash
5f5d1cfae6 Merge pull request #80119 from mikeash/allocation-failure-fatal-error
[Runtime] Include size/alignment in allocation failure fatal error message.
2025-03-25 18:32:21 -04:00
Mike Ash
ed3e6356ec Merge pull request #80243 from mikeash/ignore-constructor-warnings
[Runtime] Ignore some global constructor warnings.
2025-03-25 17:42:16 -04:00
Fabrice de Gans
ec503e7ee7 Disable CompatibilitySpans outside of stdlib build 2025-03-25 12:49:03 -07:00
nate-chandler
17952d4d6f Merge pull request #80221 from nate-chandler/general-coro/20250320/1
[CoroutineAccessors] Default overrides of new symbols.
2025-03-25 12:22:40 -07:00
Fabrice de Gans
9505d55c96 Build CompatibilitySpan as STATIC for build tools
In some cases, like when building the Swift toolchain build tools,
`SWIFT_STDLIB_LIBRARY_BUILD_TYPES` is not defined. This causes a
configuration failure when the `CompatibilitySpan` library is being
added.

This commit sets a default value of `STATIC` to work around this
problem.
2025-03-25 12:06:11 -07:00
Doug Gregor
0d296b5f89 [Standard library] Address remaining memory-safety warnings 2025-03-25 10:57:17 -07:00
Dario Rexin
2f4a8a8658 Merge pull request #80272 from glessard/rdar137710901-span-properties-prototype
[temporary] disable spans over inline elements
2025-03-25 09:02:14 -07:00
Guillaume Lessard
e5c7dfc430 [temporary] disable spans over inline elements
unblocks building a debug-mode standard library
2025-03-25 08:55:53 -07:00
Nate Chandler
5534eb4043 [DefaultOverides] Install in vtables at runtime. 2025-03-25 07:22:44 -07:00
Nate Chandler
ddb89af283 [NFC] Runtime: Return early here.
In preparation for adding more work to this branch.
2025-03-25 07:22:43 -07:00
Nate Chandler
9a9c2ffee8 [NFC] Runtime: Use a range-based for loop.
Replace this direct use of the count in a table header as the upper
bound of a for loop with a range-based for loop over the range which was
being indexed into.  That range was constructed using that count to
begin with.
2025-03-25 07:22:13 -07:00
Nate Chandler
c576c61122 [NFC] Runtime: Extract fields from param aggregate
Rather than pass a MethodOverrideDescriptor directly, instead pass the
fields from it that are needed by the callee.  In preparation for adding
another caller which doesn't have a MethodOverrideDescriptor.
2025-03-25 07:22:13 -07:00
Nate Chandler
4bfdaed78a [NFC] Runtime: Extract function.
Break this chunk of functionality out into a separate function in
preparation for adding another caller.
2025-03-25 07:22:13 -07:00
Nate Chandler
5d53d3bdaa [NFC] Runtime: Mark parameter const.
The implementation doesn't depend on it being non-const and a
forthcoming caller will require it be const.
2025-03-25 07:22:13 -07:00
Slava Pestov
6463dcb9c9 Merge pull request #79703 from slavapestov/span-backward-deployment
Build CompatibilitySpan shim
2025-03-25 07:28:47 -04:00
Michael Chiu
617a701afc Arm64 FreeBSD toolchain should use 'aarch64' arch 2025-03-24 18:46:32 -04:00
Saleem Abdulrasool
82dc5bba03 runtime: adjust API usage for Windows (NFCI)
This replaces `strdup` with `_strdup` on Windows to avoid the POSIX API
deprecation warnings. It also does a minor simplification by removing
the superfluous `else`.
2025-03-24 15:00:10 -07:00
Slava Pestov
b0627e28a2 stdlib: Build with -previous-module-installname-map-file on Apple platforms 2025-03-24 17:56:45 -04:00
Slava Pestov
fa41c70b7f stdlib: Symlink libswiftCore.dylib to libswiftCompatibilitySpan.dylib 2025-03-24 17:56:44 -04:00
Slava Pestov
5c1b20d2bc stdlib: Build libswiftCompatibilitySpan.dylib compatibility shim
This dynamic library contains a copy of the standard library's
exported entry points for the Span and RawSpan types. This will
allow backward deployment of code that uses those new types.
2025-03-24 17:56:44 -04:00
Karoy Lorentey
5bc723d703 [stdlib] Adjust lifetime declarations 2025-03-24 12:16:20 -07:00
Karoy Lorentey
192b404947 [stdlib] Work around ~Escapable breaking Optional.init syntax 2025-03-24 12:16:19 -07:00
Karoy Lorentey
b17a8d493d Generalize Optional._consumingUncheckedUnwrapped()
This is just to round things out — this internal function was sticking out from the public interfaces. No stdlib code needs this generalization yet, but I see no reason to delay it.
2025-03-24 12:16:18 -07:00
Karoy Lorentey
dc5e9f585f Add some missing @lifetime attributes
We were relying on infererred lifetimes by accident — it’s better to spell things out for now.
2025-03-24 12:16:17 -07:00
Karoy Lorentey
21169d12e8 Reinstate generalization of Optional.unsafelyUnwrapped 2025-03-24 12:16:16 -07:00
Karoy Lorentey
480f87027d [stdlib] Mark Unsafe*BufferPointer.indices as safe 2025-03-24 12:16:15 -07:00
Karoy Lorentey
6ead0d8cd6 [stdlib] Postpone generalizing Result.flatMapError 2025-03-24 12:16:13 -07:00
Karoy Lorentey
40d2cda28c [stdlib] Properly generalize metatype comparisons 2025-03-24 12:16:12 -07:00
Karoy Lorentey
c2d33b4f71 [stdlib] Take out generalization of Optional.unsafelyUnwrapped for now 2025-03-24 12:16:08 -07:00
Karoy Lorentey
26176cc929 [stdlib] Allow metatypes of noncopyable/nonescapable types to get compared 2025-03-24 12:16:08 -07:00
Karoy Lorentey
eba00922c3 [stdlib] Properly generalize ObjectIdentifier.init(Any.Type)
With Slava’s fix in https://github.com/swiftlang/swift/pull/79647, we can now refer to generalized type existentials in ABI stable code.
2025-03-24 12:16:07 -07:00
Karoy Lorentey
801385ad49 [stdlib] Generalize the signature of type(of:)
`func type(of:)` is wholly magical, but it does have a signature in the stdlib (mostly for documentation purposes), and it currently requires its input to be copyable and escapable.

`type(of:)` is actually usable on all entities, so it seems desirable to update its signature to reflect this.

Additionally, this seems like a good time to mark its exported symbol obsolete. I don’t expect anyone would ever link to it (unless there is/was a bug), so in theory we could also silently remove it — but explicitly marking it as legacy ABI seems the least risky option.
2025-03-24 12:16:06 -07:00
Karoy Lorentey
3c133d56c1 Revert "[stdlib] unsafeBitCast: generalize for ~Escapable input types"
This reverts commit 0d7cab589f1a7fbcb988b28aec50db768e018539.
2025-03-24 12:16:03 -07:00
Karoy Lorentey
8a7fcc3bbf [stdlib] Update syntax for conditional conformances to invertable protocols 2025-03-24 12:16:02 -07:00
Karoy Lorentey
538f2742ef [stdlib] Roll back generalization of the nil-coalescing operator ??
We cannot currently express its proper lifetime semantics: its result’s lifetime should depend on the intersection of the lifetime of the left argument and the lifetime of the result of the right argument.

`@lifetime(optional, defaultValue.result)` is what we want, but the `.result` part is not currently expressible. (Tying the dependency on the closure argument itself may be a viable option, but we aren’t confident enough to ship it like that yet.)
2025-03-24 12:16:01 -07:00
Karoy Lorentey
96fd749ecc [stdlib] Generalize unsafe buffer pointer operations on Slice
`Slice` continues to require `Element` to be copyable, so this is limited to`moveInitializeMemory`, `bindMemory`, `withMemoryRebound` and `assumingMemoryBound`. Generalizing these restores parity with the corresponding operations on unsliced buffer pointers, and reduces the need to artificially rebase the slices only to call these.
2025-03-24 12:16:01 -07:00
Karoy Lorentey
b7b75aeace [stdlib] Generalize Optional.unsafelyUnwrapped 2025-03-24 12:15:56 -07:00
Karoy Lorentey
cf35c65863 [stdlib] Generalize Unsafe[Mutable]BufferPointer.indices 2025-03-24 12:15:55 -07:00
Karoy Lorentey
0e55d96a22 [stdlib] Generalize Optional.take(), ?? and nil comparisons 2025-03-24 12:15:52 -07:00
Karoy Lorentey
84b63956bf [stdlib] Generalize Optional’s “some” initializer 2025-03-24 12:15:51 -07:00