Commit Graph

33 Commits

Author SHA1 Message Date
Doug Gregor
d2a001af17 [ABI] Move the ABI parts of Runtime/Metadata.h into the ABI library.
Runtime/Metadata.h collected a large number of metadata data
structures that are actually part of the ABI. Move those data
structures into a new header, ABI/Metadata.h, and keep the in-process,
runtime-specific bits in Runtime/Metadata.h.
2018-06-12 09:55:39 -07:00
Pavel Yaskevich
0da5e48a0e [Runtime/Reflection] Add swift_getFieldAt runtime accessor
Use information from reflection section of the binary to lookup
type field info such as name and it's type and return it using
new `swift_getFieldAt` method based on nominal type and field index.
2018-02-20 18:20:09 -08: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
Pavel Yaskevich
8f05d64770 [Reflection] Add support for imported structs with recorded fields
Update IRGen to trigger generation of type metadata for foreign
struct types found in fields. And fix TypeRefBuilder to handle
the case where struct has fields but at the same time has opaque
metadata.
2018-02-06 15:50:52 -08:00
Mark Lacey
8667eb6f91 Revert "[WIP][IRGen] Emit type field descriptors for imported structs" 2018-02-03 10:27:34 -08:00
Pavel Yaskevich
9e08ea4c56 [Reflection] Add support for imported structs with recorded fields
Update IRGen to trigger generation of type metadata for foreign
struct types found in fields. And fix TypeRefBuilder to handle
the case where struct has fields but at the same time has opaque
metadata.
2018-02-02 15:54:12 -08:00
Joe Groff
3258902f77 Preserve whether fields are var or let in the reflection metadata.
Useful for future mutable reflection features to know whether they're allowed to mutate a field after initialization.
2018-01-31 19:04:39 -08:00
Saleem Abdulrasool
df54b2af11 reflection: handle LMA != VMA for ELF
ELF is segment mapped, where the segment which contains a particular
section may be mapped to an address which does not correspond to the
address on disk.  Since the reflection dumper does not use the loader to
load the image into memory, we must manually account for any section
offsets.  Calculate this value when we query the mmap'ed image and wire
it through to the relative direct pointer accesses.

When switching to the linker table approach for the ELF metadata
introspection, this was uncovered as the segment containing the orphaned
sections was coalesced into a separate PT_LOAD header which had a non-0
offset for the mapping.
2017-11-29 17:56:15 -08:00
Slava Pestov
ab4d37a422 Reflection: Record superclass as its own field instead of an associated type of AnyObject
The "superclass as associated type" modeling was put in to
maintain backward compatibility.

We just bumped the version number because of new mangling so
we may as well fix this sillyness too.
2017-05-02 01:18:49 -07:00
Erik Eckstein
29694722ba Increment the reflection-metadata version number.
Because we switched to the new mangling in 2d127e4192
2017-02-15 17:00:03 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
90efa574e2 [gardening] Make sure FieldRecordFlags.Data never contains uninitialized data
This will silence the warning "The left expression of the compound assignment
is an uninitialized value. The computed value will also be garbage."
2016-12-18 18:57:02 +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
e2cf23d971 Reflection: Don't emit builtin descriptors for imported classes
Previously we would emit both a builtin descriptor and field
descriptor for imported classes, but we only need the latter.

Untangle some code and fix a crash with imported Objective-C
generics in the process.

Fixes <rdar://problem/26498484>.
2016-05-26 19:32:59 -07:00
David Farler
fe2872fae1 SwiftRemoteMirror: Lower types with imported / Objective-C types
- Lower Objective-C class typerefs as strong references with unknown
reference counting.
- Lower other imported C types as builtin blobs of their known
size, alignment, etc.

In the future, it might be beneficial to track which stored properties
of imported types are pointers, for better conservative scanning of
outgoing pointers to the heap.

rdar://problem/26240258
rdar://problem/26240394
2016-05-12 20:49:32 -07:00
Slava Pestov
2abcd97aa8 Reflection: Remove some unused code, NFC 2016-05-09 13:40:57 -07:00
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
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
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
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
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
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
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
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
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
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