Commit Graph

33 Commits

Author SHA1 Message Date
Davide Italiano
b4434fdd8d [Reflection] Fix the computation of boundaries in getFieldName(). 2019-05-06 17:27:20 -07:00
Davide Italiano
1acedc6c69 [Reflection] Check that the offset is within the section.
<rdar://problem/49043621>
2019-05-03 17:09:09 -07:00
Joe Groff
05dfec0cda Push the conformance accessor hack down into getTypeByMangledName. 2019-04-17 14:44:40 -07:00
Erik Eckstein
a60086f1dd Runtime: use lambdas to avoid allocations in std::function
Instead of capturing SubstGenericParametersFromMetadata and SubstGenericParametersFromWrittenArgs by value, capture by reference.
This avoids those instances to be copied and thus avoids a lot of mallocs.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
John McCall
d07efd37e0 Requestify the mangling-to-metadata APIs.
Note that I've called out a couple of suspicious places where we
are requesting abstract metadata for superclasses but probably
need to be requesting something more complete.
2019-02-05 16:20:48 -05:00
Doug Gregor
986b8f3f9f [Runtime] Make swift_getTypeByMangled(Name|Node) overridable.
Rename the funnel points for demangling strings/nodes to metadata to
swift_getTypeByMangled(Name|Node) and make them overridable. This will let
us back-deploy mangling improvements and bug fixes.
2018-11-15 16:43:38 -08:00
Doug Gregor
cd6d6be64d [Runtime] Consolidate runtime functions used for demangle-to-metadata.
Clean up the interfaces used to go from a mangled name or demangle tree to
metadata. Parameterize these interfaces for generic parameter substitutions
(already in use) and dependent conformance substitutions (speculative).
2018-11-15 15:57:44 -08:00
Mike Ash
101c7cbbdb [Runtime] Fix a leak when reading a weak property with Mirror.
SR-8878 rdar://problem/44872927
2018-10-09 12:48:44 -04:00
Doug Gregor
0a775dab54 [Runtime] Extract a function object for demangling using base metadata.
The field metadata translation has a great little lambda for extracting
generic arguments from metadata when demangling. Extract it into a
reusable function object.
2018-09-22 20:38:47 -07:00
Doug Gregor
6982284baf [Runtime] Only request Abstract metadata when demangling to metadata.
When SWIFT_ENABLE_MANGLED_NAME_VERIFICATION is set, we would end up
deadlocking when we encounter a metadata cycle. The demangling code only
requires abstract metadata, because at most it needs type identity and
filling in the type arguments of generics. Update clients of
_getTypeByMangledName to assert the kind of metadata they require.
2018-09-21 22:40:44 -07:00
Joe Groff
e9b45178a0 Make runtime warnings about missing metadata more descriptive.
Describe the consequences of missing metadata instead of just posting a scary
message about a bug.  Furthermore, since these warnings tend to show up in
playgrounds, and probably aren't relevant to the user of a playground, suppress
them when running in a playground. rdar://problem/44642942
2018-09-20 13:03:54 -07:00
Joe Groff
2166dfcfdd Merge pull request #18746 from jckarter/nominal-type-field-info-xref
IRGen/Runtime: Reference field descriptor directly from type context descriptors.
2018-08-20 13:32:39 -07:00
Joe Groff
6ea8134eac Runtime: Simplify getFieldAt and take it private. 2018-08-15 16:44:16 -07:00
Mike Ash
46309d9794 [Runtime] Rename swift_unknown* functions to swift_unknownObject*.
These functions don't accept local variable heap memory, although the names make it sound like they work on anything. When you try, they mistakenly identify such things as ObjC objects, call through to the equivalent objc_* function, and crash confusingly. This adds Object to the name of each one to make it more clear what they accept.

rdar://problem/37285743
2018-08-15 17:48:23 -04:00
Joe Groff
6f45c2a36e IRGen/Runtime: Reference field descriptor directly from type context descriptors.
This saves us some expensive cross-referencing and caching in the runtime, and lets us reclaim the `isReflectable` bit from the context descriptor flags (since a null field descriptor is a suitable and more accurate indicator of whether a type is reflectable).
2018-08-15 14:19:53 -07:00
Azoy
b8fc8b333c Remove _interface 2018-07-29 10:41:22 -04:00
Michael Gottesman
5648ef219d [+0-all-args] Clean up remains of +1 convention from the runtime. 2018-07-06 23:10:12 -07:00
Joe Groff
06ac23842f IRGen: Correctly set and honor the "is reflectable" bit on structs and classes.
If we only emit an opaque reflection record for a struct or class, then we can't reflect its fields. We failed both to clear the "is reflectable" bit in the context descriptor for non-reflectable structs, and to check for the bit before trying to present a struct's fields as children in the runtime. rdar://problem/41274260
2018-07-03 13:52:46 -07:00
Joe Groff
5887165582 Merge pull request #15565 from tanner0101/get-field-c-callable
[runtime] make `swift_getFieldAt` callable from C / Swift
2018-06-13 09:39:32 -07:00
Joe Groff
681a96b45c Runtime: Tolerate unknown metadata kinds.
We want to be able to potentially introduce new metadata kinds in future Swift compilers, so a runtime ought to be able to degrade gracefully in the face of metadata kinds it doesn't know about. Remove attempts to exhaustively switch over metadata kinds and instead treat unknown metadata kinds as opaque.
2018-05-17 15:35:06 -07:00
tanner0101
1af7c118ab make swift_getFieldAt runtime method c-callable 2018-03-27 02:21:05 -04:00
Arnold Schwaighofer
9d8c381ab4 Remove resilient tag indices 2018-03-20 13:19:56 -07:00
Joe Groff
7f9e322d98 [+0-all-args] Knock out some inappropriate "unreachable"s in the runtime.
Future Swifts may add new metadata kinds, so it isn't appropriate to crash when
we see one. In the case of reflection, we can fall back to opaque behavior.

rdar://34222540
2018-03-09 22:44:04 -08:00
John McCall
f2bb319bdb Change the pattern of generic class metadata instantiation.
Minimize the generic class metadata template by removing the
class header and base-class members.  Add back the set of
information that's really required for instantiation.
Teach swift_allocateGenericClass how to allocate classes without
superclass metadata.  Reorder generic initialization to establish
a stronger phase-ordering between allocation (the part that doesn't
really care about the generic arguments) and initialization (the
part that really does care about the generic arguments and therefore
might need to be delayed to handle metadata cycles).

A similar thing needs to happen for resilient class relocation.
2018-03-04 00:01:56 -05:00
Saleem Abdulrasool
c6eed1f19b runtime: make Windows build again
Windows does not have `strndup` and `asprintf`.  Provide equivalents in
terms of other available APIs.  This enables us to build the standard
library for Windows again.
2018-02-28 11:16:18 -08:00
John McCall
4e49329393 Make is-reflectable a type descriptor flag instead of a separate field.
Also fix a test for 32-bit compatibility.
2018-02-28 00:38:00 -05:00
Mike Ash
03476e919e Merge branch 'master' into remove-reflectionlegacy 2018-02-22 11:44:55 -05:00
Mike Ash
50697a7778 [Runtime] Guard ReflectionMirror's vw_destroy call to avoid emitting it when +0 is enabled.
rdar://problem/20356017
2018-02-21 14:33:05 -05:00
Mike Ash
29eb740bf3 [Runtime] Style fixes in new ReflectionMirror code.
rdar://problem/20356017
2018-02-21 14:32:17 -05:00
Mike Ash
0cff498db4 [Reflection] Use getClassObject() when testing for ObjCness rather than blindly casting to ClassMetada, which turns out to be completely incorrect. 2018-02-20 15:15:14 -05:00
Mike Ash
44d9b2f5cd [Runtime] Move swift_demangle to Demangle.cpp. It seems more at home there. 2018-02-16 16:55:11 -05:00
Mike Ash
33990583df [Runtime] Have ReflectionMirror.mm get SwiftObject declarations from SwiftObject.h. 2018-02-16 16:20:12 -05:00
Mike Ash
4045edf886 [Runtime] Remove old-style mirrors in ReflectionLegacy.swift.
The old-style mirrors were the basis for non-custom, reflection based Mirrors. As part of removing old-style mirrors, reflection based Mirrors are reimplemented without them. Reflection.mm is deleted and replaced with ReflectionMirror.mm, which borrows a chunk of the old code but presents a simpler API to the Swift side. ReflectionMirror.swift then uses that API to implement a reflection-based Mirror init.

rdar://problem/20356017
2018-02-16 16:05:40 -05:00