Commit Graph

461 Commits

Author SHA1 Message Date
Pavel Yaskevich
877c70bae9 [Runtime/Metadata] Add support for dynamic field descriptor registration 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
0da5e48a0e [Runtime/Reflection] Add swift_getFieldAt runtime accessor
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.
2018-02-20 18:20:09 -08:00
John McCall
23fa44e56c Render TypeContextDescriptor into a proper hierarchy; NFC.
The purpose here is to make it easier to add type-specific fields to the
descriptor.
2018-02-20 15:20:32 -05:00
Pavel Yaskevich
73f09ecbf5 [Runtime] Existential types marked as @objc should satisfy class requirement
Make sure that `checkGenericRequirements` properly enforces
"class requirement" constraint on the generic parameters.
2018-02-14 21:16:44 -08:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
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.
2018-02-10 10:43:47 -08:00
Arnold Schwaighofer
d981bb1d96 Mangling: noescape functions will be trivial and no longer compatible with escape function types.
Mangle escapeness as part of the type.

Part of:
SR-5441
rdar://36116691
2018-02-06 08:51:43 -08:00
Doug Gregor
93442cf11f [Runtime] SE-0143: Evaluate conditional conformances at runtime.
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.
2018-02-02 16:41:27 -08:00
Doug Gregor
b9e91e3934 [ABI] Describe module context and conditional requirements of conformances.
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.
2018-02-02 16:41:27 -08:00
Doug Gregor
6dc429af43 Merge pull request #14327 from DougGregor/demangle-to-metadata-generic-reqs
Check generic requirements in `_typeByMangledName`.
2018-02-01 16:07:29 -08:00
Doug Gregor
7f926809e7 [Runtime] Fix accessors for TargetGenericParamRef.
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.
2018-02-01 14:45:13 -08:00
Doug Gregor
8c4d86c74a [Mangled name -> metadata] Check generic protocol conformance requirements.
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.
2018-02-01 14:43:24 -08:00
Doug Gregor
82259e11f1 [Runtime] Make type context descriptor accessor for TargetTypeMetadataRecord robust.
Don't assert if we have an unexpected kind; return null so the caller
can handle it.
2018-02-01 14:41:53 -08:00
Michael Gottesman
6ac81e5489 [metadata] Add dump to Metadata.
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
2018-02-01 13:29:08 -08:00
Michael Gottesman
8e4024328e [runtime] Add support for dumping ProtocolDescriptor/ProtocolDescriptorFlags.
This is only enabled when the runtime is compiled with assertions. This will
make it easier to debug the runtime.

rdar://34222540
2018-02-01 08:53:33 -08:00
Michael Gottesman
e3342c753c [runtime] Add support for verifying at runtime that a protocol descriptive has a valid type kind/conformance kind.
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
2018-02-01 08:53:13 -08:00
Joe Groff
d974ee4acc Runtime: Wrap the metadata access function pointer in a functor that calls it properly.
Provide a bit of type safety for parts of the runtime that may want to invoke it, and centralize the logic for handling its calling convention.
2018-01-31 20:37:05 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
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.
2018-01-29 16:19:25 -08:00
Greg Parker
e223f1fc9b [IRGen][runtime] Simplify runtime CCs and entry point ABIs (#14175)
* 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.
2018-01-29 13:22:30 -08:00
Pavel Yaskevich
07534a6464 [Runtime] NFC: Create a .def file with all supported built-in types 2018-01-23 23:40:13 -08:00
Doug Gregor
eb4f9a3d4c [ABI] Reserve space in the protocol descriptor for the superclass.
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.
2018-01-19 14:03:24 -08:00
Doug Gregor
e614f6650b [Runtime] Give some structure to witness tables.
Make it easier to access the protocol conformance descriptor.
2018-01-18 17:13:14 -08:00
Doug Gregor
e766473ed9 [ABI] Emit separate symbols for protocol conformance descriptors.
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).
2018-01-17 10:35:16 -08:00
Doug Gregor
663d6af063 [ABI] Factor out the protocol conformance flags (again).
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).
2018-01-17 10:06:07 -08:00
Doug Gregor
a2d97719d3 [Runtime] Support nested generic types in mangled name -> type metadata. 2018-01-12 15:35:12 -08:00
Doug Gregor
0b62e4000f [Mangled name -> type] Support simple generic types up to 3 arguments.
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.
2018-01-12 15:35:12 -08:00
Doug Gregor
fc55835483 [IRGen/Metadata] Minor fixes for associated type witness name testing. 2018-01-11 21:35:39 -08:00
Doug Gregor
3405852ef0 [Runtime] Find metadata for substitutions into demangled dependent members.
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.
2018-01-11 16:04:53 -08:00
Doug Gregor
adf38f5486 [Runtime] Pack element count into the flags of swift_getTupleTypeMetadata.
Reduces the # of parameters we need to pass to this runtime API.
2018-01-11 10:06:57 -08:00
Doug Gregor
c302042dc5 [Runtime] Lookup @objc protocols in mangled name -> type metadata function.
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.
2018-01-10 16:21:42 -08:00
swift-ci
ea489cead0 Merge pull request #13844 from DougGregor/runtime-protocol-name-lookup 2018-01-09 23:06:09 -08:00
Doug Gregor
a7fef62a44 [Runtime] Search through protocols to resolve protocol declarations.
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.
2018-01-09 20:17:44 -08:00
Doug Gregor
0f4963dba8 [IRGen] Put references to all emitted protocols into a special section.
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.
2018-01-09 16:10:18 -08:00
swift-ci
fc4d66d269 Merge pull request #13827 from DougGregor/type-decoder-protocol-composition 2018-01-09 15:39:45 -08:00
Doug Gregor
61884f7702 [Type decoder] Rework the builder contract for protocols.
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.
2018-01-09 10:46:31 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Doug Gregor
5853cf3c87 [Runtime] Teach swift_getTupleTypeMetadata() to copy "labels" string.
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.
2018-01-05 23:11:21 -08:00
Pavel Yaskevich
fc64e34c8e Merge pull request #13701 from xedin/rdar-36278686
[Runtime/ABI] Optimize number of function metadata ABI endpoints
2018-01-05 21:47:13 -08:00
Pavel Yaskevich
86de71ee6d [Runtime/ABI] Remove swift_getFunctionTypeMetadata{1-3}WithFlags
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
2018-01-04 16:32:51 -08:00
Pavel Yaskevich
8409cdb8a2 [Runtime/ABI] Add swift_getFunctionTypeMetadata0 function
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.
2018-01-04 16:32:51 -08:00
Pavel Yaskevich
d787a14d6c [Runtime] NFC: Remove getThinFunctionTypeMetadata* stubs 2018-01-04 16:32:51 -08:00
Pavel Yaskevich
300587a507 [Runtime] NFC: Remove getCFunctionTypeMetadata* stubs 2018-01-04 16:32:51 -08:00
Pavel Yaskevich
08ed42076d [Runtime] NFC: Remove getBlockTypeMetadata* API stubs 2018-01-04 16:32:51 -08:00
Doug Gregor
cc3e3701b2 [Runtime] Eliminate the now-unused "NonuniqueDirectType" type reference kind.
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.
2018-01-04 13:21:58 -08:00
Doug Gregor
6118d86032 [Runtime] Introduce equality operation for nominal type descriptors.
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.
2018-01-04 12:36:34 -08:00
Doug Gregor
7458640883 [Runtime] Add nominal type descriptor field to foreign class metadata.
Like other nominal type metadata, include a nominal type descriptor in
foreign class metadata.
2018-01-04 10:12:19 -08:00
Slava Pestov
f18ef548d7 Runtime: Code cleanups based on code review feedback 2018-01-03 19:30:30 -08:00
Doug Gregor
0632d8763a Merge pull request #13685 from DougGregor/protocol-conformance-record-cleanup
[Runtime] Improve representation of protocol conformance records
2018-01-03 14:11:00 -08:00
Doug Gregor
3219047783 [Runtime] Clean up TypeMetadataRecordKind and TargetProtocolConformanceRecord.
Per JoeG's comments, thanks!
2018-01-03 13:21:10 -08:00
Doug Gregor
310bd6be48 [Runtime] Mangle the reference kind in the lower two bits of type references.
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.
2018-01-03 10:49:21 -08:00
Doug Gregor
bfd2230c6d [Runtime] Eliminate ProtocolConformanceFlags.
Eliminate the separate flags field in protocol conformance records, now that
all of the information is stored in spare bits elsewhere. Reserve this
32-bit value for future use to describe conditional requirements.
2018-01-03 10:49:21 -08:00