Commit Graph

20133 Commits

Author SHA1 Message Date
Carl Peto
de449c9611 revert atomics for now 2024-07-16 22:39:31 +01:00
Mike Ash
c1772eba50 [Concurrency] Fix unsafe continuation validation when a continued task has been destroyed.
SWIFT_DEBUG_VALIDATE_UNCHECKED_CONTINUATIONS works by tracking the context pointers of active continuations, and verifying that a resumed context is in the set of active continuations. However, the resume calls are passed the task pointer, not the context pointer. The context pointer is recovered from the task. If the task has been destroyed, the context pointer is invalid. This can result in a weird error message or it can crash if the context pointer is used before checking it against the active continuations.

Instead, track tasks that are suspended pending an unchecked continuation. If the task is destroyed, we'll still be passed the dangling pointer and check that pointer against the tracking info. We must be sure to check that before trying to use anything inside it.

rdar://131858544
2024-07-16 15:08:26 -04:00
Carl Peto
3689427834 [AVR] standard library support for AVR
- when compiling embedded cross compile target standard libraries, include AVR
- add 16-bit pointer as a conditional compilation condition and get the void pointer size right for gyb sources
- attempt to fix clang importer not importing __swift_intptr_t correctly on 16 bit platforms
- changed the unit test target to avr-none-none-elf to match the cmake build

[AVR] got the standard library compiling in a somewhat restricted form:

General
- updated the Embedded Runtime
- tweaked CTypes.swift to fix clang import on 16 bit platforms

Strings
- as discussed in https://forums.swift.org/t/stringguts-stringobject-internals-how-to-layout-on-16-bit-platforms/73130, I went for just using the same basic layout in 16 bit as 32 bit but with 16 bit pointers/ints... the conversation is ongoing, I think something more efficient is possible but at least this compiles and will probably work (inefficiently)

Unicode
- the huge arrays of unicode stuff in UnicodeStubs would not compile, so I skipped it for AVR for now.

Synchronization
- disabled building the Synchronization library on AVR for now. It's arguable if it adds value on this platform anyway.
2024-07-16 12:28:27 +01:00
Doug Gregor
a3bf1fc4c2 Merge pull request #75248 from DougGregor/unsafe-inherit-executor-the-rest
Extend _unsafeInheritExecutor_ to remaining @_unsafeInheritExecutor APIs
2024-07-15 18:46:38 -07:00
Doug Gregor
a47483c0ec Fix ABI issue with TaskLocal.withValue and update ABI test 2024-07-15 14:37:45 -07:00
Doug Gregor
f6ba1bbeaa Adopt _unsafeInheritExecutor_ workaround on the internal withValueImpl 2024-07-15 14:12:40 -07:00
Doug Gregor
d6b6bafe60 Extend _unsafeInheritExecutor_ to remaining @_unsafeInheritExecutor APIs
Extend the _unsafeInheritExecutor_ workaround to all remaining APIs in the
Concurrency library that have adopted `#isolation` default arguments to
(safely) stay in the caller's isolation domain...

... except one. Clock.measure() is currently running into problems with
the type checker workaround and needs a little more thought.

Fixes rdar://131760111.
2024-07-15 14:12:36 -07:00
Kenta Kubo
7b7110061f [stdlib][docs] Fix the SeeAlso documentation for withDiscardingTaskGroup (#72767)
The SeeAlso documentation for `withDiscardingTaskGroup` is missing trailing backticks.
2024-07-15 13:51:21 +09:00
Alejandro Alonso
bc7db0df4f Merge pull request #75205 from jmschonfeld/sync-shims-module-error
Fix build failure in _SynchronizationShims module
2024-07-13 23:17:15 +01:00
Nate Cook
846a861660 Improve RangeSet initialization performance (#75089)
When initializing a range set with a group of overlapping, identical,
or empty ranges, the initializer can exhibit poor performance due
to removing the unneeded ranges during processing. This change uses
a partitioning scheme instead, only removing the unnecessary ranges
at the end of initialization.
2024-07-12 15:01:38 -05:00
Jeremy Schonfeld
0216e62179 auto --> __swift_uint32_t 2024-07-12 10:07:42 -07:00
Jeremy Schonfeld
a3c614d924 Fix build failure in _SynchronizationShims module 2024-07-12 09:54:46 -07:00
Allan Shortlidge
373a3fe7de Merge pull request #75185 from tshortli/revert-aeic-diagnose-unavailable-code-reached
SILGen/stdlib: Remove `_diagnoseUnavailableCodeReached_aeic()`
2024-07-12 09:22:11 -07:00
Tim Kientzle
5916325b39 Merge pull request #75151 from tbkka/tbkka-harden-casting-failure
Tailored error reporting when dynamic casts have nonsensical type args
2024-07-11 15:14:10 -07:00
Allan Shortlidge
14200e412c SILGen/stdlib: Remove _diagnoseUnavailableCodeReached_aeic().
It should no longer be necessary to provide an `@_alwaysEmitIntoClient` version
of `_diagnoseUnavailableCodeReached()`. This workaround was originally added to
provide compatibility with projects that were misconfigured to compile against
a newer stdlib but link against an older one.

Resolves rdar://119892482.
2024-07-11 14:53:03 -07:00
Alastair Houghton
e2c7ec6ee7 Merge pull request #75108 from al45tair/eng/PR-130992923
[Runtime][Win32] Fix fatalError() backtraces.
2024-07-11 14:49:19 +01:00
Alastair Houghton
a72c167af5 [Runtime][Win32] Further tweaks to SymbolInfo.cpp and Errors.cpp.
Fix an unused variable warning in `Errors.cpp`.

Use brace initialization syntax in `SymbolInfo.cpp` rather than using
a constructor call.

rdar://130992923
2024-07-11 11:51:59 +01:00
Tim Kientzle
fac8c972a5 Tailored error reporting when dynamic casts have nonsensical type args
This inserts a suitably named function into the stack trace whenever
a dynamic cast failure involves a NULL source or target type.
Very often, crash logs include backtraces with function names but
no log output; with this change, such a backtrace might look like
the following -- note `TARGET_TYPE_NULL` in the function name
here to mark the missing type information:

```
 frame #0: __pthread_kill + 8
 frame #1: pthread_kill + 288
 frame #2: abort + 128
 frame #3: swift::fatalErrorv()
 frame #4: swift::fatalError()
 frame #5: swift_dynamicCastFailure_TARGET_TYPE_NULL()
 frame #6: swift::swift_dynamicCastFailure()
 frame #7: ::swift_dynamicCast()
```

Resolves rdar://130630157
2024-07-10 15:57:36 -07:00
Doug Gregor
2a8b3fcf95 Merge pull request #75093 from DougGregor/unsafe-inherit-executor-vs-pound-isolation
Ensure that a `@_unsafeInheritExecutor` function does not depend on `#isolation`
2024-07-10 11:05:37 -07:00
Tim Kientzle
55d4a56c69 Merge pull request #74821 from tbkka/tbkka-bincompat
Upstream some binary-compatibility logic
2024-07-10 09:47:14 -07:00
Alastair Houghton
418a240e80 [Runtime][Win32] Tweak SymbolInfo slightly based on review comments.
Prefer `ZeroMemory()` to `::memset()` here.

Use `sizeof(*wszBuffer)` instead of `sizeof(WCHAR)`, just in case.

Don't use `*this=other`, because that motivates tests around `::free()`,
but instead pull the shared code out into some private functions.

Also, fix `SymbolInfo()` to initialize the pointer members.

rdar://130992923
2024-07-10 12:22:35 +01:00
Doug Gregor
8964436f36 Add _unsafeInheritExecutor_ version of TaskLocal.withValue 2024-07-09 15:38:38 -07:00
Allan Shortlidge
0ba007661a AST: Promote BuiltinAddressOfRawLayout to baseline. 2024-07-09 14:29:30 -07:00
Allan Shortlidge
45f3e94b46 AST: Promote AssociatedTypeImplements feature to baseline. 2024-07-09 14:28:30 -07:00
Allan Shortlidge
b85da32707 AST: Promote OptionalIsolatedParameters feature to baseline. 2024-07-09 14:28:29 -07:00
Allan Shortlidge
99dbbe4a12 AST: Promote BuiltinStoreRaw feature to baseline. 2024-07-09 14:28:29 -07:00
Allan Shortlidge
9717961202 AST: Promote BuiltinAllocVector feature to baseline. 2024-07-09 14:28:29 -07:00
Allan Shortlidge
ab99cac77d AST: Promote BuiltinUnprotectedStackAlloc feature to baseline. 2024-07-09 14:28:28 -07:00
Tim Kientzle
0ab1b1631d Upstream some binary-compatibility logic 2024-07-09 13:30:13 -07:00
Ian Anderson
dad0a21b01 Merge pull request #74920 from ian-twilightcoder/builtin_float_module-abi-name
[overlay] Support the older @rpath Darwin library for _Builtin_float's $ld$previous$ symbols
2024-07-09 12:04:37 -07:00
Alastair Houghton
8ad89c08e2 [Runtime][Win32] Fix fatalError() backtraces.
We were calling `SymInitialize()` multiple times, which is wrong, which
was making the `SymbolInfo::lookup()` call fail.  Also, we weren't
fetching the module names, so we should do that too.

rdar://130992923
2024-07-09 18:50:20 +01:00
Ian Anderson
9e9d66efc9 [overlay] Support the older @rpath Darwin library for _Builtin_float's $ld$previous$ symbols
The _Builtin_float symbols were moved twice, most recently from the OS Darwin library, but previously they were in the embedded @rpath Darwin library. @_originallyDefinedIn doesn't support multiple install names, but it can be replaced with -module-abi-name, and then multiple $ld$previous$ symbols can be used.
Update the Platform and Concurrency magic symbols to use $ld$previous$ everywhere.

rdar://130107191
2024-07-09 09:13:30 -07:00
Joe Groff
dfc5321ca6 Merge pull request #74997 from jckarter/protocol-extension-self-same-type-runtime-resolution
Runtime: Fix runtime type resolution when mangled names refer to protocol extensions with Self same type constraints.
2024-07-09 09:10:19 -07:00
Doug Gregor
a2038f92f8 Address code review feedback and fix rebase typo in a test 2024-07-09 08:13:24 -07:00
Konrad `ktoso` Malawski
a3e0b173ea [Concurrency] TaskExecutors may be non-swift objects; dont swift_release them (#75059) 2024-07-09 02:55:11 -07:00
Doug Gregor
a2b2324e7f Use @_unsafeInheritExecutor forms of with*Continuation from @_unsafeInheritExecutor functions
The move from `@_unsafeInheritExecutor` to `#isolation` for the
with*Continuation breaks code that is using `@_unsafeInheritExecutor` and
calling these APIs. This originally caused silent breakage (which manifest
as runtime crashes), and is now detected by the compiler as an error.

However, despite `@_unsafeInheritExecutor` being an unsafe,
not-intended-to-be-user-facing feature, it is indeed being used, along
with these APIs. Introduce _unsafeInheritExecutor_-prefixed versions of
the `with*Continuation` and `withTaskCancellationHandler` APIs into
the _Concurrency library that use `@_unsafeInheritExecutor`. Then,
teach the type checker to swap in these
_unsafeInheritExecutor_-prefixed versions in lieu of the originals
when they are called from an `@_unsafeInheritExecutor` function. This
allows existing code using `@_unsafeInheritExecutor` with these APIs
to continue working as it has before, albeit with a warning that
`@_unsafeInheritExecutor` has been removed.

Fixes rdar://131151376.
2024-07-08 23:35:37 -07:00
Allan Shortlidge
7e4425c97e Merge pull request #75090 from tshortli/no-more-ncg-condfails
AST: Remove `NoncopyableGenerics` feature suppression
2024-07-08 23:03:40 -07:00
Allan Shortlidge
b1bf693f3f stdlib: Remove #if $NoncopyableGenerics guards.
The stdlib is always built with NoncopyableGenerics enabled, so `#if
$NoncopyableGenerics` guards in non-inlinable code are superfluous.
Additionally, the stdlib's interface no longer needs to support compilers
without the feature, so the guards in inlinable code can also be removed.
2024-07-08 17:44:24 -07:00
Allan Shortlidge
20d97556ae stdlib: Remove #if $TypedThrows guards.
https://github.com/swiftlang/swift/pull/72612 can be reverted because it is no
longer necessary for the interface of the stdlib to be compatible with
compilers without `$TypedThrows` support.
2024-07-08 16:52:52 -07:00
Joe Groff
e0df8ffdb5 Runtime: Fix runtime type resolution when mangled names refer to protocol extensions with Self same type constraints.
If a type or opaque type descriptor appears inside of a protocol extension of the form:

```
extension P where Self == Nominal { ... }
```

then the runtime representation of the extension context was interpreted by the runtime
demangler as a nominal type extension, even though the parameterization is on the
`<Self>` generic signature of the protocol extension and not the generic signature of
the nominal type. This would cause spurious rejection of mangled names referencing the
extension context because we mistakenly thought that the type arguments mismatched with
the nominal type signature rather than matching them to the extension context.

Add some code to `_findExtendedTypeContextDescriptor` to detect when an extension is
a protocol extension with a `Self == SameType` constraint, and pass the extension along
rather than treating it as a nominal type extension. Fixes rdar://130168101.
2024-07-08 07:41:24 -07:00
Nate Cook
6d4f4a45cf Improve RangeSet union performance (#74963) 2024-07-08 09:00:37 -05:00
Alastair Houghton
565a9b9208 Merge pull request #75051 from al45tair/eng/PR-131294724
[Runtime] Add missing cast.
2024-07-08 13:27:08 +01:00
Egor Zhdan
71c81d5fc5 Merge pull request #74994 from swiftlang/egorzhdan/cxx-overlay-maccatalyst
[cxx-interop] Build Cxx and CxxStdlib modules for macCatalyst
2024-07-08 12:11:55 +01:00
Alastair Houghton
b6e7a5107a Merge pull request #75024 from Sajjon/cyon_typo_batch__stdlib
Typos: `stdlib`
2024-07-08 10:57:54 +01:00
Alastair Houghton
64b891d5fe [Runtime] Add missing cast.
Apparently we're missing a cast in `_swift_initRuntimePath()`.  Previously
this code was accidentally not being used, which is why we hadn't noticed
it.

rdar://131294724
2024-07-08 10:29:31 +01:00
Konrad `ktoso` Malawski
a8f68aab4b Merge pull request #75008 from kateinoigakukun/yt/fix-mutex-guard-wasm-thread
Concurrency: Guard TG state with a mutex even with cooperative executor
2024-07-08 17:56:31 +09:00
Konrad `ktoso` Malawski
df43b63f44 [Concurrency] Attempt to unbreak embedded build (#75006) 2024-07-08 11:21:12 +09:00
Konrad `ktoso` Malawski
3c75f2fac8 Add comment explaining #if guard 2024-07-08 10:49:38 +09:00
Konrad `ktoso` Malawski
5ad2291ac0 [Concurrency] Fix build in actors as locks configuration (#75004) 2024-07-07 10:37:33 +09:00
Alexander Cyon
c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02:00