Instead of passing around raw local pointers and references, and spreading
tricky offset arithmetic around with the Local/RemoteAddress fields in
ReflectionInfo, have the TypeRefBuilder code use RemoteRefs everywhere,
which keep the remote/local mapping together in one unit and provide
centralized API for this logic.
This doesn't yet change how code uses the RemoteRef address data to
follow pointers across objects, for things like reading type refs, but
that should be much easier to do after this lands.
By including the trailing mangled name reference in the baseSize, we computed the wrong offset for
the generic parameter header, and then miscomputed the size of the trailing generic context info.
This would lead to accesses into the context sometimes reading from uninitialized memory.
Fixes rdar://problem/55711107
Resolving a direct relative reference given a RemoteRef doesn't need the MetadataReader,
since the offset should already be in the local buffer; we can add it to RemoteRef's
saved remote address and get a new remote address. Refactor the API to make as much as
possible of it available directly on RemoteRef.
The only thing the Runtime affects is the width of the StoredPointer for the remote address, for
which storing a uint64_t ought to be enough for anyone we care about so far. This will make it
easier to store and use RemoteRefs in code that isn't or shouldn't ideally be templatized on
Runtime (such as TypeRefBuilder, and ultimately ReflectionContext, from the Reflection library.)
This makes for a cleaner and less implicit-context-heavy API, and makes it easier for symbolic
reference resolvers to do context-dependent things (like map the in-memory base address back to a
remote address in MetadataReader).
When building for debug, the opaque return type context is nested under an anonymous context for
the defining function. Demangle the anonymous context name to reconstruct the mangling for the
opaque type.
This is done by disallowing nodes with children to also have index or text payloads.
In some cases those payloads were not needed anyway, because the information can be derived later.
In other cases the fix was to insert an additional child node with the index/text payload.
Also, implement single or double children as "inline" children, which avoids needing a separate node vector for children.
All this reduces the needed size for node trees by over 2x.
An Error existential value can directly store a
reference to an NSError instance without wrapping
it in an Error container.
When "projecting" such an existential, the dynamic type
is the NSError's isa pointer, and the payload is the
address of the instance itself.
Turns out the tags are shuffled around by XORing with a
per-process hash, and we have to deobfuscate the tag
before checking if its an extended tag.
There's no test for this; just running the existing tests
several times in a row is sufficient to trigger the problem.
If resolving the type of an instance produces a class metadata for
which we cannot build a type (for example, a special class like
__NSCFNumber, which the ClangImporter does not produce a ClassDecl
for), we try the superclass.
The caching logic was broken in this case, so subsequent calls
would return an empty type.
Translate the metadata for the generic requirements of an extension context
into a demangle tree that is associated with the demangling of an extension.
Teach the ASTDemangler how to handle class layout constraints as well.
With this, RemoteAST can resolve types nested within most constrained
extensions.
When reading a mangled name, make sure to cope with embedded null bytes that
show up in symbolic references. When demangling such a name, handle symbolic
references.
Protocol references are interesting because we have to deal with the
low bit indicating whether we have a reference to an Objective-C protocol.
Factor out this logic for later re-use.
Read the extended context mangled name from an extension context descriptor
so we can form a proper demangle tree for extensions. For example, this allows
types nested within extensions of types from different modules to be found.
When the mangled name is available within an anonymous context descriptor
for a local type, use that mangled name to help RemoteAST resolve lookups
based on local type metadata.
Debug info uses a special mangling where type aliases can be
represented without being desugared; attempt to reconstruct
the TypeAliasType in this case.
When an anonymous context descriptor provides a mangled name, use that
mangled name to provide the private declaration name for its child context.
This allows us to resolve private type names correctly when the corresponding
anonymous context has its mangled name.
Fixes rdar://problem/38231646.
We should also allow references via manglings just to cover the
general case if we need it, but this is useful on its own so that
we can emit a reference to any natively-declared Swift type.
Right now we expect that every class and protocol has a field
descriptor that tells us if the entity is @objc or not.
For imported types, the descriptor will not exist if we did not
directly emit a field whose concrete type contains the imported
type. For example, in lldb, we might have a generic type whose
runtime substituted type includes an imported type.
In this case, TypeLowering would fail to produce a layout because
it did not find a field descriptor for the imported type.
A better approach is to have the TypeDecoder call a different
factory method for imported types, and handle them specially in
TypeLowering, bypassing the field type metadata altogether.
When building the remote mirror for Windows, the build would fail due to the
symbol resolution being slightly different on Windows. Explicitly qualify the
name to resolve the ambiguity. This reapirs the build of the remote mirror for
Windows.
Extending the mangling of symbolic references to also include indirect
symbolic references. This allows mangled names to refer to context
descriptors (both type and protocol) not in the current source file.
For now, only permit indirect symbolic references within the current module,
because remote mirrors (among other things) is unable to handle relocations.
Co-authored-by: Joe Groff <jgroff@apple.com>
The superclass descriptor reference in class context descriptors is only used
for metadata bound computations when the superclass is resilient. Only
include the superclass descriptor reference when the class has a resilient
superclass, using a trailing record. It’s a tiny space savings for
classes that don’t have resilient superclasses.
Like we did for structs, make it so that tuple types can also get extra inhabitants from whichever element with the most, not only the first. This lets us move all of the extra inhabitant handling functionality between structs and tuples in IRGen up to the common RecordTypeInfo CRTP base.