Commit Graph

98 Commits

Author SHA1 Message Date
Slava Pestov
5858756651 Reflection: Correct handling of nested types in TypeRef substitution 2016-05-05 22:28:48 -07:00
Slava Pestov
27b951e1e5 Reflection: Demangling for lowered metatypes
Lowered types appear in capture descriptors.
2016-05-05 13:47:54 -07:00
Slava Pestov
86dae6850c Reflection: Add SILBoxTypeRef, which can come up in capture descriptors 2016-05-02 19:26:12 -07:00
practicalswift
06fe6b0424 Merge pull request #2358 from practicalswift/a-vs-an-fixes
[gardening] Fix "a" vs. "an" issues.
2016-05-02 23:21:15 +02:00
Slava Pestov
efca93e632 Reflection: Add dumping of capture descriptors to swift-reflection-dump
The tests show that there's some round-tripping issue; I will investigate
this next.
2016-05-02 01:16:25 -07:00
practicalswift
d804026b34 [gardening] Fix "a" vs. "an" issues. 2016-05-01 13:29:57 +02: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
acbec3a341 Reflection: Small cleanup, NFC 2016-04-28 23:43:46 -07:00
Slava Pestov
a72773a9b4 Reflection: Use \n instead of std::endl 2016-04-28 22:56:16 -07:00
Slava Pestov
2a44b33dc2 Reflection: Use _ instead of - as word separator in metadata source s-expression output
For consistency with TypeRefs, and AST dumping.

Most Lisps use -, but we're C++ programmers here.
2016-04-28 22:56:15 -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
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
Slava Pestov
75dffb79c0 Reflection: Fix accidental edit 2016-04-26 00:13:07 -07:00
Slava Pestov
e98295aedc Reflection: Add comments and some small cleanups, NFC 2016-04-26 00:11:44 -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
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
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
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
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
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
Slava Pestov
3f21ae328a Reflection: Fix a warning, NFC 2016-04-19 17:23:47 -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
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
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
David Farler
e806fd2d1d Remove accidental CMake change to stdlib/public/Reflection 2016-04-13 15:38:03 -07: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
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
Slava Pestov
68f6a1179d Reflection: Add TypeRef kinds corresponding to {Unowned,Weak,Unmanaged}ReferenceStorageType 2016-04-12 19:15:37 -07:00
David Farler
cd13200b66 Don't install stdlib/public/Reflection into the stdlib component
This is only privately linked into the test tools for remote reflection
and eventually the C API dylib.

rdar://problem/25556475
2016-04-05 16:06:01 -07:00
David Farler
e1eca69d1a Ensure swiftReflection is always built for the host
swift-reflection-dump, a host-side tool, requires this library that
normally builds for the configured platform. So, if the host platform
isn't configured to build for some reason, swift-reflection-dump will
fail to link.
2016-04-04 15:23:07 -07: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