Commit Graph

3149 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
e3b9c987b1 Fix RelativePtr ptrauth in swift_getAssociatedConformanceWitnessSlowImpl to sign *then* cast (#41354) 2022-02-12 06:47:24 -08:00
Mike Ash
6f923f35ad [Concurrency] Remove explicit_bzero call on Linux.
Clearing memory before freeing it is difficult to do portably. The Linux version didn't build on CentOS. Have Linux use `= 0` for now.
2022-02-10 21:07:39 -05:00
Rokhini Prabhu
a5fa349f88 Merge pull request #41281 from apple/rokhinip/88600541-task-priority-escalation-arm64_32
Task Escalation support on arm64_32 Apple platforms
2022-02-10 17:02:38 -08:00
Pavel Yaskevich
c3868244ec Merge pull request #41318 from xedin/fix-dist-windows
[Distributed] Runtime: Add missing accessible function section regist…
2022-02-10 13:42:02 -08:00
Rokhini Prabhu
98a8bdbd38 Task Escalation support on arm64_32 Apple platforms
Radar-Id: rdar://problem/88600541
2022-02-10 11:50:31 -08:00
Pavel Yaskevich
24b9c6486a [Distributed] Runtime: Add missing accessible function section registration on COFF 2022-02-10 09:20:51 -08:00
Pavel Yaskevich
b5f42981be Merge pull request #41307 from xedin/fix-dist-linux
[Distributed] Runtime: Add missing accessible function section registration on ELF
2022-02-10 08:40:29 -08:00
Mike Ash
8c61e4c063 Merge pull request #41210 from mikeash/clear-async-slab-metadatas
[Concurrency] Clear Slab's fake metadata pointer before freeing it.
2022-02-10 10:48:43 -05:00
Pavel Yaskevich
ecf1c1ede1 [Distributed] Runtime: Add missing accessible function section registration on ELF
Resolves: rdar://87240034
2022-02-09 16:06:11 -08:00
Mike Ash
1020a1a9c8 [Concurrency] Clear Slab's fake metadata pointer before freeing it.
This helps ensure that memory analysis tools don't get confused by leftover metadata pointers in reallocated memory that hasn't been initialized yet.

rdar://88494373
2022-02-09 11:41:32 -05:00
Saleem Abdulrasool
1b5b9d3573 Runtime: change atomic implementation for AllocationPool
The `AllocationPool` type is reflected upon and inspected by debugging
tools.  This requires that the layout of the atomically wrapped type
must store the value at offset 0.  However, the `std::atomic` does not
make any such guarantees, and a layout differing would render debug
utilities useless.  Switch instead from a `std::atomic` to
`swift::atomic`.  In order to do so, we also need to introduce the
`compare_exchange_strong` helper which maps to
`compare_exchange_strong_explicit` mirroring `compare_exchange_weak`.
2022-02-06 12:37:48 -08:00
Kuba (Brecka) Mracek
a268f02c65 Account for -disable-preallocated-instantiation-caches for non-dependent wtables in swift_getWitnessTable (#41199) 2022-02-04 06:52:36 -08:00
Mike Ash
ec073302c2 Merge pull request #41185 from mikeash/protocol-conformance-dyld
[Runtime] Support precomputed protocol conformances outside the shared cache.
2022-02-04 09:13:19 -05:00
Mike Ash
d262acfa04 [Runtime] Support precomputed protocol conformances outside the shared cache.
Extend the support for precomputed protocol conformances in the shared cache. When available, we'll query dyld for conformances in optimized images loaded outside the shared cache. This is a relatively small addition; where we previously checked the shared cache, we now check both. The order is conditionalized on `scanSectionsBackwards` to preserve that behavior. We also rename some identifiers to fit this more expansive use of preoptimized conformances.

rdar://87425446
2022-02-03 13:30:39 -05:00
Kuba (Brecka) Mracek
e6a1e23a9f Add SWIFT_STDLIB_ENABLE_VECTOR_TYPES to take away support for SIMD (#41149) 2022-02-02 12:06:45 -08:00
Kuba (Brecka) Mracek
17c5d6f0de Add a flag to disable compile-time preallocated instantiation caches (for type metadata and protocol conformances) (#41148) 2022-02-02 12:06:16 -08:00
Pavel Yaskevich
e801e4e2b7 [Distributed] Runtime: Add a way to fetch witness tables for given generic env/arguments 2022-01-24 10:18:00 -08:00
Pavel Yaskevich
206969a705 [Distributed] Augment parameter/result type decoded to support generic substitutions 2022-01-24 10:17:59 -08:00
Pavel Yaskevich
0e35951213 [Distributed] Stage use of generic environment to decode target parameter/result types 2022-01-24 10:17:59 -08:00
Alastair Houghton
4a3612b873 Merge pull request #40955 from al45tair/problem/86368350
[Runtime] Fix a potential NULL pointer dereference.
2022-01-21 21:32:05 +00:00
Alastair Houghton
a0313e9538 [Runtime] Fix a potential NULL pointer dereference.
If we find multiple conformances for the same protocol, we generate a
warning.  This works fine for Swift types, but for Objective-C types
it's possible that while generating the warning we might find that the
type description is NULL.

Fix by using swift_getTypeName().

rdar://86368350
2022-01-21 17:42:02 +00:00
Adrian Prantl
fede775269 Make Objective-C interoperability configurable in the runtime
In order to be able to debug, for example, a Linux process from a macOS host, we
need to be able to initialize a ReflectionContext without Objective-C
interoperability. This patch turns ObjCInterOp into another template trait, so
it's possible to instantiate a non-ObjC MetadataReader on a system built with
ObjC-interop (but not vice versa).

This patch changes the class hierarchy to

                          TargetMetadata<Runtime>
                                    |
                          TargetHeapMetadata<Runtime>
                                    |
                          TargetAnyClassMetadata<Runtime>
                                   /                \
                                  /               TargetAnyClassMetadataObjCInterop<Runtime>
                                 /                              \
TargetClassMetadata<Runtime, TargetAnyClassMetadata<Runtime>>    \
                                                                  \
                    TargetClassMetadata<Runtime, TargetAnyClassMetadataObjCInterop<Runtime>>

TargetAnyClassMetadataObjCInterop inherits from TargetAnyClassMetadata because
most of the implementation is the same. This choice makes TargetClassMetadata a
bit tricky. In this patch I went with templating the parent class.

rdar://87179578
2022-01-20 18:28:18 -08:00
Mike Ash
17ac26903d [Concurrency] Adjust the task allocator slab size to 984 bytes.
A slab capacity of 1000 bytes was overflowing the 1024 byte malloc bucket when adding in the slab header. Adjust it down to 984 bytes. Calculate this by subtracting the slab header size from 1024, plus a little slop for malloc stack logging, to ensure we don't overflow the bucket again.

rdar://87612288
2022-01-19 16:50:15 -05:00
Pavel Yaskevich
847b6c0209 Merge pull request #40864 from xedin/fixes-for-dist-metadata-retrieval
[Distributed] Metadata: Refactor demangling of function types from method mangled names
2022-01-15 17:55:28 -08:00
Holly Borla
d146b69ccc Merge pull request #40666 from hborla/explicit-existential-fixes
[SE-0335] Enable explicit existential types.
2022-01-14 16:38:14 -08:00
Pavel Yaskevich
4746370963 [Distributed] Metadata: Refactor demangling of function types from method mangled names
- Extract common logic across count, result and parameter type demangling
- Add support for demangling of generic functions
- Fix handling of single unlabeled parameter types
2022-01-14 15:39:04 -08:00
tbkka
184488d3f2 Conditionalize the fix for SR-14635 (#40822)
* Refactor Bincompat

Organize everything around internal functions that test for
a particular OS version.

Correctly handle cases where we don't know the version of the app.

Make all bincompat functions consistently return `true` for the
legacy semantics, `false` for new semantics.  Consistently name
them all to reflect this.

* Conditionalize the support for SR-14635

SR-14635 pointed out a hole in the updated dynamic casting logic
that allowed certain casts that should have been illegal.

In particular, when casting certain types to Obj-C protocols,
the Swift value gets boxed; we would permit the cast to succeed
whenever the resulting box satisfied the protocol.  For example,
this allowed any Swift value to be cast to `NSCopying` regardless of
whether or not it implemented the required `copy(with:)` method.

This was fixed in #37683 to reject such casts but of course some folks were
depending on this behavior to pass Swift data into Obj-C functions.
(The properly supported approach for passing arbitrary Swift data into
Obj-C functions is to cast the Swift value to `AnyObject`.)

This change makes that new behavior conditional.  For now,
the legacy semantics are enabled on Apple platforms and the
new semantics are in use everywhere else.  This will allow
us to gradually enable enforcement of the new behavior over
time.

* Just skip this test on Apple platforms, since it is inconsistently implemented there (and is therefore not really testable)
2022-01-14 11:56:25 -08:00
Holly Borla
992a871a73 [Type Reconstruction] Re-construct existential types with ExistentialType
by propagating whether the decoded type is for a requirement through
TypeDecoder.
2022-01-13 19:31:37 -08:00
Jonathan Grynspan
0db7b5abc4 Ensure Debug Help library calls on Windows are made in as thread-safe a manner as possible by wrapping them in a scoped lock. 2022-01-12 12:37:45 -05:00
David Smith
3d039251b4 Merge pull request #39378 from Catfish-Man/any-hashable-in-this-economy
Avoid protocol conformance lookups in more NSString bridging scenarios
2022-01-10 10:49:24 -08:00
Konrad `ktoso` Malawski
9438cf6b2e [Distributed] Func metadata operations and implement executeDistributedTarget entry (#40605)
* [Distributed] Implement func metadata and executeDistributedTarget

dont expose new entrypoints

able to get all the way to calling _execute

* [Distributed] reimplement distributed get type info impls

* [Distributed] comment out distributed_actor_remoteCall for now

* [Distributed] disable test on linux for now
2022-01-09 23:55:06 +09:00
David Smith
12166a9c2d Optimize NSString->AnyHashable and String->AnyHashable 2022-01-08 02:33:51 -08:00
swift-ci
bebe119eda Merge pull request #40573 from Catfish-Man/unicodectomy 2022-01-06 17:33:39 -08:00
David Smith
48399afb03 Merge branch 'main' into unicodectomy 2022-01-03 22:57:37 -08:00
Jonathan Grynspan
099fdc2e41 Fix an issue on COFF/ELF targets where the runtime would register each loaded image twice (at least early on.) 2022-01-01 11:39:25 -05:00
Kuba (Brecka) Mracek
663a6fb771 Introduce SWIFT_STDLIB_HAS_TYPE_PRINTING flag to remove the ability to print types at runtime (to save codesize) (#40649) 2021-12-21 17:47:54 -08:00
David Smith
f1a5e27821 Add a build flag to disable building Unicode support 2021-12-21 17:26:15 -08:00
Nate Chandler
150145263f [runtime] Fixed typo.
There was a call to addImageAccessibleFunctionBlockCallbackUnsafe but no
function with that name.  Change the called function to
addImageAccessibleFunctionsBlockCallbackUnsafe.
2021-12-21 13:39:20 -08:00
Arnold Schwaighofer
cf3951394a Revert "Fix an issue on COFF/ELF targets where the runtime would register each loaded image twice (at least early on.)" 2021-12-21 07:15:08 -08:00
John McCall
4b4ac29759 Merge pull request #40647 from rjmccall/uncondition-variables
Remove dead code: override jobs and condition variables
2021-12-20 22:25:16 -05:00
John McCall
3343331ded Remove the ConditionVariable abstraction. 2021-12-20 18:04:19 -05:00
Jonathan Grynspan
7fe5ea7398 Fix an issue on COFF/ELF targets where the runtime would register each loaded image twice (at least early on.) 2021-12-20 15:15:02 -05:00
Pavel Yaskevich
d65906b1e8 [Runtime] Expose accessible function lookup as stdlib SPI
`findAccessibleFunction` has to be accessible from Concurrency
and Distributed modules to be able to lookup distributed accessors.
2021-12-17 10:52:56 -08:00
Pavel Yaskevich
7eee8c0dd2 [Distributed] Runtime: Cache previously requested accessible functions 2021-12-17 10:52:56 -08:00
Pavel Yaskevich
3f4c06eb1b [Distributed] Runtime: Add skeleton support for accessible function sections 2021-12-17 10:52:56 -08:00
Kuba (Brecka) Mracek
c92f2a24ed When ptrauth-copying vtable/wtables, allow NULL entries (due to VFE) (#40578)
* When ptrauth-copying vtable/wtables, allow NULL entries (due to VFE)

* Mark virtual-function-elimination-generics-exec.swift UNSUPPORTED: arm64e until the rebranch

* Fix test expectations
2021-12-16 16:49:24 -08:00
John McCall
4969407352 Merge pull request #40542 from rjmccall/atomic-wait-queue-metadata
Eliminate priority inversions in the metadata completion runtime
2021-12-15 21:42:17 -05:00
Kuba Mracek
c10c1bbe5e When SWIFT_ENABLE_REFLECTION is Off, don't build the reflection runtime code (stdlib/public/Reflection/*.cpp) 2021-12-15 09:13:06 -08:00
John McCall
749ed09f8c Eliminate priority inversions in the metadata completion runtime.
The current system is based on MetadataCompletionQueueEntry
objects which are allocated and then enqueued on dependencies.
Blocking is achieved using a condition variable associated
with the lock on the appropriate metadata cache.  Condition
variables are inherently susceptible to priority inversions
because the waiting threads have no dynamic knowledge of
which thread will notify the condition.  In the current system,
threads that unblock dependencies synchronously advance their
dependent metadata completions, which means the signaling
thread is unreliable even if we could represent it in condition
variables.  As a result, the current system is wholly unsuited
for eliminating these priority inversions.

An AtomicWaitQueue is an object containing a lock.  The queue
is eagerly allocated, and the lock is held, whenever a thread
is doing work that other threads might wish to block on.  In
the metadata completion system, this means whenever we construct
a metadata cache entry and the metadata isn't already allocated
and transitively complete after said construction.  Blocking
is done by safely acquiring a shared reference to the queue
object (which, in the current implementation, requires briefly
taking a lock that's global to the surrounding metadata cache)
and then acquiring the contained lock.  For typical lock
implementations, this avoids priority inversions by temporarily
propagating the priority of waiting threads to the locking
threads.

Dependencies are unblocked by simply releasing the lock held
in the queue.  The unblocking thread doesn't know exactly what
metadata are blocked on it and doesn't make any effort to
directly advance their completion; instead, the blocking
thread will wake up and then attempt to advance the dependent
metadata completion itself, eliminating a source of priority
overhang that affected the old system.  Successive rounds of
unblocking (e.g. when a metadata makes partial progress but
isn't yet complete) can be achieved by creating a new queue
and unlocking the old one.  We can still record dependencies
and use them to dynamically diagnose metadata cycles.

The new system allocates more eagerly than the old one.
Formerly, metadata completions which were never blocked never
needed to allocate a MetadataCompletionQueueEntry; we were
then unable to actually deallocate those entries once they
were allocated.  The new system will allocate a queue for
most metadata completions, although, on the positive side,
we can reliably deallocate these queues.  Cache entries are
also now slightly smaller because some of the excess storage
for status has been folded into the queue.

The fast path of an actual read of the metadata remains a
simple load-acquire.  Slow paths may require a bit more
locking.  On Darwin, the metadata cache lock can now use
os_unfair_lock instead of pthread_mutex_t (which is a massive
improvement) because it does not need to support associated
condition variables.

The excess locking could be eliminated with some sort of
generational scheme.  Sadly, those are not portable, and I
didn't want to take it on up-front.

rdar://76127798
2021-12-14 22:18:46 -05:00
Alejandro Alonso
8a5f728daf Merge pull request #40340 from Azoy/drop-icu
[stdlib] Drop ICU
2021-12-07 01:44:38 -08:00