Commit Graph

296 Commits

Author SHA1 Message Date
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
David Farler
45d2355cd6 Merge pull request #2206 from bitjammer/metadata-source
Add MetadataSource classes
2016-04-15 15:14:14 -07:00
David Farler
ffdc91a038 Add MetadataSource classes
The compiler is generally free to not include pointers to metadata in
heap boxes, which are used for closure captures, if it knows you can get
to metadata through some other path. These MetadataSource classes will
describe a sequence of steps to get to metadata at runtime.

In the short term, this will be useful for describing the layout of
function/closure capture contexts, which can vary depending on what is
captured.
2016-04-15 13:52:07 -07:00
David Farler
f5583c8295 Restore const-ness of TypeRefs
We got rid of the last mutating methods on TypeRefs, so let's
make these all const again.
2016-04-15 13:13:34 -07:00
Slava Pestov
7b0e8d2b2f Reflection: Clean up duplication in typeref_decoding*.result.txt
Previously we would pre-process the same input files in the ObjC
and non-ObjC tests. This made the tests difficult to update because
the output of one was a subset of the other, and only one of the
two tests would run on any given platform.

Instead, let's just put the Objective-C tests in their own test
and input files.
2016-04-15 00:12:29 -07:00
Slava Pestov
824bd7544d IRGen: Emit typerefs for all builtin types referenced from reflection metadata sections
In order to perform layout, the remote mirrors library needs to know
about the size, alignment and extra inhabitants of builtin types.

Ideally we would emit a reflection info section in libswiftRuntime.o,
but in the meantime just duplicate builtin type metadata for all
builtin types referenced from the current module instead.

In practice only the stdlib and a handful of overlays like the SIMD
overlay use builtin types, and only a few at a time.

Tested manually by running swift-reflection-tool on the standard
library -- I'll add automated tests by using -parse-stdlib to
reference Builtin types in a subsequent patch that adds more layout
logic.

NFC if -enable-reflection-metadata is off.
2016-04-15 00:12:11 -07:00
Slava Pestov
f236383865 Reflection: Fix metadata for empty cases
Also change std::endl to '\n' in the dumper, since std::endl flushes
the output stream.
2016-04-14 23:44:45 -07:00
John McCall
5eef441240 Extract the core implementation of ReflectionContext and
template it over the builder type.

Also preserves more information about function types until
the builder, at least.
2016-04-14 21:21:44 -07:00
Slava Pestov
d39c7f29c4 Reflection: Eliminate NominalTypeTrait::setParent()
When creating a TypeRef from metadata, we have a parent pointer
handy, and construct the TypeRef directly, so there's no need
to mutate the TypeRef after the fact.

When demangling a TypeRef from a string, the mangling encodes
the parent module or type context, so we can set it when
constructing the TypeRef there too.
2016-04-14 15:31:15 -07:00
Slava Pestov
d998fda52e Reflection: Nitpicks, NFC 2016-04-14 15:31:14 -07:00
John McCall
7ff15dd075 Progress towards marking ReflectionContext templated over the builder. 2016-04-14 13:39:35 -07:00
practicalswift
51281e6fd3 [gardening] Fix spacing. 2016-04-14 09:51:27 +02:00
David Farler
cf97a12109 Tie lifetime of typerefs to the ReflectionContext
We will be handing pointers to typerefs over the SwiftRemoteMirrors C
API boundary, at which point it is unclear who will hold onto a shared
pointer. The useful lifetime of a typeref is tied to the
ReflectionContext for which they were created anyway so, when it goes
away, all of those typerefs can go away anyway.

We can't use LLVM's bump-pointer allocator here because we only build
the Support library for the host. As a compromise, stuff new typeref
pointers into a vector pool, where they will be taken down during
ReflectionContext's destructor.
2016-04-13 13:58:35 -07:00
David Farler
20f5304b90 Revised SwiftRemoteMirror C API
Some minor changes to the SwiftRemoteMirror C API, NFC yet.
2016-04-13 13:09:27 -07:00
Slava Pestov
c373b1c015 Reflection: Some improvements to substitutions
The most important change is a fix for dependent member lookup in
bound generic TypeRefs.

The TypeRef logic here is a similified version of what Sema does,
and roughly works as follows:

When looking up a member type O.M for an original type O and
member type M, we first substitute O, to yield a concrete type S.
Then, we look up M in the serialized conformance info section
to yield the unsubstituted member type T', and apply substitutions
to produce the substituted member type T.

Trouble is, we were applying the wrong substitutions the second
time around.

If S is a bound generic type, the "base type substitutions" of S
are the substitutions required to turn the fully-abstracted
bound generic type into S. This might not be the same substitution
map that took us from O to S.

Apart from that, add some assertions that the result of a
substitution is always concrete and that the substitution map
must not contain all generic parameters referenced in the
original type.
2016-04-12 19:15:38 -07:00
Slava Pestov
22bf2dcdbe Reflection: Clean up Parent type handling a bit, NFC 2016-04-12 19:15:38 -07:00
Slava Pestov
d2b16597f8 Reflection: Fixes for tuple types with labels, and varargs
Just drop labels when demangling TypeRefs. This is OK for now
since labels do not affect layout.

Vararg tuple types cannot appear directly as the type of
storage, however they can appear in function input types, and
therefore must be minimally supported. Since we don't plan on
doing function call reflection just yet, this doesn't matter
for now, but again we need to not crash.

With this patch, all TypeRefs in the Swift standard library now
successfully demangle and print.
2016-04-12 19:15:37 -07:00
Slava Pestov
9738d77677 Reflection: TypeRef demangling now returns nullptr if any part of the tree is invalid
Previously, we would return TypeRefs containing nullptrs.
2016-04-12 19:15:37 -07:00