Commit Graph

381 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
caf73113ea [Runtime/Metadata] Add ownership information to _getTypeByMangledName
`_typeByMangledName` could encounter types which have ownership attributes
associated with them which are not representable by the metadata object
but nevertheless are important, so such ownership information should be
returned along with metadata itself from the call.
2018-02-05 15:26:11 -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
5c59e81480 [Runtime] Evaluate same-type requirements at runtime.
Extend the runtime's ability for evaluating generic requirements to
handle same-type requirements, demangling/substituting the name from
the generic requirement metadata.
2018-02-01 17:00:51 -08:00
Doug Gregor
f8c769c4ae [Demangle-to-type] Handle type arguments and requirements for nested generics.
Extend the support for mangled-name-to-type-metadata's handling of generic
types to handle nested types, including gathering type arguments from
parent contents and checking generic requirements.
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
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
Pavel Yaskevich
86916cf4d8 [Mangled name -> metadata] Add built-in types support 2018-01-24 00:29:24 -08:00
Doug Gregor
2c9ad900ae [Mangled name -> metadata] Handle import-as-member types.
When import-as-member takes a C type and imports it as a nested type,
we end up with a nominal type descriptor for a nested type, but the
mangled name remains "flat". Cope with inconsistency to allow
_typeByMangledName() to handle such nested types.
2018-01-19 23:32:51 -08:00
Doug Gregor
40283f9b73 [ABI] Add the protocol conformance descriptor into a witness table.
Extend witness tables with a pointer to the protocol conformance
descriptor from which the witness table was generated. This will allow
us to determine (for example) whether two witness tables were
generated from the same (or equivalent) conformances in the future, as
well as discover more information about the witness table itself.

Fixes rdar://problem/36287959.
2018-01-18 17:13:13 -08:00
Doug Gregor
59c98e6ecf [Mangled name -> type metadata] Support arbitrary # of generic args.
Now that we have a suitable calling convention for the access function
of a generic nominal type descriptor with > 3 arguments, add support
for calling with an arbitrary number of generic arguments.
2018-01-13 22:34:51 -08:00
Doug Gregor
d0b73b85d0 [Type decoder] Generalize the canonicalization of nominal type decl references.
Various TypeDecoder clients will depend on having the "bare" nominal
type declaration demangled node for looking up nominal type descriptors,
so move the generic argument-stripping code into TypeDecoder.
2018-01-12 15:35:12 -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
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
cd1bd20fce [Runtime mangling -> meadata] Support type parameter substitutions.
Extend _typeByMangledName with support for user-provided type parameter
substitutions, where type parameters that occur in the mangling can be
replaced with specific types.
2018-01-11 11:08:57 -08:00
Doug Gregor
93cd5e8270 [ABI] Make TargetTupleTypeFlags size_t sized and move “labels” bit.
Addresses feedback from @rjmccall.
2018-01-11 11:08:12 -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
759f4c3a2c [Runtime] Skip Objective-C type records when looking for types.
When we scan the type metadata records or conformances to look
for a type by name, skip over indirect Objective-C class
references. We won’t find anything new there, but we’ll 
currently crash if they exist.
2018-01-11 00:14:41 -08:00
Doug Gregor
efde1dfc35 [Runtime] Support lookup of Objective-C classes.
Classes defined in Objective-C are mangled differently from
Swift-defined classes, and have no nominal type
descriptor. Recognize this mangling and search for the
appropriate Objective-C class using the Objective-C
runtime. Thread the resulting metadata through the mangled name
-> metadata decoder.
2018-01-10 16:56:51 -08:00
Doug Gregor
9916fdf17e [Runtime] Support lookup of Objective-C protocols.
Protocols defined in Objective-C are mangled differently from
Swift-defined protocols. Recognize this mangling and search for the
appropriate Objective-C protocol using the Objective-C runtime.
2018-01-10 16:46:12 -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
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
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
Doug Gregor
f1821c6f9a [Runtime] Remove the older _getTypeByName entry point.
_getTypeByMangledName() is more general and will be the way forward. Use
that instead. Note that we're still keeping around Foundation-only SPI
function _typeByName() in the Swift standard library, until we settle
on what the standard library API should be like for this functionality.
2018-01-07 00:01:33 -08:00
Doug Gregor
909e882110 [Runtime] Support "ModuleName.ClassName" syntax for mangled type lookup. 2018-01-06 23:56:51 -08:00
Doug Gregor
5bf11b1981 [Runtime] Find nominal type descriptors by mangled name.
Now that all nominal types have nominal type descriptors, directly
search for nominal type descriptors when looking up metadata by
mangled name. This eliminates some bouncing between metadata and
nominal type descriptor when decoding a mangled name.
2018-01-06 23:49:04 -08:00
Doug Gregor
78e8ad87be [Runtime] Find (simple) nominal types based on a mangled name. 2018-01-06 23:30:31 -08: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
Doug Gregor
5f51df4b92 [Runtime] Add missing #include 2018-01-05 20:12:29 -08:00
Doug Gregor
04a151d8a0 [Runtime] Form existential types and existential types based on mangled names.
Introduce basic support for existential types (just Any and AnyObject), so
we can test those, shared/owned parameters, and existential metatypes.
2018-01-05 16:56:56 -08:00
Doug Gregor
33f89a1344 [Runtime] Form metatypes based on mangled names. 2018-01-05 16:34:55 -08:00
Doug Gregor
83fd37a2d0 [Runtime] Form function types based on mangled names.
Fixes some issues in the type decoder with function flags not getting
set when forming function types.
2018-01-05 16:23:49 -08:00
Doug Gregor
7148e84099 [Runtime] Stub out the implementation of _typeByMangledName().
Introduce a standard library/runtime entry point that produces type metadata
given a mangled name, based on the TypeDecoder logic lifted from the remote
mirrors library.

Implement support for tuple types as a proof-of-concept.
2018-01-05 15:42:45 -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
d64592264e [Runtime] Use nominal type descriptor references for non-foreign types.
Rather than emitting unique, direct type metadata for non-foreign
types, emit a reference to the nominal type descriptor. This collapses
the set of type metadata reference kinds to 3: nominal type
descriptor, (indirect) Objective-C class object, and nonuniqued
foreign type metadata.
2018-01-03 00:02:07 -08:00
Doug Gregor
c1782d8cc0 [Runtime] Eliminate the UniqueDirectClass metadata record kind.
Now that references to Objective-C class objects are indirected
(via UniqueIndirectClass), classes with Swift type metadata can be
directly referenced (via UniqueDirectType) rather than hopping through
swift_getObjCClassMetadata().
2018-01-02 22:48:54 -08:00
Pavel Yaskevich
10c385d1b7 [Mangling/ABI] Add special LabelList to store parameter labels
Instead of mangling parameter labels as part of the function type
move them to the end of the function name instead, to match the
language semantics.
2017-12-18 15:44:24 -08:00
Greg Parker
415b36dddc [runtime] Clean up symbol exports in casting and class introspection. (#13005) 2017-12-01 17:48:48 -08:00
Joe Groff
95d251051b Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
This is a small code size win, and also gives us some abstraction so that future cooperative ObjC compilers/runtimes might be able to interoperate ObjC class objects with Swift type metadata efficiently than they currently are in the fragile Swift runtime.

While I'm here, I also noticed that swift_getObjCClassMetadata was unnecessarily getting exposed in non-ObjC-interop runtime builds, so I fixed that as well.
2017-11-03 10:18:38 -07:00
Saleem Abdulrasool
7bd2256120 runtime: clean up last of -Wqual-cast warnings
This fixes up the remaining cast qualifier warnings from GCC 6.  Use
multiple casts to adjust the const qualification.  Prefer C++ style
casts.  NFC.
2017-09-22 14:14:13 -07:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Erik Eckstein
7d7dc5aaac Demangler: Use a bump-pointer allocator for node allocation.
This makes the demangler about 10 times faster.
It also changes the lifetimes of nodes. Previously nodes were reference-counted.
Now the returned demangle  node-tree is owned by the Demangler class and it’s lifetime ends with the lifetime of the Demangler.

Therefore the old (and already deprecated) global functions demangleSymbolAsNode and demangleTypeAsNode are no longer available.

Another change is that the demangling for reflection now only supports the new mangling (which should be no problem because
we are generating only new mangled names for reflection).
2017-02-24 19:04:13 -08:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Erik Eckstein
6a1ff0293e stdlib: a small fix in _typeByName
The demangling tree was not correct and this did’t work with the old re-mangler.
2017-02-08 09:01:51 -08:00
Erik Eckstein
fd62be59a1 stdlib: Use the re-mangler for _typeByName
The old method of constructing a mangled class name does not work anymore with the new mangling scheme.
Also, by using the re-mangler, _typeByName now works with class names containing non-ascii characters.
2017-02-07 08:36:21 -08:00
Hugh Bellamy
63cf2d561e Remove extern "C" from uses of SWIFT_RUNTIME_EXPORT 2017-01-22 18:32:17 +00:00