Commit Graph

21502 Commits

Author SHA1 Message Date
Slava Pestov
001b1129f7 stdlib: Update {Mutable,}{Raw,}Span availability for backward deployment 2025-04-21 15:01:29 -04:00
Slava Pestov
b3eb1a5bbd CompatibilitySpan: Add MutableRawSpan.swift, MutableSpan.swift 2025-04-21 15:01:28 -04:00
Slava Pestov
4af982902c cmake: Add NO_SWIFTMODULE option to add_swift_target_library() 2025-04-21 15:01:28 -04:00
Meghana Gupta
adb809369f Reland #79707
Revert "Merge pull request #80767 from meg-gupta/reverttransparent"

This reverts commit 198a802719, reversing
changes made to 8eb43af590.
2025-04-21 11:23:00 -07:00
Meghana Gupta
856cbaff9d Add @_transparent to some integer operations in the stdlib
@_transparent will ensure there are inlined in MandatoryInlining which runs before OSLogOptimization.

OSLogOptimization does not look through their calls because they are not marked with
@_semantics("constant_evaluable") which requires them to also be annotated as @_optimize(none)

rdar://148256435
2025-04-21 11:22:26 -07:00
Mike Ash
b2d6514b63 [6.2][Runtime] Add function_cast, switch from std::bit_cast.
Function types aren't always trivially copyable, e.g. with address-discriminated signed pointers on ARM64e. Introduce a function_cast helper and use that instead.

(cherry picked from commit 185b739cf1)
2025-04-21 12:47:48 -04:00
Doug Gregor
19975bc78f Remove extraneous unsafe from the concurrency library
(cherry picked from commit 1c9875e14a)
2025-04-21 09:03:34 -07:00
Doug Gregor
3724f84376 [Strict memory safety] Update standard library for nested safe/unsafe types
Use this to mark a few internal types @safe now that it works properly.

(cherry picked from commit 457eb4cc64)
2025-04-21 09:03:30 -07:00
Doug Gregor
469b30334c [Strict memory safety] Remove now-extraneous "unsafe" from the standard libraries
Now that we aren't propagating "unsafe" to nested types, remove
unnecessary "unsafe" keywords from the standard library.

(cherry picked from commit fe6856726e)
2025-04-21 09:03:23 -07:00
Evan Wilde
506d128487 Fix Bootstrap: UTF8EncoddingError
The pass that annotated control-flow positions unreachable after an
infinite loop was migrated to pure Swift in PR 79186
(https://github.com/swiftlang/swift/pull/79186). As a result, the
C++-only bootstrap compiler is unable to determine that the
code-location is unreachable. Placing a fatalError after the infinite
while loop.

Fixes: rdar://149568740
(cherry picked from commit 783c969e10)
2025-04-20 09:06:38 -07:00
Guillaume Lessard
ea57dd93a0 [stdlib] work around autoclosure issues
- The move-only checker has issues with the existence of autoclosures.
- These `borrowing` accessors are within the purview of the move-only checker.
2025-04-18 10:45:00 -07:00
Guillaume Lessard
4ae1ad744d Revert "[temporary] disable small-string support"
This reverts commit ea44ff9fc9.
2025-04-18 10:44:59 -07:00
Michael Ilseman
393c24ddd7 UTF8Span (#78531) (#80890)
Add support for UTF8Span

Also, refactor validation and grapheme breaking
2025-04-18 10:01:15 -04:00
Doug Gregor
c363658147 Merge pull request #80887 from DougGregor/conformance-cache-extended-entry-deleak-6.2 2025-04-17 19:07:09 -07:00
Eric Miotto
a948f794c9 Merge pull request #80883 from edymtt/emiotto/mark-executorimpl_cpp-optional-6.2
[6.2] CMake Embedded Stdlib: mark `ExecutorImpl.cpp` as optional
2025-04-17 14:37:26 -07:00
Doug Gregor
cead04b530 [Conformance cache] Add allocated extended-storage for entries to the free list
This memory is part of the conformance cache concurrent hash map, so
when we clear the conformance cache, record each of the allocated
pointers within the concurrent map's free list. This way, it'll be
freed with the rest of the concurrent map when it's safe to do so.

(cherry picked from commit 885f829a63)
2025-04-17 09:03:16 -07:00
Doug Gregor
e8eed435ee [Runtime] Replace use of C++ new with malloc()
(cherry picked from commit d576fa30c9)
2025-04-17 09:03:13 -07:00
Eric Miotto
d542e5c728 [6.2] CMake Embedded Stdlib: mark ExecutorImpl.cpp as optional
This is needed for internal Apple configurations that build the Embedded
Stdlib on its own.

Addresses rdar://149410405

(cherry picked from commit a249e7fd8d)
2025-04-17 06:52:43 -07:00
Konrad `ktoso` Malawski
361ebea8d7 Merge pull request #80797 from ktoso/pick-wip-parent-cancel-must-cancel-group
[6.2][Concurrency] Parent task cancellation must cancel task group itself
2025-04-17 11:33:11 +09:00
Doug Gregor
15ecd6654d Merge pull request #80845 from DougGregor/relative-witness-tables-fixes-6.2
[6.2] Relative witness table fixes
2025-04-16 17:37:51 -07:00
Alastair Houghton
b5a61a1d48 Merge pull request #80796 from al45tair/eng/PR-149067144-6.2
[Concurrency] Fix size of AsyncTask::PrivateStorage.
2025-04-16 13:17:05 +01:00
Guillaume Lessard
e81fbe5f48 [stdlib] use “LifetimeDependenceMutableAccessors” 2025-04-15 22:25:24 -07:00
Doug Gregor
77caa2dadd [Conformance cache] Handle missing protocol descriptors
This can happen when running against an older version of a library that
doesn't have the protocol defined.
2025-04-15 21:12:52 -07:00
Doug Gregor
e32174abae [Runtime] Don't use the low bit of a WitnessTable pointer in the conformance cache
With relative witness tables, the low bit of a witness table pointer is
an indicator that we need to load from the given pointer. We were also
using the low bit of the witness table pointer in the conformance
cache entry as part of a pointer union. Hilarity ensures [*].

Switch to another low bit by exploding the conformance cache key
into separate fields and taking the low bit of one of those pointers
that isn't reserved.

Fixes the remainder of rdar://149326058, I hope.

[*] No, I am not laughing.
2025-04-15 18:15:26 -07:00
Doug Gregor
2de64b666f [Runtime] Handle relative witness tables in _getIsolationCheckingOptionsFromExecutorWitnessTable
Part of rdar://148687148.
2025-04-15 18:15:06 -07:00
Konrad 'ktoso' Malawski
29b8e271e1 [Concurrency] Refactor _swift_taskGroup_cancelAllChildren -> _cancel
This way we do the right thing always when cancelling the group;
and we MAY visit the child tasks if we have to.
2025-04-14 17:44:00 +09:00
Konrad 'ktoso' Malawski
059e5dd15e [Concurrency] Parent task cancellation must cancel task group itself.
Seems that during refactorings of child cancellations we somehow missed
also cancelling the group itself. It seems we did not have good test
coverage of the addTaskUnlessCancelled somehow and thus this slipped
through.

This adds a regression test for addTaskUnlessCancelled and fixes how we
handle the cancellation effect in TaskStatus.

resolves #80789
resolves rdar://149177600
2025-04-14 17:43:55 +09:00
Alastair Houghton
55ec37253e [Concurrency] Fix size of AsyncTask::PrivateStorage.
Because `TaskAllocator` is not a round multiple of the machine word
size on 64-bit platforms, I think we end up with padding before the
`TaskLocal::Storage` following it, which makes the `PrivateStorage`
structure larger than the calculation in `ABI/Task.h`.

rdar://149067144
2025-04-14 09:28:50 +01:00
Alastair Houghton
670be7df63 [Concurrency] Remove -executor-factory option and replace with magic type.
We decided that using a magic typealias to set the executor factory was better
than using a compiler option. Remove the `-executor-factory` option, and replace
by looking up the `DefaultExecutorFactory` type, first in the main module, and
then if that fails in Concurrency.

rdar://149058236
2025-04-14 09:23:03 +01:00
Meghana Gupta
c22acc530e [6.2] Revert #79707
Revert "Merge pull request #79707 from DougGregor/transparent-integer-conversions"

This reverts commit 9c2c4ea07f, reversing
changes made to 829e03c104.
2025-04-11 10:57:14 -07:00
Guillaume Lessard
cb390140d6 [stdlib] correct MutableRawSpan sizing 2025-04-10 10:31:18 -07:00
Guillaume Lessard
53b6b45bda [stdlib] update lifetime annotation syntax 2025-04-10 10:31:18 -07:00
Guillaume Lessard
77431f5217 [stdlib] add MutableSpan.mutableBytes 2025-04-10 10:31:05 -07:00
Meghana Gupta
b3881cde1d Merge pull request #80645 from meg-gupta/lifetimeinoutcp
[6.2] Add support for inout lifetime dependencies
2025-04-10 03:04:28 -07:00
Mike Ash
29db1eca14 Merge pull request #80644 from mikeash/fix-task-sizes-6.2
[6.2][Concurrency] Fix task status and private storage sizes.
2025-04-09 13:37:37 -04:00
Mike Ash
c689d748eb Merge pull request #80612 from mikeash/metadata-cycle-race-fix-6.2
[6.2][Runtime] Fix a false metadata cycle diagnostic when threads race to instantiate cyclical metadata.
2025-04-09 13:28:23 -04:00
Meghana Gupta
00bda986a9 Introduce InoutLifetimeDependence feature 2025-04-09 10:19:11 -07:00
Meghana Gupta
0c5edc5222 Update stdlib 2025-04-09 10:19:11 -07:00
Guillaume Lessard
79fb06faf3 [stdlib] update lifetime annotation syntax 2025-04-09 09:56:06 -07:00
Guillaume Lessard
f931d296a2 [stdlib] add InlineArray.mutableSpan 2025-04-09 09:56:06 -07:00
Guillaume Lessard
b90a6fcb41 [stdlib] add CollectionOfOne.mutableSpan 2025-04-09 09:56:06 -07:00
Mike Ash
5a37a27798 [Runtime] Handle relative witness tables in _checkWitnessTableIsolation.
We need to use lookThroughOptionalConditionalWitnessTable when relative witness tables are being used.

rdar://148687148
(cherry picked from commit f01d46ce38)
2025-04-08 16:17:09 -04:00
Mike Ash
7edc799b16 [6.2][RemoteMirror] Fix AsyncTask child iteration.
Iterating child tasks depends on knowing the size of AsyncTask, and changing the size of the task broke it. Instead of relying on mirroring the full structure in our out-of-process definitions, add a debug variable to libswift_Concurrency that contains the size of AsyncTask.

While we're there, add some more validation to child task enumeration. Check each child task's metadata pointer to make sure that it actually points to the AsyncTask metadata, and have the inner loop also increment and check ChildTaskLoopCount to stop runaway iteration in that loop.

rdar://148836760

(cherry picked from commit e3057031da)
2025-04-08 15:23:05 -04:00
Doug Gregor
bd83ae14f4 Merge pull request #80552 from DougGregor/resurrect-allow-unsafe-attribute-6.2 2025-04-08 09:43:19 -07:00
Mike Ash
c64a5662f2 [Runtime] Fix a false metadata cycle diagnostic when threads race to instantiate cyclical metadata.
The metadata creation system detects cycles where metadata depends on other metadata which depends on the first one again and raises a fatal error if the cycle can't be fulfilled.

Some cycles can be fulfilled. The cycle may involve a requirement for a metadata state less than full transitive completeness which can be reached without resolving the entire cycle. We only want to raise a fatal error when we detect a cycle that can't be fulfilled.

Normally this happens because the cycle checking in `blockOnMetadataDependency` only sees a cycle when it can't be fulfilled. Metadata initialization is advanced as far as it can be at each stage, so a cycle that can be fulfilled will see a fulfilling state and won't generate the dependency in the first place, since we only generate dependencies that haven't yet been met.

However, when two threads race to create types in a cycle, we can end up with such a dependency, because the dependency may be generated before another thread fulfilled yet. The cycle checker doesn't account for this and incorrectly raises a fatal error in that case.

Fix this by checking the cyclic dependency against the metadata's current state. If we have a dependency that's already been fulfilled, then there isn't really a dependency cycle. In that case, don't raise a fatal error.

rdar://135036243
(cherry picked from commit 9ad534bc4a)
2025-04-07 17:00:03 -04:00
Nate Chandler
63a1bb0705 [CoroutineAccessors] Use async bit in descriptors.
To facilitate back deployment, make use of the fact that the async bit
has up to now never been set for read and modify accessors and claim
that set bit to indicate that it is a callee-allocated coroutine.  This
has the virtue of being completely back deployable because like async
function pointers coro function pointers must be auth'd and signed as
data.
2025-04-04 15:50:11 -07:00
Doug Gregor
06c0efbce6 [stdlib] Reinstate AllowUnsafeAttribute experimental feature on libraries
We need this so that older compilers can handle the .swiftinterface
files we generate. It's unnecessary for newer compilers and can be
removed later.

Fixes rdar://148529962.

(cherry picked from commit 0100104ff7)
2025-04-04 15:18:25 -07:00
Guillaume Lessard
7dd029c372 Revert "[temporary] disable spans over inline elements"
This reverts commit e5c7dfc430.
2025-04-04 14:50:51 -07:00
Artem Chikin
69b4ea3469 Merge pull request #80421 from swiftlang/revert-80246-playing-with-pointy-pointers
Revert "Concurrency: remove workaround for silencing UB"
2025-04-03 16:12:53 -07:00
Allan Shortlidge
a6d311e3ed Merge pull request #80501 from tshortli/stdlib-warnings
stdlib: Address #StrictMemorySafety and unreachable code warnings
2025-04-03 15:05:51 -07:00