Makes sure that invalid runtime type strings result in errors and not fail silently.
In worst case this could lead to wrong reconstructed metatypes which can result in all kind of memory corruption.
relates to rdar://129861211
When emitting metadata for a Swift-defined @objc protocol that has
provided a specific Objective-C name (e.g., via @objc(renamed)),
mangle such protocols using their Objective-C names so they can be
found at runtime.
Only do this for metadata, because doing it anywhere else would cause
an ABI break. Fixes rdar://problem/47877748.
When we encounter the demangle tree for a bound generic class type, look
through the "Type" node of the child tree before checking whether we
have an Objective-C class name. If we do have an Objective-C class name,
there is no way to preserve the generic arguments, so we ignore them and
return the (non-generic) class type.
Fixes rdar://problem/47028102.
We were creating a local Demangler instance, demangling a type name
using it, and then returning one of the resulting nodes to the caller.
Fixes rdar://problem/46817009.
The “old” mangling that is used for runtime names of @objc protocols
uses a simpler substitution scheme, so you can’t simply take a mangled
name from the new mangling and fix up the ends.
Fixes rdar://problem/45685649.
When checking conformance requirements against an @objc protocol, also
check for an @objc existential using protocol_conformsToProtocol().
Fixes rdar://problem/45685649.
When searching the superclasses at runtime, e.g., to find a suitable
protocol conformance record, also consider the superclasses of CF
types, which were recorded in the metadata but otherwise unused.
Clang-importer-synthesized declarations get an extra tag character included in their mangling, which was not being preserved in type context descriptors. This caused runtime lookup for these synthesized types to fail. Fix this by adding the tag information to type context descriptors and teaching the runtime to match it up when fetching metadata by mangled name. Fixes rdar://problem/40878715.
@objc protocols don't have witness tables. However, both type metadata
(in the nominal type descriptors) and the runtime code to demangle
type names into metadata weren't acknowledging this. Fix type metadata
emission to not count an "extra argument" for @objc protocol
conformance requirements, and teach the runtime code to properly look
for conformances to @objc protocols (through the Objective-C runtime)
and not record witness tables for them.
All Swift-defined nominal types have their runtime metadata recorded
in a special section, so it can be found later. This recording is
suppressed when that type is stated to conform to a protocol, because
the runtime can find nominal types in either place.
Imported types would get their conformances recorded, but would not
get recorded in the runtime metadata record otherwose. Therefore, the
runtime would not be able to find such types by name.
For any foreign type whose metadata we emit, make sure that metadata
can be found by a runtime lookup.
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.
Emit nominal type access functions for imported types. These access
functions work with non-unique metadata references, so they perform
uniquing through the runtime on first access.
Fixes rdar://problem/36430234.
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.
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.
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.
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.