Commit Graph

260 Commits

Author SHA1 Message Date
Pavel Yaskevich
3f58daba4a [RemoteAST] Extend MetadataReader to collect flags related to function parameters 2017-10-16 16:46:45 -07:00
Saleem Abdulrasool
98c47f6b6a RemoteAST: only swift has nominal type descriptors
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.
2017-10-05 15:37:45 -07:00
Saleem Abdulrasool
086c12114d IRGen: switch to absolute pointers for nominal type descriptors
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.
2017-10-03 14:45:45 -07:00
Slava Pestov
61639cf971 RemoteAST: Stop looking at parent metadata field 2017-09-25 15:45:16 -07:00
Slava Pestov
23ded3cf6f Reflection: Fix crash when reflecting existential with fileprivate protocol member
Fixes <rdar://problem/31661662>, <rdar://problem/31668126>,
and probably many other crashes with the same backtrace.
2017-05-04 15:45:35 -07:00
Slava Pestov
f3761c1c2e Reflection: Update for subclass existentials and primitive AnyObject 2017-05-02 02:23:08 -07:00
Erik Eckstein
e427ded6c9 Mangling: refactoring: clean up tuple nodes
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.
2017-03-25 19:07:52 -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
Hugh Bellamy
7b092ae009 Fix Windows build with new demangling changes 2017-02-26 17:44:06 +07: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
John McCall
3d9ac50e2c Teach MetadataReader how to skip artificial subclasses,
and improve RemoteAST to provide corresponding APIs.
2017-02-16 15:41:50 -05:00
John McCall
505643d2de Fix the indexed-ISA metadata reader by properly initializing IsaIndexShift.
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.
2017-02-02 12:59:34 -05:00
John McCall
b37da364c4 Fix MetadataReader's isa-chasing on platforms that use indexed isa.
This is just implementing Greg Parker's spec for how to do it.

rdar://29996920
2017-02-01 20:14:32 -05:00
Hugh Bellamy
818099ecbe Rename swift_unreachable to swift_runtime_unreachable 2017-01-26 15:31:34 +00:00
Hugh Bellamy
5a59971b95 Move Unreachable.h from include/Basic to include/Runtime 2017-01-26 15:31:33 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Hugh Bellamy
53744b9b5a Fix errors and warnings building swift/remote on Windows using MSVC 2016-12-10 16:05:01 +00:00
Joe Groff
7429ffb228 Mangle SILBoxTypes with their layout.
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.
2016-12-08 20:02:44 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
1c7a50dcc5 Reflection: Fix class layout, again
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>.
2016-11-16 19:31:18 -08:00
Slava Pestov
db79762c3b Reflection: Fix class layout start offset calculations
Fixes <rdar://problem/29115967>.
2016-11-11 03:13:22 -08:00
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Slava Pestov
3fdf978af1 Remote: Sanity check number of elements in existential and tuple
This will hopefully make the reflection library more robust when
we point it at random memory.

Fixes <rdar://problem/27359445>.
2016-08-26 14:48:02 -07:00
David Farler
8c74092944 [Remote] Cache built types when reading metadata
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
2016-06-02 19:13:11 -07:00
David Farler
2799cabcfb SwiftRemoteMirror: Dig into generic SIL boxes
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
2016-05-17 01:30:28 -07:00
David Farler
9dddc6492b SwiftRemoteMirror: Project error existentials
Error existentials have a kind of special heap layout and can also
be compatible as NSError instances, too.
2016-05-10 12:50:31 -07:00
Slava Pestov
4fccd2f6fc Reflection: Closure context layout
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.
2016-05-09 13:40:58 -07:00
Slava Pestov
c392b3beb4 Remote: demangling of existential metatype with representation
Just drop the representation for now.
2016-05-09 13:40:58 -07:00
Slava Pestov
2abcd97aa8 Reflection: Remove some unused code, NFC 2016-05-09 13:40:57 -07:00
Slava Pestov
ffaba2598a Reflection: Demangling for lowered function types
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.
2016-05-05 13:47:54 -07:00
Slava Pestov
27b951e1e5 Reflection: Demangling for lowered metatypes
Lowered types appear in capture descriptors.
2016-05-05 13:47:54 -07:00
David Farler
f239740098 Fix egregious typo I recently introduced. 2016-05-04 00:01:00 -07:00
David Farler
9fac5409e8 Don't bail reading a metadata instance if swift_isaMask isn't available
This symbol is conditionally emitted based on whether there is an isa
mask for the platform. For 32-bit embedded platforms, this symbol
isn't present.
2016-05-03 21:04:31 -07:00
David Farler
5f5ce39a1d SwiftRemoteMirror: Wire up existential projection API
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.
2016-05-03 21:04:31 -07:00
David Farler
bfc94f4290 SwiftRemoteMirror: Add API to convert mangled type name to a typeref
This is useful on its own as well as for testing, so you can generate
typerefs to canned types such as Any, Swift.Int, etc.
2016-05-03 21:04:31 -07:00
Slava Pestov
86dae6850c Reflection: Add SILBoxTypeRef, which can come up in capture descriptors 2016-05-02 19:26:12 -07:00
Slava Pestov
1d5b9b09ac Reflection: Add instance-specific layout entry point, and do some refactoring
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.
2016-04-29 15:39:49 -07:00
Slava Pestov
975401ba3d Reflection: Fix broken Linux build
For some reason, initializer lists are not supported by std::tuple
in our Linux CI. Just call std::make_tuple() instead.
2016-04-29 00:25:14 -06:00
Slava Pestov
e81fca926a Reflection: Use correct starting offset and alignment in class instance layout
Also, add caching for class instance layout.
2016-04-28 22:56:15 -07:00
Slava Pestov
ce1c30b1bc Reflection: Support reading the remote process's isaMask
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.
2016-04-28 22:56:15 -07:00
Slava Pestov
7a9a4dca83 Reflection: Preliminary C API entry points for class instance layout
Tested by manually running swift-reflection-test, no automated
tests yet, but coming soon.
2016-04-27 23:15:08 -07:00
John McCall
83dc7cffe8 RemoteAST: implement member-offset calculations for tuples. 2016-04-27 19:00:30 -07:00
John McCall
92cf4a6d39 Teach MetadataReader how to handle ObjCClassWrapper metadata. 2016-04-26 13:04:02 -07:00
John McCall
627e2325d3 Read tuple labels in MetadataReader and preserve them in RemoteAST.
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.
2016-04-25 22:33:41 -07:00
Slava Pestov
c0c02a3148 Reflection: ProtocolTypeRefs now store a mangled name
This is better for field metadata lookups. Clients that want the
module name and decl name can demangle, just like they do with
NominalTypeRefs.
2016-04-25 20:08:49 -07:00
John McCall
812557ca24 Reorganization within RemoteAST. Basic error propagation.
Initial stabs towards reading foreign class metadata, although
these do not yet successfully resolve the declaration.
2016-04-25 16:57:19 -07:00
John McCall
964bd44066 Remove unnecessary shared ownership of loaded metadata/dominator buffers. 2016-04-25 14:45:14 -07:00
Enrico Granata
5d315ae30b Add a getKindForRemoteTypeMetadata() API to the RemoteAST - LLDB plans to use this API to decide whether certain kinds of existential containers need a two-level type resolution (e.g. if an existential box points to a class, the true type that we want to resolve is the type that the class's ISA refers to, not the static type that the box refers to) 2016-04-25 11:50:03 -07:00
David Farler
3a3cafc6bd MetadataReader infrastructure for reading capture descriptors
This starts wiring up capture descriptors to the metadata reader
so we can discern the layout of closures at runtime.

rdar://problem/24989531
2016-04-24 23:47:41 -07:00
practicalswift
9a078b54ef [gardening] Fix recently introduced typo: "a executable" → "an executable"
[gardening] Fix recently introduced typo: "a offset" → "an offset"
[gardening] Fix recently introduced typo: "accessiblity" → "accessibility"
[gardening] Fix recently introduced typo: "cant" → "can't"
[gardening] Fix recently introduced typo: "inteference" → "interference"
[gardening] Fix recently introduced typo: "unsatified" → "unsatisfied"
[gardening] Remove accidental space.
2016-04-24 22:11:59 +02:00