Commit Graph

842 Commits

Author SHA1 Message Date
Pavel Yaskevich
05ff9d8011 Merge pull request #42311 from xedin/ptrauth-for-dist
[Runtime] Add pointer auth to accessible function section/cache
2022-04-13 09:33:00 -07:00
John McCall
6385934d7e Metadata emission for extended existential type shapes 2022-04-12 14:52:47 -04:00
Pavel Yaskevich
8cfb4ea087 [ABI/Runtime] Add pointer auth primitiives for accessible functions 2022-04-11 11:04:20 -07:00
Yuta Saito
ed7ab2a5a3 [Wasm][KeyPath] Resolve absolute function pointer as identity
Emit and resolve idValue of KeyPath as an absolute pointer if relative
function pointer is turned-off on Wasm target.
The existing ABI can't distinguish an idValue between function pointer
or data pointer in use-site at compile-time and also at runtime. So this
patch adds a new id resolution scheme `ResolvedAbsolute` to distinguish
them at runtime properly.
2022-04-02 16:25:23 +00:00
Yuta Saito
8c598e98f7 [Wasm][Runtime] Interpret absolute function pointer in runtime structures
When SWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER is enabled, relative direct
pointers whose pointees are functions will be turned into absolute
pointer at compile-time.
2022-04-02 04:32:41 +00:00
John McCall
148357f899 Implement extended existential shapes and type metadata.
The immediate use case is only concretely-constrained existential
types, which could use a much simpler representation, but I've
future-proofed the representation as much as I can; thus, the
requirement signature can have arbitrary parameters and
requirements, and the type can have an arbitrary type as the
sub-expression.  The latter is also necessary for existential
metatypes.

The chief implementation complexity here is that we must be able
to agree on the identity of an existential type that might be
produced by substitution.  Thus, for example, `any P<T>` when
`T == Int` must resolve to the same type metadata as
`any P<Int>`.  To handle this, we identify the "shape" of the
existential type, consisting of those parts which cannot possibly
be the result of substitution, and then abstract the substitutable
"holes" as an application of a generalization signature.  That
algorithm will come in a later patch; this patch just represents
it.

Uniquing existential shapes from the requirements would be quite
complex because of all the symbolic mangled names they use.
This is particularly true because it's not reasonable to require
translation units to agree about what portions they mangle vs.
reference symbolically.  Instead, we expect the compiler to do
a cryptographic hash of a mangling of the shape, then use that
as the unique key identifying the shape.

This is just the core representation and runtime interface; other
parts of the runtime, such as dynamic casting and demangling
support, will come later.
2022-03-27 18:24:17 -04:00
John McCall
01e0f37399 [NFC] Infrastructure to avoid storing simple generic params in metadata
The vast majority of generic parameters follow a simple pattern
(type parameter that defines a key argument), which we can take
advantage of to avoid actually representing them in type metadata:
if all the type arguments is the simple pattern, and there's not
more than some preset number, simply use a pre-allocated array in
the runtime.

Actually doing this for generic types will require some care around
back-deployment, as well as finding a bit to store that we've done
it.  But we can at least start doing this for new ABI, such as the
extended existential shape descriptors.
2022-03-27 14:11:20 -04:00
John McCall
ebd73893b4 [NFC] Add RuntimeGenericSignature
This encapsulates the ABI representation of a generic signature, which
can be used in multiple places in the system.
2022-03-24 00:53:45 -04:00
John McCall
78de2fba7d [NFC] Move generic contexts and metadata references into separate headers 2022-03-23 02:18:39 -04:00
John McCall
e2332a34bc [NFC] Move ValueWitnessTable layout into its own file
I've also target-ified EnumValueWitnessTable while I was at it.
2022-03-22 21:58:27 -04:00
John McCall
cb3818ea16 [NFC] Split the basic target-layout logic into its own file 2022-03-22 21:58:27 -04:00
John McCall
1b910f539b [NFC] Document the fields in an ABI generic context header 2022-03-22 18:45:48 -04:00
Ben Langmuir
779bdf0bf3 Merge pull request #41550 from benlangmuir/make-next-less-sad
Pre-fix some build failures that we'll see with newer llvm
2022-03-02 09:23:07 -08:00
John McCall
aca744b211 Remove the Flags field from AsyncContext.
Generated code has never actually initialized this field, so we
might as well remove it.  Doing so mostly doesn't impact the ABI
since we don't store anything for arguments or results in the
context as part of the normal call sequence.  We do need to adjust
some of the hard-coded contexts, however, such as continuation
contexts and the statically-sized context for special runtime
async functions.
2022-02-25 16:57:49 -05:00
Ben Langmuir
5a5dd13ca1 Include what you use: Optional and Hashing
Add a few includes of Optional.h and Hashing.h. These files are failing
ot build in the "next" branch due to changes in llvm's own includes, but
it's general goodness to include them on main as well.
2022-02-24 13:47:04 -08:00
Augusto Noronha
87d41a4e27 Merge pull request #41454 from augusto2112/add-dwarf-segment
Make ObjectFile aware that the DWARF segment may contain Swift metadata
2022-02-19 18:56:56 -03:00
Augusto Noronha
49275a9091 Make ObjectFile aware that the DWARF segment may contain Swift metadata 2022-02-18 12:40:34 -03:00
Shubham Sandeep Rastogi
9315e922ea Use Swift.def to define enums and switch cases for swift5 reflection sections 2022-02-11 14:40:52 -08:00
Pavel Yaskevich
f75ed39f97 Merge pull request #41323 from xedin/update-object-file
[ABI] Add "accessible functions" section to object format
2022-02-11 00:40:33 -08:00
Pavel Yaskevich
bc013b3e4e [ABI] Add "accessible functions" section to object format 2022-02-10 12:12:31 -08:00
Rokhini Prabhu
6beb11ed7d Rename flagAsEnqueuedOnExecutor to flagAsAndEnqueueOnExecutor to reflect
what it actually does.

Radar-Id: rdar://problem/88600541
2022-02-10 11:50:31 -08:00
Rokhini Prabhu
d77edf6cd9 Merge pull request #41088 from apple/rokhinip/76127624-task-priority-escalation
Task Priority Escalation
2022-02-08 10:00:55 -08:00
Rokhini Prabhu
66d4af0b01 Task priority escalation on Apple platforms
A task can be in one of 4 states over its lifetime:

    (a) suspended
    (b) enqueued
    (c) running
    (d) completed

This change provides priority inversion avoidance support if a task gets
escalated when it is in state (a), (c), (d).

Radar-Id: rdar://problem/76127624
2022-02-07 16:34:46 -08:00
Rokhini Prabhu
519e60c43e Allow concurrent modifications to the ActiveTaskStatus while another
thread has the task status record lock.

Today, if a thread is holding the StatusRecordLock, then no other
modification of the task status is possible - including a thread
starting to execute the task or stopping execution of the task.
However, the TaskStatusRecordLock is really about protecting the linked
list that is maintained in the ActiveTaskStatus. As such, other
operations which don't need to look at that linked list of us records
really shouldn't have to block on the StatusRecordLock.

This change allows for concurrent modification of the veTaskStatus while
the TaskStatusRecordLock is held. In particular, a task can cancelled,
escalated, start and stop running, all while another ad is holding onto
the task's StatusRecordLock. In the event of cancellation and
escalation, the task's StatusRecordLock must be n in order to propagate
cancellation and escalation to its child tasks is not needed to cancel
or escalate the task itself.

Radar-Id: rdar://problem/76127624
2022-02-07 16:34:46 -08:00
Dave Lee
dee4c5dbf5 [Reflection] Add __TEXT to sectionContainsReflectionData 2022-02-07 15:15:11 -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
David Smith
039403c236 Merge pull request #41165 from Catfish-Man/linked-lost
Fix SR-15785 by adding a cached reference to the last linked list node, avoiding n^2 append scaling
2022-02-03 11:40:33 -08:00
David Smith
1707ffebfe Review feedback 2022-02-02 16:28:53 -08:00
David Smith
df577f2c5b Fix SR-15785 by adding a cached reference to the last linked list node, avoiding n^2 append scaling 2022-02-02 14:02:12 -08:00
Artem Chikin
b4926dffe7 Merge pull request #41027 from artemcm/AddConformanceMetadataReader
Add extraction of protocol conformance descriptor info, as read from an object file image, to `TypeRefBuilder`.
2022-02-01 18:05:48 -08:00
Artem Chikin
5d17074222 [Static Mirror] Allow ObjCInteropKind to be specified by the client of conformanceReader, separately from how the client builds. 2022-02-01 10:56:58 -08:00
Dave Lee
9d80ea21ba use startswith for elf and coff too 2022-01-31 15:28:22 -08:00
Dave Lee
fd3054533b describe how sectionContainsReflectionData is called 2022-01-31 15:18:16 -08:00
Dave Lee
1d5b4bebbe __DATA,__const too 2022-01-28 15:18:34 -08:00
Dave Lee
e1a39bf059 use startswith for macho and add header doc 2022-01-28 15:18:33 -08:00
Dave Lee
e2be9a3ec7 [ABI] Add predicate to identify sections containing reflection data 2022-01-28 15:18:03 -08:00
Artem Chikin
cd6d8f975f Extract fully-qualified names for protocol conformances by traversing their parent contexts and extracting their names 2022-01-28 10:51:48 -08:00
Artem Chikin
59d1960c7c Add support for reading protocol descriptors from an indirect protocol descriptor target in an conformance descriptor.
Previously, the code assumed that such an indirect target will always point to an external symbol pointer, but it can also be an absolute pointer to an in-image protocol descriptor.
2022-01-27 10:55:29 -08:00
Augusto Noronha
8849acf096 Merge pull request #41021 from augusto2112/reflection-segment-name
Specify the segment name that contains the reflection sections.
2022-01-27 11:44:55 -03:00
Artem Chikin
e934fe201a Add extraction protocol conformance descriptor extraction, as read from an object file image, to TypeRefBuilder. 2022-01-26 13:54:02 -08:00
Augusto Noronha
6e088c3863 Specify the segment name that contains the reflection sections. 2022-01-26 18:13:31 -03:00
Pavel Yaskevich
ac875d00f0 Merge pull request #40947 from xedin/generic-dist-funcs
[Distributed] Augment accessor to support calling generic distributed thunks
2022-01-25 22:51:23 -08:00
Rokhini Prabhu
f5e5a07230 Merge pull request #40718 from apple/rokhinip/86100376-change-task-propagation-rules
Change task priority propagation rules
2022-01-25 12:13:11 -08:00
Artem Chikin
d6d4216371 Add Conformance section to ReflectionInfo read from object files 2022-01-24 16:46:35 -08:00
Pavel Yaskevich
2bd7a49d75 [IRGen] Record generic environment associated with accessible function
Without this piece of information it wouldn't be possible to form
a call to the recorded function at runtime if it's generic.
2022-01-24 10:17:59 -08:00
Rokhini Prabhu
a2a5c64d4b Change task's base and escalated priority propagation rules for
detached, unstructured and structured concurrency child tasks

Radar-Id: rdar://problem/86100376
2022-01-24 07:50:28 -08:00
Rokhini Prabhu
9df1c9a135 Track base priority separately from max priority whereby base priority
is set at creation time. Create a new API for accessing this state

Radar-Id: rdar://problem/86100376
2022-01-24 07:50:27 -08:00
Saleem Abdulrasool
f87a0d4afd ABI: repair the build after #40927
This fixes the build on Windows by fixing the template code.  The
template type was not qualified and caused an ambiguity in the name
resolution with the local typename and the previously declared
namespaced name.
2022-01-21 15:56:29 -08:00
Rokhini Prabhu
6d5c7b5797 NFC: Rename priority set during task creation to be RequestedPriority
Radar-Id: rdar://problem/86100376
2022-01-21 12:12:12 -08: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