Commit Graph

163 Commits

Author SHA1 Message Date
Slava Pestov
71d28691ef Reflection: Plumb through capture descriptor section 2016-05-02 01:16:25 -07:00
Slava Pestov
9627aa98b5 Reflection: Add operator-> overloads to reflection section iterators 2016-05-02 01:16:24 -07:00
Slava Pestov
8f3279a17d Reflection: Formatting fix, NFC 2016-05-02 01:16:24 -07:00
Slava Pestov
faecfda594 Reflection: Consolidate some code for passing around reflection sections
I'm about to add a new section, and I'd like to update as few
places as possible.
2016-04-30 15:12:38 -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
1bd536e577 Reflection: Fix compile error, oops 2016-04-29 15:39:49 -07:00
Slava Pestov
8f06358b5b Reflection: Fix typos 2016-04-29 15:13:29 -07: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
Slava Pestov
95d648779b Reflection: Fix some bugs in swift-reflection-test
- Improper handling of read() returning an incomplete read
- Update SwiftReflectionTest library for new builtin types section

Only tested manually so far; automated tests coming soon.
2016-04-27 18:17:25 -07:00
David Farler
243bc7545b Move cache check into TypeRefs' static create methods
along with the boilerplate macro. This allows one to create TypeRefs
with either the builder or via the static methods, so long as a builder
argument is supplied so uniquing caches can be checked.

rdar://problem/25924875
2016-04-26 01:11:35 -07:00
David Farler
8e0412f84f Don't include Parent pointer in Nominal/BoundGeneric TypeRef uniquing
This information is already in the mangled type name.
2016-04-26 01:11:31 -07:00
David Farler
defe2b17a2 Include WasAbstract flag when uniquing MetatypeTypeRef 2016-04-26 00:11:46 -07:00
David Farler
dd7b6635e8 TypeRefID: Only add high bits of a pointer if on 64-bit
Adding another 0 to the TypeRefID bits is useless on 32-bit
platforms.
2016-04-25 23:56:28 -07:00
David Farler
50440abcd0 TypeRef Uniquing
We'd like to be able to compare TypeRefs with pointer equality,
but we can't link LLVMSupport, so make a lightweight TypeRefID
like FoldingSetID, that only supports the input types necessary
to unique TypeRefs.

rdar://problem/25924875
2016-04-25 23:56:28 -07:00
David Farler
d9368ff5ec Wrap 80-columns, NFC. 2016-04-25 23:56:28 -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
729428b4b1 Reflection: Type lowering for metatypes
The thin vs thick distinction is handled a little awkwardly. Instead of
passing around abstraction patterns, we add a "must be thick" bit to
MetatypeTypeRef, and thicken substitutions (to handle T; T := C.Type)
and the result of a subtitution (to handle T.Type; T := C).

With the exception of enums this completes <rdar://problem/25738849>.
2016-04-25 21:22:20 -07:00
Slava Pestov
996a859235 Reflection: Add basic type lowering for existentials
This approach doesn't work for imported Objective-C protocols yet.
2016-04-25 20:08:49 -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
Slava Pestov
00e0c89b30 IRGen: Emit reflection info for protocols
For now, just enough for lowering.

Perhaps we should have a way to always just get this information
from metadata instead, since protocol metadata is always static
and not instantiated.

This would require the static "object file" interface used by
swift-reflection-dump to take a callback for symbol lookup.
2016-04-25 20:08:48 -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
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
Slava Pestov
285e1b4824 Reflection: Re-organize TypeLowering a bit to aid C API wrapper
Lowering a record type now returns the substituted types of all
fields as well as their lowerings.

Also fix a bit of code duplication.
2016-04-24 23:36:23 -07:00
practicalswift
69fad27ac7 Merge pull request #2291 from practicalswift/typo-fixes-20160424
[gardening] Fix recently introduced typos.
2016-04-24 22:13:23 +02: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
practicalswift
cd47ad1cf4 [gardening] Fix headers. 2016-04-24 21:51:00 +02:00
David Farler
f24f445997 Merge pull request #2274 from apple/closure-metadata
Start emitting capture descriptors for closure metadata
2016-04-22 23:43:00 -07:00
Slava Pestov
d39e7d9416 Reflection: Add type lowering for class references and functions
Also add slightly inaccurate lowering for the special case of an
optional of a reference type. I need to rethink the approach for
extra inhabitants and enums, but this suffices for now.
2016-04-22 22:40:16 -07:00
Slava Pestov
d9c2fac613 Reflection: Add function representation to FunctionTypeRef 2016-04-22 19:47:06 -07:00
Slava Pestov
8cb268d0f6 Reflection: Rename make_typeref to makeTypeRef, NFC 2016-04-22 19:47:06 -07:00
David Farler
c05e48b116 Add CaptureDescriptor struct definition
For convenience when reading looking at heap closure metadata.

Also move the capture typerefs above the metadata sources, since
they're more likely to be accessed than generic metadata sources.
2016-04-22 19:09:06 -07:00
David Farler
6a51ae84b2 Add Self- and SelfWitnessTable metadata sources to capture descriptors
These can show up in partial applications of functions with the
witness_method calling convention.
2016-04-22 19:09:06 -07:00
David Farler
09d0cfee8d Hang closure capture descriptors from their heap metadata
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
2016-04-22 19:09:06 -07:00
David Farler
8d736a1cf6 MetadataSource Improvements: Builder; Parent, Impossible kinds
Create a builder divorced from the ReflectionContext so that
MetadataSources can be created in other contexts, such as emitting
private heap metadata during IRGen, where we'll have to record the
layout of captures and how to get metadata for generic arguments in
order to construct typerefs of the captures, etc.

Add Parent, Metadata capture, and Impossible metadata sources.
2016-04-22 19:09:06 -07:00
Slava Pestov
15d2149d78 Reflection: Should not depend on header file from SwiftRemoteMirror, NFC 2016-04-22 19:03:14 -07:00
Slava Pestov
2380f9f957 Re-apply "Reflection: Preliminary implementation of struct and tuple type lowering"
Re-apply now that reflection metadata is emitted by default and
the test can actually pass. Oops...
2016-04-21 15:15:38 -07:00
John McCall
0278616eb9 Allow MetadataReader to use a more precise type for tracking nominal
types than just a std::string.
2016-04-19 11:34:24 -07:00
Greg Parker
4f98a54eb4 Revert "Reflection: Preliminary implementation of struct and tuple type lowering" and "Reflection: Fix a nit"
Test Reflection/typeref_lowering.swift failed on a bot:
https://ci.swift.org/job/oss-swift-package-osx/1346/

This reverts commits 52f475c0b0 and f4af29b53c.
2016-04-19 01:51:48 -07:00
Slava Pestov
52f475c0b0 Reflection: Preliminary implementation of struct and tuple type lowering
Now that we can parse and substitute typerefs, and look up field
types, we finally have enough infrastructure in place to do some
basic layout of struct and tuple types from within the Reflection
library.

To facilitate testing, swift-reflection-dump now accepts multiple
-binary-filename flags, allowing types defined in the standard
library to be looked up.

More detailed end-to-end tests will come once I finish the
typeref-to-metadata builder.
2016-04-18 23:13:50 -07:00
Slava Pestov
d91d865667 Reflection: Split up TypeRefBuilder::getFieldTypeRefs()
We want to look at the nominal type kind before lowering any field
types, since the lowering of a class type does not depend on any
of its field types at all.

Tested by upcoming type lowering patch, for now NFC.
2016-04-18 21:18:01 -07:00
Slava Pestov
1d6740abb3 Reflection: Add TypeRefBuilder::getBuiltinTypeInfo()
Tested by upcoming type lowering patch, for now NFC.
2016-04-18 21:17:55 -07:00
Slava Pestov
c76b1f1cec Reflection: Record the nominal type kind in the field descriptor
Tested by upcoming type lowering patch, for now NFC.
2016-04-18 21:17:41 -07:00
Slava Pestov
cca413580a Reflection: Small fixes
- Use -parse-as-library in tests
- Use _ instead of - when printing TypeRefs for consistency with AST Types
- Fix printing of unowned(unsafe) types
2016-04-18 21:17:40 -07:00
Slava Pestov
a91becc023 Reflection: Move some code from TypeRefBuilder.h to TypeRefBuilder.cpp, NFC
Now that we no longer need the template parameter everywhere
we can start moving code out of header files.
2016-04-16 02:37:40 -07:00
Slava Pestov
d184122e83 Reflection: Move field and associated type metadata parsing from ReflectionContext to TypeRefBuilder, NFC
ReflectionContext is now solely concerned with converting runtime
metadata in a remote address space into a TypeRef.

TypeRefBuilder now knows how to parse reflection metadata, and
in particular look up associated type witnesses. This decouples
the TypeRef substitution code from the ReflectionContext. Now
substitution only needs a TypeRefBuilder, which means the code
is no longer templated, and can be moved from TypeRef.h to
TypeRef.cpp.

This also allows the upcoming TypeRef lowering code to live in
a source file instead of headers.
2016-04-16 02:19:04 -07:00
Slava Pestov
29aa01fcf4 Reflection: Don't accidentally copy or assign TypeRefBuilders and ReflectionContexts, NFC 2016-04-16 02:18:31 -07:00
Slava Pestov
a3e0b63423 Reflection: Split off TypeRefBuilder.h from ReflectionContext.h, NFC
ReflectionContext is getting too large, and having to thread a
<Remote> template parameter through all code that wants to construct
typerefs is getting tricky. This is the first patch in a refactoring
to move some stuff out of ReflectionContext.
2016-04-16 02:18:26 -07:00
practicalswift
dc39ac43bf [gardening] Fix file header formatting. 2016-04-16 10:17:53 +02:00