Commit Graph

3157 Commits

Author SHA1 Message Date
Mike Ash
d61fee3884 [Runtime] Check the weak-linked _dyld_has_preoptimized_swift_protocol_conformances for NULL before calling it.
rdar://89522018
2022-03-02 14:24:12 -05:00
Mike Ash
504584c2a9 Merge pull request #41501 from mikeash/protocol-conformance-dyld-fixes
[Runtime] Fix dyld protocol conformances.
2022-02-22 12:23:53 -05:00
Tim Kientzle
4d91b45988 [RemoteMirror] Get spare bit info from reflection records (#40906)
This adds a new reflection record type carrying spare bit information for multi-payload enums.

The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask.

A few notes:
 * The internal calculation is not perfect.  In particular, it does not support MPEs that contain other enums (e.g., optionals).  It should accurately refuse to project any MPE that it does not correctly support.
 * The new reflection field is designed to be expandable; this might someday avoid the need for a new section.

Resolves rdar://61158214
2022-02-21 17:06:14 -08:00
Mike Ash
99752c5d08 [Runtime] Fix dyld protocol conformances.
Leftover code was overwriting the result from the `on_disk` calls. Don't do that.

While we're in there, change the name of the `DYLD_CONFORMANCES_LOG` macro to `DYLD_CONFORMANCES_LOG` and fix up the wording to be more general.

rdar://89154273
2022-02-21 15:47:21 -05:00
Karoy Lorentey
b0a60faf08 [runtime][NFC] Unify reportOnCrash implementations into a single function 2022-02-18 15:02:40 -08:00
Arnold Schwaighofer
62ec31a462 Merge pull request #41338 from aschwaighofer/reuse_contiguous_array_storage_metadata
Reuse `_ContiguousArrayStorage<AnyObject>` metadata for any class or objc generic type
2022-02-17 12:47:23 -05:00
Rokhini Prabhu
4c736b0507 Create the notion of an ActiveActorStatus which captures the atomic
state of the actor similar to the ActiveTaskStatus. Refactor the default
actor runtime implementation to set us up for priority escalation
support

Radar-Id: rdar://problem/86100521
2022-02-16 10:21:40 -08:00
Arnold Schwaighofer
9f2b6a4ebb Reuse _ContiguousArrayStorage<AnyObject> metadata for any class or objc generic type
Reduces the number of _ContiguousArrayStorage metadata.

In order to support constant time bridging we do need to set the correct
metadata when we bridge to Objective-C. This is so that the type check
succeeds when bridging back from Objective-C to reuse the storage
instance rather than bridging the elements.

To support dynamically setting the `_ContiguousArrayStorage` element
type i needed to add support for optimizing `alloc_ref_dynamic`
throughout the optimizer.

Possible future improvements:
* Use different metadata such that we can disambiguate native Swift
  classes during destruction -- allowing native release rather then unknown
  release usage.
* Optimize the newly added semantic function
  getContiguousArrayStorageType

rdar://86171143
2022-02-16 07:55:34 -08:00
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