Commit Graph

58 Commits

Author SHA1 Message Date
Mike Ash
e4564087af [RemoteMirrors] Move ownsObject into ReflectionContext. 2018-02-27 10:32:32 -05:00
Davide Italiano
7d4b3ae372 [RemoteMirrors] Remove now unused code. 2018-02-26 17:42:29 -08:00
Davide Italiano
ec39bbb08c [RemoteMirrors] Move addImage from stdlib to Reflection. 2018-02-26 17:41:08 -08:00
Mike Ash
6f887475a3 [Reflection] Lots of smaller fixes and API changes due to testing the interop code.
* Remove getPointerSize and getSizeSize functions, replace with a single PointerSize value.
* Remove imageLength parameter from addImage, calculate it internally instead.
* Check remote mirrors libraries' metadata version and reject them if it's too old.
* Shim GetStringLength and GetSymbolAddress for the legacy library since we don't pass the caller's context pointer through directly.
* Actually set the IsLegacy flag in the Library struct.
* Implement ownsObject by tracking each added image's data segment and checking metadata pointers against them. The previous approach didn't work.
2018-02-26 16:56:54 -05:00
Mike Ash
4c7d203574 [Reflection] Implement more interop API calls.
rdar://problem/37538580
2018-02-23 11:47:24 -05:00
Mike Ash
29beaa3126 [Reflection] Track the memory returned from readBytes calls in addImage and free it when destroying the context.
rdar://problem/37538580
2018-02-22 17:17:48 -05:00
Mike Ash
04f2fa8dd7 [Reflection] Minor cleanup of SwiftRemoteMirror files.
rdar://problem/37538580
2018-02-22 12:06:59 -05:00
Mike Ash
1dcdd939ca [Reflection] Implement swift_reflection_addImage which takes care of looking up reflection info on behalf of the client.
rdar://problem/37538580
2018-02-20 16:47:07 -05:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
2018-02-10 10:43:47 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08: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
Saleem Abdulrasool
ac6edab22e Merge pull request #6025 from hughbe/remote-msvc
Port swift/remote to Windows and MSVC
2016-12-10 12:54:35 -08:00
Hugh Bellamy
53744b9b5a Fix errors and warnings building swift/remote on Windows using MSVC 2016-12-10 16:05:01 +00:00
practicalswift
76f0fdd670 [gardening] NULL → nullptr 2016-12-09 23:17:54 +01: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
David Farler
941ec1e043 SwiftRemoteMirror: Add reflection metadata version query API
rdar://problem/27251582
2016-07-08 14:12:59 -07:00
Slava Pestov
95bc009e3e Reflection: Multi-payload enum layout
The approach here is to split this into two cases:

- If all case payloads have a fixed size, spare bits may be
  potentially used to differentiate between cases, and the
  remote reflection library does not have enough information to
  compute the layout itself.

  However, the total size must be fixed, so IRGen just emits a
  builtin type descriptor (which I need to rename to 'fixed type
  descriptor' since these are also used for imported value types,
  and now, certain enums).

- If at least one case has a size that depends on a generic
  parameter or is a resilient type, IRGen does not know the size,
  but this means fancy tricks with spare bits cannot be used either.
  The remote reflection library uses the same approach as the
  runtime, basically taking the maximum of the payload size and
  alignment, and adding a tag byte.

As with single-payload enums, we produce a new kind of
RecordTypeInfo, this time with a field for every enum case.
All cases start at offset zero (but of course this might change,
if for example we put the enum tag before the address point).

Also, just as with single-payload enums, there is no remote
'project case index' operation on ReflectionContext yet.

So the the main benefit from this change is that we don't entirely
give up when doing layout of class instances containing enums;
however, tools still cannot look inside the enum values themselves,
except in the simplest cases involving optionals.

Notably, the remote reflection library finally understands all
of the standard library's collection types -- Array, Character,
Dictionary, Set, and String.
2016-07-01 01:31:25 -07:00
Slava Pestov
48c928938a Reflection: Single-payload enum layout
Attempt to lay out single-payload enums, using knowledge of extra
inhabitants where possible.

- The extra inhabitants of an aggregate are the extra inhabitants of
  the first field. If the first field is empty, there are no extra
  inhabitants, and subsequent fields do not affect anything.

- Function pointers and metatypes have different extra inhabitants
  than Builtin.RawPointer, so have IRGen emit distinct builtin type
  descriptors for those.

- Opaque existentials do not have extra inhabitants.

- Weak references do not have extra inhabitants.

Also, fix IRGen to emit more accurate enum reflection metadata in
these two cases:

- We now record whether enum cases are indirect or not. An indirect
  case is the same as a payload case with Builtin.NativeObject.

- We now record whether a case is empty or not using the same logic
  as the rest of IRGen. Previously, we would incorrectly emit a
  payload type for a case with a payload that is an empty struct,
  for example.

At this point we don't have a way to get the currently inhabited
enum case from a value. However, this is still an improvement because
we can still reflect other fields of aggregates containing enums,
instead of just giving up.

Finally make some methods on TypeCoverter private, and use 'friend'
to allow them to be accessed from other internal classes, making the
public API simpler.
2016-06-30 12:57:14 -06:00
Slava Pestov
da40b5e566 Merge pull request #2285 from tinysun212/pr-portability-1
[SwiftRemoteMirror] Renamed addr_t to swift_addr_t
2016-06-02 10:59:46 -07:00
Slava Pestov
710d7ede71 Reflection: Break out SWIFT_RAW_POINTER vs SWIFT_BUILTIN in the C API
Also, use "opaque existential" consistently to refer to non-class
existentials, and clean up some other random bits.
2016-05-12 18:27:35 -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
Han Sangjin
675de4048d [SwiftRemoteMirror] Renamed addr_t to swift_addr_t
They would think the type 'addr_t' is defined in the standard library
because it has the same name format with the types in <cstdint>. In
addition, the definition conflicts in Cygwin which defines it differently
in the system library.
2016-05-11 04:02:11 +09:00
David Farler
2fd0b39751 SwiftRemoteMirror: move dump APIs to print to stdout instead of stderr
Rather than move file descriptors around in the tools, just tell the
underlying ::dump methods to print to stdout instead.
2016-05-09 14:29:33 -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
David Farler
7e06ee45e8 SwiftReflectionContext: Remove dependency on SwiftRemoteMirror header
Although mechanically it's not a circular dependency yet, conceptually
it is. Use RemoteAddress instead of the raw addr_t typedef.
2016-05-04 13:33:08 -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
David Farler
97fe3e70d9 SwiftRemoteMirror: Add convenience API for demangling
rdar://problem/26060031
2016-05-03 19:11:00 -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
8f06358b5b Reflection: Fix typos 2016-04-29 15:13:29 -07:00
Slava Pestov
4c3aa34966 Reflection: Fix field name in swift_reflection_childOf{TypeRef,Metadata}()
An accidental copy meant the lifetime of the string was incorrect.

Discovered in manual testing. Automated tests coming up.
2016-04-28 23:43:23 -07:00
Slava Pestov
a72773a9b4 Reflection: Use \n instead of std::endl 2016-04-28 22:56:16 -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
David Farler
210f8dfe63 swift-reflection-test: Target SwiftRemoteMirror C API
This tool should test the usage from SwiftRemoteMirror dylib and
the C API, since that is the public interface from which we're
vending the remote reflection functionality.
2016-04-28 19:38:03 -07:00
David Farler
9b06e78965 SwiftRemoteMirror: More convenience APIs for dumping
Add convenience functions for dumping the typeinfos via an isa pointer
and a typeref.
2016-04-28 18:07:31 -07:00
David Farler
f2189162fe SwiftRemoteMirror: Add convenience API for dumping typerefs. 2016-04-28 14:52:06 -07:00
David Farler
84c3613e12 SwiftRemoteMirror: Add API stub for projecting existentials
This API will take a pointer to the start of an existential
container and its typeref and provide a typeref for its
instance type and the address to the start of the instance's
data.

This has a dummy implementation that returns false for now.
2016-04-28 14:52:06 -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
David Farler
88fde5050d SwiftRemoteMirror: Fix missing ReaderContext in creation API
swift_reflection_createReflectionContext was defaulting to C++ mangling
because the declaration under extern C in the header didn't match
its signature.
2016-04-27 12:53:39 -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
David Farler
90f1523c4c Add opaque context pointer to SwiftRemoteMirror C API Reader API
Memory readers on the C-side of the API may actually have an object-
oriented design, so they may want to pass an instance to revive
when callbacks make it to the other side of the API boundary.
2016-04-25 00:00:27 -07:00
Slava Pestov
936d4e5e23 Reflection: Flesh out SwiftRemoteMirror C API
- Add swift_reflection_genericArgumentCountOfTypeRef()
- Flesh out swift_reflection_infoForTypeRef()
- Flesh out swift_reflection_infoForChild()
2016-04-24 23:36:31 -07:00
Slava Pestov
15d2149d78 Reflection: Should not depend on header file from SwiftRemoteMirror, NFC 2016-04-22 19:03:14 -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
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
John McCall
7ff15dd075 Progress towards marking ReflectionContext templated over the builder. 2016-04-14 13:39:35 -07:00