Commit Graph

296 Commits

Author SHA1 Message Date
Slava Pestov
68f6a1179d Reflection: Add TypeRef kinds corresponding to {Unowned,Weak,Unmanaged}ReferenceStorageType 2016-04-12 19:15:37 -07:00
Slava Pestov
39f0fff19d Reflection: Small stylistic cleanups, NFC 2016-04-12 19:15:36 -07:00
John McCall
91f02848df Organize the MemoryReader interface headers to better support
multiple clients.
2016-04-12 16:05:29 -07:00
David Farler
0b04b90895 SwiftRemoteMirrors: Stub implementations for infoFor{TypeRef,Field}
These are just some dummy implementations to temporarily appease
the linker.
2016-04-11 20:03:45 -07:00
David Farler
358a0fefe8 Add SwiftRemoteMirror library
This will wrap the ./lib/Reflection functionality in a C
interface.
2016-04-05 13:45:46 -07:00
Ge Sen
5ad36b2962 [gardening] Put white spaces in between if/while clauses and braces where it is missing.
For instance:

'if (foo){' => 'if (foo) {'
2016-04-02 14:43:45 +08:00
David Farler
5ea5bb06a3 Split swift-refleciton-test into host and target test targets
swift-reflection-test is now the test that forks a swift executable
and performs remote reflection, making it runnable on other targets,
such as the iOS simulator.

swift-reflection-dump is now a host-side tool that dumps the remote
reflection sections for any platform binary and will continue to
link in LLVM object file support.

This necessitates finally moving lib/Refleciton into stdlib/public,
since we're linking target-specific versions of the test tool and
we would eventually like to adopt some of this functionality in
the runtime anyway.
2016-03-28 16:34:44 -07:00
David Farler
76b31a9343 swift-reflection-test: Increase reading robustness
- Check return values from `read`
- Make the reflstr section optional, as it can be stripped by
  -strip-reflection-names.
2016-03-24 12:05:18 -07:00
David Farler
0dcd813c02 FieldRecord: Guard when field name is null
Field name relative offsets can be null if -strip-reflection-names
is passed to the frontend.
2016-03-24 12:05:18 -07:00
David Farler
23a823a3ed Remote Mirrors: Make MemoryReader a real class
Make the reader a class interface internally, with the
bag-of-function pointers via the eventual C API being the
special case.
2016-03-24 12:05:18 -07:00
David Farler
5ca4b428eb [TypeRef] Add isStruct, isClass, isEnum accessors
These will be used during layout calculation and for nicer
printing.
2016-03-17 19:03:13 -07:00
David Farler
840855253e SubstituteTypeRef: Don't rely on Metadata address for substitution
We'll need to drill into nested structs to get their field typerefs and
so on, without metadata necessarily available. Decouple the lookup from
the address.

TODO: Cache associated type descriptors based on typeref or mangled
name.
2016-03-17 19:03:03 -07:00
David Farler
d77903c110 [TypeRef] Return const string references for name members
No need to copy these - they aren't ever modified.
2016-03-17 19:02:01 -07:00
David Farler
be34129c43 Include protocols in DependentMemberTypeRef
This is necessary for proper uniquing when looking up associated
types.
2016-03-17 19:02:01 -07:00
David Farler
579ce977f0 swift-reflection-test: Replace Mach IPC with pipes
This is more amenable to cross-platform remote reflection tests.

Also add a new callback to the memory reader: getSymbolAddress,
which will be used for getting the addresses of nominal type
descriptors for concrete and fixed generic types.
2016-03-17 19:02:01 -07:00
David Farler
55efcb35c7 Track parent typerefs for nominal and bound generic types
- Read the Parent pointer out of Class/Value metadata and create
  typerefs for them.
- Add Parent fields to NominalTypeRef and BoundGenericTypeRef.
- Add TypeRef::getSubstMap(), which creates a new generic argument
  map after substitution has taken place on it. This is used to
  continue to burrow into nested value types, where generic type
  parameters may have a different index.
- Use a DenseMap as that generic argument map.
- Unconditionally key the generic argument map with (Depth, Index)
- Clean up ordering and presentation of Index and Depth. In the rest
  of the compiler, Depth comes before Index.
2016-03-17 19:02:01 -07:00
practicalswift
7bc51357be [gardening] Fix recently introduced typo: "metadat" → "metadata" 2016-03-08 18:59:53 +01:00
David Farler
80d3e7e189 [TypeRef] Look up generic substitutions with index and depth
A little bit of trivial future-proofing looking forward to nested
generics.
2016-03-07 18:53:19 -08:00
David Farler
6d32c02c74 [ReflectionContext] Remove some now dead code re: dependent members
This is done as a part of TypeRefSubstitution now.
2016-03-07 18:53:19 -08:00
David Farler
834b03b6cd [Reflection] Substitute generics and resolve dependent members
Once an unsubstituted typeref for a field is built, we substitute
`GenericTypeParameterTypeRef`s with concrete ones built from the generic
arguments of concrete bound generic metadata.

During that process, if we run into a `DependentMemberTypeRef` (e.g.
something of type T.Index), we substitute the base (T) using the current
list of substitutions, and then resolve what `Index` is for the base
using the associated type metadata in the 'assocty' data section.
2016-03-07 17:43:13 -08:00
David Farler
7fd8c79ec5 [ReflectionContext] Cache results of reading metadata and nominal type descriptors
These are the two main round-trips to the external target.
2016-03-07 17:43:13 -08:00
David Farler
db1a715ef1 Fix off-by-one allocation for reading remote strings 2016-03-07 17:43:12 -08:00
David Farler
96386b03be Don't use interface type as field descriptor key
Nominal type descriptors use declared types for their mangled names,
so we need to use them when scanning the fieldmd section for a
matching record. This is fine because the descriptor can tell us
about the type's generics. Individual field records continue to use
the interface type.
2016-03-07 17:43:12 -08:00
David Farler
0aba14430c Move PrintTypeRef and TypeRefSubstitution into the cpp - NFC 2016-03-07 17:43:12 -08:00
David Farler
a9404f910b Directly pass 'free' as custom deleter for SharedTargetNominalTypeDescriptorRef 2016-03-07 17:43:11 -08:00
David Farler
ea352103f8 Check result of getting function result typeref
Bail if it can't be constructed.
2016-03-07 17:43:11 -08:00
David Farler
bd6d657411 Get typerefs for existential type metadata 2016-03-04 17:10:40 -08:00
David Farler
0f05b390c3 Gardening: fix some 80-column violations 2016-03-04 17:10:40 -08:00
David Farler
3b2ceb7f19 Skip name= header if ObjCClass/Foreign TypeRef name is empty
A minor cosmetic change when dumping typerefs.
2016-03-04 17:10:40 -08:00
David Farler
5f169b466c Get typerefs for function type metadata 2016-03-04 17:10:40 -08:00
David Farler
04444c44a2 Get typerefs for tuple type metadata, including their elements 2016-03-04 17:10:40 -08:00
David Farler
5196f5b89c Get typerefs for nominal type metadata
and read their generic arguments, if there are any, too.
2016-03-04 17:10:39 -08:00
practicalswift
b9dd782e4b [gardening] Fix recently introduced file header. Also: "–" → "--". 2016-03-03 23:10:43 +01:00
David Farler
0e6dd788cf FunctionTypeRef: Track arguments as an array, not a tuple 2016-03-02 21:25:04 -08:00
David Farler
0ab31065ff Flesh out remote memory reader
Adds a rough sketch of what will be a test harness, currently only supported
on OS X:
- Launch a child process: an executable written in Swift
- Receive the child process's Mach port
- Receive reflection section addresses and the address of a heap instance
  of interest
- Perform field type lookup on the instance remotely (TODO)
2016-03-02 21:25:04 -08:00
David Farler
744806a742 [Reflection] Add Foreign, ObjC, and Opaque type references
These likely don't have Swift type metadata but might be useful to
record or instantiate based on what kind of metadata is encountered for
the sake of memory tools.
2016-03-02 21:25:04 -08:00
David Farler
c7d4d25d53 [Reflection] Adopt the MemoryReader in swift-reflection-test
Also do a little bit of gardening of the various headers.
2016-02-12 16:34:28 -08:00
David Farler
69bb6235fa [Reflection] Serialize associated types for nominal decls
This closes the loop on being able to resolve dependent member types
during remote reflection.
2016-02-12 16:34:28 -08:00
David Farler
666726d3dd [Reflection] Fix Index/depth inversion when decoding DependentGenericParamType 2016-02-12 16:34:28 -08:00
David Farler
c5298c0b52 [Reflection] Start fleshing out the remote mirrors library
- Don't depend on LLVM Support and swiftBasic as this will bring in
  llvmSupport and other heavy dependencies, which we don't build for
  non-host architectures right now anyway.

- Add a reader template that works with the same (albeit somewhat
  clunky) interface in-process with the runtime and remotely, by having
  the memory tool supply a function that will copy data from the remote
  process.

- Add a Buffer type to abstract indirecting pointers in a remote address
  space, which is handled by the memory reader.

- Start sketching out the C remote mirrors interface.
2016-02-12 16:34:28 -08:00
David Farler
ceae63cff4 Adopt llvm::TrailingObjects for TypeRefs
Thanks @jrose-apple for making me a believer!
2016-02-07 21:40:09 -08:00
David Farler
9f76eb61c4 Add associated type name typeref
This tracks the names 'T' and 'Index' in a T.Index dependent member type.
2016-02-07 21:40:08 -08:00
David Farler
9d5947d814 Fix Linux build
- Add an explicit link to swiftBasic
- Shuffle some constness

NFC.
2016-02-04 19:59:15 -08:00
David Farler
7a77284368 Add #include guards to TypeRef.h, ReflectionContext.h 2016-02-04 19:08:02 -08:00
David Farler
086000a198 Start the swiftReflection library
- Nearly done: TypeRefs and the mangled name decoder.

- Add the swift-reflection-test tool.
  The field reflection pipeline is roughly:
  - Decode type references
  - Substitute generic parameters
  - Calculate sizes and offsets

  There is currently only one action in the tool, which will test the
  *Decode* part of the pipeline: `dump-reflection-section`. This reads
  the *swift3_reflect section from an object file and dumps the decoded
  type references for all of the stored properties and enum cases in the
  file.
  - TODO: Write tests with various type arrangements to exercise the
    decoder - there are likely some holes in the decoder still since the
    AST mangler is quite rich in its kinds.

  TODO: The next test mode, `dump-field-types`, will do the following:
  1. Launch a swift executable with a canned stopping point
  2. Get the address of a heap object instance of interest
  3. Dump the fully substituted typerefs of all of the stored properties
  or enum case payloads.

  That test mode will be more involved since it will attach to another
  process and need to read from its address space but will test the
  entire out-of-process reflection pipeline in a controlled environment.
  We can maybe take this test a step further, with an option or a new
  test mode, that prints the entire heap reference graph rooted at that
  object of interest, in order to test the ability to detect reference
  cycles, for example.
2016-02-04 18:10:49 -08:00
David Farler
ef863136f3 Sketch out TypeRef structures for the reflection library
This adds the various TypeRef classes that will hold the
type references prior to substitution. There is also some
basic TypeRef visitor and dumping support.

rdar://problem/24173679
2016-02-03 13:52:26 -08:00