When the RemoteAST is used to access objects from LLDB, the object that
we are interacting with may not be a Swift object but rather an ObjC
object that has been bridged into swift. In such a case, the object
does not have a nominal type descriptor associated with it. Ensure that
the type is a valid Swift type before reading the nominal type
descriptor from the metadata. This avoids an assertion when evaluating
expressions in LLDB.
Alter the value metadata layout to use an absolute pointer for the
nominal type descriptor rather than a relative offset relative to the
complete type metadata. Although this is slightly less efficient in
terms of load times, this is more portable across different
environments. For example, PE/COFF does not provide a cross-section
relative offset relocation. Other platform ports are unable to provide
a 64-bit relative offset encoding.
Given that the value witness table reference in the value metadata is
currently an absolute pointer, this page is most likely going to be
dirtied by the loader.
Replace VariadicTuple and NonVariadicTuple with a single Tuple node.
The variadic property is now part of the tuple element and not of the whole tuple.
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
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).
Unfortunately, I'm flying blind a bit --- this code is hard to
test outside of an integrated environment on a target using the
ABI in question, and I don't have such an environment set up ---
so I'm left with this rather ugly process of iteratively submitting
patches for trivial bugs and waiting for the bots to deliver judgment.
The environment could be mocked with a test environment that used
a nonstandard ObjC ABI, but that would actually take a lot of work
because of Swift's assumptions about the ObjC ABI: we'd basically
have to configure the test environment as a real, proper target,
possibly all the way through LLVM.
Use a new mangling scheme that describes the layout of compound boxes. For compatibility with reflection-based clients, continue to use the legacy mangling for single-field boxes when emitting reflection TypeRefs until we fully support reflection for the new box implementation.
There were a few problems here with subclasses of Objective-C classes.
Use the InstanceStart field from rodata to correctly lay out instance
variables, and verify the results match with dynamic and static layout.
Better fix for <rdar://problem/27932061>.
If bad data is fed to the reader, it might be convinced it's looking at
a generic type. If the generic type parameter also happens to be the
same metadata pointer, an infinite recursion results. To prevent this,
insert an invalid type into the cache at the start of the read. If we
then ask for that same metadata pointer again, we'll return the
invalid/empty built type.
This also might improve performance a little by preventing rereading
and rebuilding types.
rdar://problem/26529650
Part 1: Generic SIL Boxes always have instatiated metadata with kind
HeapGenericLocalVariable, which includes a metadata pointer for the
boxed type.
Part 2, after this, is to provide some kind of outgoing pointer map for
fixed heap boxes, whose metadata may be shared among different but
destructor-compatible types.
rdar://problem/26240419
This adds various MetadataReader methods to support closure layout:
- Reading generic arguments from metadata
- Reading parent metadata
- Reading capture descriptor from heap metadata
To a large extent, this is not currently taken advantage of, because
SILGen always wraps address-only captures in SIL box types.
Tests are in the next patch.
Lowered function types appear in capture descriptors.
For now, we completely punt on demangling parameters and
results, and just hackishly map the SIL function type
representation to an AST function type representation.
This is good enough, because all we care about is whether
we have a raw function pointer, raw function pointer with
context, or a block.
Implement the ReflectionContext's implementation of:
swift_reflection_projectExistential.
First, we get the type info of the existential typeref - it should be a
record type info. If it's a class existential, it has trivial layout:
the first word is a pointer to the class instance. Otherwise, if the
value fits in the 3-word buffer of the existential container, it
trivially is also at the start of the container. Otherwise, the value is
off in a heap box somewhere, but the first word of the container is a
pointer to that box.
Closure context layout will depend on the instance itself as well
as the isa pointer, because instead of instantiating metadata for
closures that capture generic parameters, we store the substitutions
inside the context itself.
For classes, this entry point just reads the isa pointer, applies
the isa mask and proceeds down the metadata path.
For now, the only the latter is hooked up.
Also, use the instance layout entry point in swift-reflection-test,
so that we can dump the layout of a class instance and not the
lowering of the reference value.
The metadata system doesn't actually unique based on labels
correctly, so the test case has to play some games. That's
something that will be easier to fix when there are fewer
clients poking at the internals of the metadata runtime.