Commit Graph

183 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
cbee90cf5d Merge pull request #12812 from xedin/bring-back-function-metadata-changes
[IRGen] Improve function type metadata representation
2017-11-08 12:03:54 -08:00
Greg Parker
9a38e609af [IRGen][runtime] Reduce object header to 8 bytes on 32-bit platforms. (#12790)
SR-4353, rdar://29765800
2017-11-08 02:50:11 -08:00
Pavel Yaskevich
622cc1c64a [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
aa89c4f4a8 Revert "[ABI/IRGen] Add custom function parameter flags representation for metadata use"
This reverts commit f6b0d2d2cf.
2017-11-07 00:24:21 -08:00
Pavel Yaskevich
f6b0d2d2cf [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
51d9542a2a [Reflection] Add label and flags to function type reference parameters 2017-10-16 16:46:45 -07:00
Pavel Yaskevich
bf8d6f591e [Reflection] NFC: Rename FunctionTypeRef::{getArguments() -> getParameters()} 2017-10-16 16:46:45 -07:00
Pavel Yaskevich
3f58daba4a [RemoteAST] Extend MetadataReader to collect flags related to function parameters 2017-10-16 16:46:45 -07:00
Slava Pestov
55cd329cb3 Reflection: Remove logic for the parent metadata source 2017-09-25 15:45:17 -07:00
Slava Pestov
61639cf971 RemoteAST: Stop looking at parent metadata field 2017-09-25 15:45:16 -07:00
Greg Parker
c262440e70 [runtime] Fix some const cast warnings. 2017-08-31 18:22:17 -07:00
Arnold Schwaighofer
ca63326e1b Delete unused existential value witnesses from the old existential
implementation

And remove the SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS flag.
2017-06-02 14:34:41 -07:00
Slava Pestov
9599211e80 Reflection: Remove unused vestiges of now-gone AnyObject protocol 2017-05-09 00:16:04 -07:00
Slava Pestov
8416b1caf7 Reflection: Don't crash if closure capture type cannot be demangled
I don't have a test case, but this will address the
crashes in <rdar://problem/30398155> and
<rdar://problem/31961386>.
2017-05-04 15:45:49 -07:00
Slava Pestov
23ded3cf6f Reflection: Fix crash when reflecting existential with fileprivate protocol member
Fixes <rdar://problem/31661662>, <rdar://problem/31668126>,
and probably many other crashes with the same backtrace.
2017-05-04 15:45:35 -07:00
Slava Pestov
f3761c1c2e Reflection: Update for subclass existentials and primitive AnyObject 2017-05-02 02:23:08 -07:00
Slava Pestov
a77f2f2045 Reflection: Share a Demangler instead of creating new ones all the time 2017-05-02 01:19:36 -07: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
Slava Pestov
ea4fe32295 Reflection: Give up instead of producing an empty field list if a field type does not demangle
Better to fail instead of producing an invalid layout.
2017-05-02 01:18:24 -07:00
Arnold Schwaighofer
d5cbb0bd62 Runtime changes for the copy-on-write existential implementation
Adds the runtime implementation for copy-on-write existentials. This support is
enabled if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is defined. Focus is on
correctness -- not performance yet.

Don't use allocate/deallocate/projectBuffer witnesses for globals in cow
existential mode.

Use SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS configuration to set the default for
SILOptions.

This includes an IRGen fix to use the right projection in
emitMetatypeOfOpaqueExistential if SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS is set.

Use unknownRetain instead of native retain in dynamicCastToExistential.
2017-03-15 14:54:55 -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
Erik Eckstein
2d127e4192 Reinstate ”Use the new mangling for reflection."
It also uses the new mangling for type names in meta-data (except for top-level non-generic classes).
lldb has now support for new mangled metadata type names.

This reinstates commit 21ba292943.
2017-02-15 09:47:22 -08:00
Erik Eckstein
254f36aba5 Revert "Use the new mangling for reflection."
This needs some changes in lldb.
Disabled for now until lldb supports the new mangling.

This reverts commit 21ba292943.
2017-02-08 09:01:51 -08:00
Erik Eckstein
21ba292943 Use the new mangling for reflection.
For this we are linking the new re-mangler instead of the old one into the swift runtime library.
Also we are linking the new de-mangling into the swift runtime library.

It also switches to the new mangling for class names of generic swift classes in the metadata.
Note that for non-generic class we still have to use the old mangling, because the ObjC runtime in the OS depends on it (it de-mangles the class names).
But names of generic classes are not handled by the ObjC runtime anyway, so there should be no problem to change the mangling for those.
The reason for this change is that it avoids linking the old re-mangler into the runtime library.
2017-02-07 08:36:21 -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
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
Hugh Bellamy
137b2ab295 Fix errors and warnings building swift/reflection on Windows with MSVC 2016-12-11 10:00:32 +00: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
Slava Pestov
1c7a50dcc5 Reflection: Fix class layout, again
There were a few problems here with subclasses of Objective-C classes.
Use the InstanceStart field from rodata to correctly lay out instance
variables, and verify the results match with dynamic and static layout.

Better fix for <rdar://problem/27932061>.
2016-11-16 19:31:18 -08:00
Slava Pestov
db79762c3b Reflection: Fix class layout start offset calculations
Fixes <rdar://problem/29115967>.
2016-11-11 03:13:22 -08:00
Slava Pestov
83692bb398 Reflection: Fix bug where presence of a no-payload enum resets field offsets back to zero for subsequent fields
The alignment was set to 0, which messed up the record layout
computations. Add an assert to catch this in the future.

Fixes <rdar://problem/29115967>.
2016-11-10 22:43:15 -08:00
Slava Pestov
e32a8fcd03 Reflection: Remove a bit of dead code 2016-09-24 02:17:46 -07:00
Slava Pestov
5e632f8e86 Reflection: Walk up the superclass chain when resolving associated types
Now that IRGen emits the right metadata, we can make use of it to fix
associated type lookup.

Fixes <rdar://problem/28331935>.
2016-09-24 02:17:46 -07:00
Slava Pestov
2e6e2c2b17 Reflection: Fix crash in single-payload enum layout if payload type could not be lowered
Fixes <rdar://problem/27906876>.
2016-08-23 18:30:00 -07:00
David Farler
787b0dcc3f Merge pull request #3419 from bitjammer/remote-mirror-metadata-version
SwiftRemoteMirror: Add reflection metadata version query API
2016-07-14 08:30:18 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07: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
Saleem Abdulrasool
f29e6144a4 Reflection: use std::strtol instead of std::atoi
Address post-commit review comments from Harlan.  Use `std::strtol` as it can
deal with hex and octal inputs.
2016-06-22 19:07:59 -07:00
Saleem Abdulrasool
b979359d43 Reflection: use atoi instead of stoi
The Microsoft C++ library does not have std::stoi.  Opt to use std::atoi with
the C-string backing the std::string.  NFC.
2016-06-20 07:13:00 -07: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
2799cabcfb SwiftRemoteMirror: Dig into generic SIL boxes
Part 1: Generic SIL Boxes always have instatiated metadata with kind
HeapGenericLocalVariable, which includes a metadata pointer for the
boxed type.

Part 2, after this, is to provide some kind of outgoing pointer map for
fixed heap boxes, whose metadata may be shared among different but
destructor-compatible types.

rdar://problem/26240419
2016-05-17 01:30:28 -07:00
David Farler
c9e0df7d4d Add an opaque field for necessary bindings struct
Without this, offsets of captures in closure contexts may be
incorrect if there is a non-empty necessary bindings structure
at the front.

rdar://problem/26312900
2016-05-16 20:25:35 -07:00
practicalswift
21c872c590 [gardening] Fix recently introduced typos. 2016-05-14 20:33:28 +02: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
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