Use information from reflection section of the binary to lookup
type field info such as name and it's type and return it using
new `swift_getFieldAt` method based on nominal type and field index.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
When evaluating whether a given type conforms to a protocol, evaluate the
conditional requirements and pass the results to the witness table
accessor function. This provides the ability to query conditional
conformances at runtime, and is the last major part of implementing
SE-0143.
The newly-added unlock/lock dance in the conformance lookup code is a
temporary stub. We have some ideas to do this better.
Fixes rdar://problem/34944655.
Extend protocol conformance descriptors with two more bits of information:
* For retroactive conformances, add the module in which the conformance
occurs. This will eventually be used for error reporting/ambiguity
resolution when retroactive conformances collide.
* For conditional conformances, add the conditional requirements. We need
these for runtime evaluation of conditional conformances.
RelativeDirectPointerIntPair uses the alignment of the pointer to determine
how many low bits are in the tiny integer value. This led to an inconsistency
between the runtime view of TargetGenericParamRef (which expected the
Boolean flag to be in the lower two bits) and the compiler's view
(which put the Boolean flag in the lowest bit), causing crashes.
Extend support for mapping a mangled name -> type metadata to include
support for checking protocol conformance requirements, using the
encoding of generic requirements that is now available within context
descriptors. For example, this allows
_typeByMangledName(mangled-name-of-Set<Int>) to construct proper type
metadata, filling in the Int: Hashable requirement as appropriate.
We dump the following information:
1. The Kind.
2. Pointer to the value witnesses.
3. Pointer to the class object if one is available.
4. Pointer the type context description if one is available.
5. Pointer to the generic arguments if one is available.
This makes it significantly easier to poke around Metadata.
rdar://34222540
This is useful when trying to track down data corruption in the runtime. I am
currently running into such issues with the +0-all-arg work, so I am adding
stuff like this to help debug this issue and future such issues.
rdar://34222540
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
* Remove RegisterPreservingCC. It was unused.
* Remove DefaultCC from the runtime. The distinction between C_CC and DefaultCC
was unused and inconsistently applied. Separate C_CC and DefaultCC are
still present in the compiler.
* Remove function pointer indirection from runtime functions except those
that are used by Instruments. The remaining Instruments interface is
expected to change later due to function pointer liability.
* Remove swift_rt_ wrappers. Function pointers are an ABI liability that we
don't want, and there are better ways to get nonlazy binding if we need it.
The fully custom wrappers were only needed for RegisterPreservingCC and
for optimizing the Instruments function pointers.
Extend protocol descriptors with a field for the superclass bound of the
protocol itself. This carves out space in the ABI for
class C { }
protocol P : C { ... }
although the feature is not yet implemented.
Emit protocol conformance descriptors as separate symbols, rather than
inlining them within the section for protocol conformance records. We
want separate symbols for protocol conformances both because it is easier
to make them variable-length (as required for conditional
conformances) and because we want to reference them from witness
tables (both of which are coming up).
Protocol conformance records are becoming richer and more interesting;
separate out the "flags" word and add the various other fields that we
want there (is-retroactive, is-synthesized-nonunique, # of conditional
requirements).
Support demangling bound generic types (e.g., Array<Int>) and forming
type metadata for them. For now, only support non-nested generic types
with up to three generic parameters.
Extend the protocol descriptor with a (space-separated) list of associated
type names, in the order of their requirements. Use this information in
the runtime to support lookup of associated type witnesses by name when
mapping a mangled name to a type and substituting generic parameters.
Swift-defined @objc protocols are registered with the Objective-C runtime
under the Swift 3 mangling scheme; look in the Objective-C runting using
objc_getProtocol() with the appropriate name.
Also, correctly compute the "class bound" bit when forming a protocol
composition metatype. The information isn't in the mangled name when it
can be recovered from the protocols themselves, so look at the protocols.
Search through the new section containing Swift protocol descriptor
references to resolve protocols by mangled name. Use this
functionality to support protocol composition types within
_typeForMangledName.
Introduce a new section that contains (relative) references to all of the
Swift protocol descriptors emitted into this module. We'll use this to
find protocol descriptors by name.
TypeDecoder's interface with its builders already treated protocols as
a type (due to their being mangled as "protocol composition containing
one type"), and intermixed protocols with superclasses when forming
compositions. This makes for some awkwardness when working with
protocol descriptors, which are very much a distinct entity from a
type.
Separate out the notion of a "protocol declaration" (now represented
by the builder-provided BuiltProtocolDecl type) from "a protocol
composition containing a single type", similarly to the way we handle
nominal type declarations. Teach remote mirrors and remote AST to
handle the new contract.
Introduce a flags parameter to swift_getTupleTypeMetadata(). Add a flag
stating when the "labels" parameter points into nonconstant memory, in
which case we need to make a copy of the string before adding an entry
into the concurrent map.
Since it's not very common to use such ABI endpoints, let's remove
them and use the most general one `swift_getFunctionTypeMetadata`
instead when function parameters have flags attached to them.
Resolves: rdar://problem/36278686
This ABI endpoint is used to retrieve metadata about functions
without parameters. Which is very common use-case and it
makes sense to save some code size for that.
Now that we use nominal type descriptors for everything that we can within
protocol conformance records, eliminate the unused
"NonuniqueDirectType" case and all of the code that supports it. Leave
this value explicitly reserved for the future.
Nominal type descriptors are not always unique, so testing them via pointer
equality is not correct. Introduce an "isEqual()" operation for
nominal type descriptors that performs the appropriate equality check,
using pointer equality when possible, and falling back to string
comparisons of the mangled type name when it is not possible.
Introduce a "nonunique" flag into nominal type descriptors to describe
when they are, in fact, not unique. The only nonunique nominal type
descriptors currently come from Clang-imported types; all
Swift-defined types have unique nominal type descriptors. Use this
flag to make the aforementioned operation efficient in the "unique"
case.
Use the new isEqual() operation for protocol conformance lookup, and
make sure we're caching results based on the known-canonical nominal
type descriptor.
The separate section of type references uses the same type reference format
as in protocol conformance records. As with protocol conformance records,
mangle the type reference kind into the lower two bits. Then, eliminate the
separate "flags" field from the type metadata record. Finally, rename
the section because the Swift 5 stable format for this section is
different from prior formats, and the two runtimes need to be able to
coexist.