Commit Graph

115 Commits

Author SHA1 Message Date
tbkka
3c8fde7885 Implement MultiPayloadEnum support for projectEnumValue (#30635)
This code rearchitects and simplifies the projectEnumValue support by
introducing a new `TypeInfo` subclass for each kind of enum, including trivial,
no-payload, single-payload, and three different classes for multi-payload enums:

* "UnsupportedEnum" that we don't understand.  This returns "don't know" answers for all requests in cases where the runtime lacks enough information to accurately handle a particular enum.

* MP Enums that only use a separate tag value.  This includes generic enums and other dynamic layouts, as well as enums whose payloads have no spare bits.

* MP Enums that use spare bits, possibly in addition to a separate tag.  This logic can only be used, of course, if we can in fact compute a spare bit mask that agrees with the compiler.

The final challenge is to choose one of the above three handlings for every MPE.  Currently, we do not have an accurate source of information for the spare bit mask, so we never choose the third option above.  We use the second option for dynamic MPE layouts (including generics) and the first for everything else.

TODO: Once we can arrange for the compiler to expose spare bit mask data, we'll be able to use that to drive more MPE cases.
2020-03-31 15:12:44 -07:00
Mike Ash
625768e976 [Reflection] Fix up Reflection/existentials.swift test.
rdar://problem/59909982
2020-03-27 10:11:19 -04:00
Mike Ash
3a9e7a6611 [Reflection] Implement TypeRef demangling for foreign classes.
rdar://problem/59909982
2020-03-25 17:22:45 -04:00
Mike Ash
e05720cd09 [RemoteMirror] Add a call to get the demangled name for a typeref.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Meghana Gupta
8e800e49bf Recommit #29812 with fixes (#30342) 2020-03-13 19:34:16 -07:00
tbkka
ee36c1cc3e RemoteMirror: Project some multi-payload enums (#30357)
* First part of multi-payload enum support

This handles multi-payload enums with fixed
layouts that don't use spare payload bits.
It includes XI calculations that allow us to
handle single-payload enums where the payload
ultimately includes a multi-payload enum
(For example, on 32-bit platforms, String uses
a multi-payload enum, so this now supports single-payload
enums carrying Strings.)
2020-03-11 18:48:39 -07:00
Rintaro Ishizaki
ccbc26d947 Revert "Use in_guaranteed for let captures (#29812)"
This reverts commit 13b9915c6f.
2020-03-10 16:08:08 -07:00
Meghana Gupta
13b9915c6f Use in_guaranteed for let captures (#29812)
* Use in_guaranteed for let captures

With this all let values will be captured with in_guaranteed convention
by the closure. Following are the main changes :

SILGen changes:
- A new CaptureKind::Immutable is introduced, to capture let values as in_guaranteed.
- SILGen of in_guaranteed capture had to be fixed.
  in_guaranteed captures as per convention are consumed by the closure. And so SILGen should not generate a destroy_addr for an in_guaranteed capture.
  But LetValueInitialization can push Dealloc and Release states of the captured arg in the Cleanup stack, and there is no way to access the CleanupHandle and disable the emission of destroy_addr while emitting the captures in SILGenFunction::emitCaptures.
  So we now create, temporary allocation of the in_guaranteed capture iduring SILGenFunction::emitCaptures without emitting destroy_addr for it.

SILOptimizer changes:
- Handle in_guaranteed in CopyForwarding.
- Adjust dealloc_stack of in_guaranteed capture to occur after destroy_addr for on_stack closures in ClosureLifetimeFixup.

IRGen changes :
  - Since HeapLayout can be non-fixed now, make sure emitSize is used conditionally
  - Don't consider ClassPointerSource kind parameter type for fulfillments while generating code for partial apply forwarder.
    The TypeMetadata of ClassPointSource kind sources are not populated in HeapLayout's NecessaryBindings. If we have a generic parameter on the HeapLayout which can be fulfilled by a ClassPointerSource, its TypeMetaData will not be found while constructing the dtor function of the HeapLayout.
    So it is important to skip considering sources of ClassPointerSource kind, so that TypeMetadata of a dependent generic parameters gets populated in HeapLayout's NecessaryBindings.
2020-03-10 12:23:02 -07:00
Mike Ash
b80e33b514 Fix reuse of the payload area when the discriminator != 0 2020-03-09 11:58:54 -07:00
Tim Kientzle
03a0042ace API changes in SwiftRemoteMirror make these tests unsuitable for back-deployment testing 2020-03-07 13:13:23 -08:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Joe Groff
e844771a74 Remove explicit target(s) from reflect_empty_struct tests
Swift CI tests backward deployment on different host OSes, so this should be covered in
testing. The explicit target doesn't work well with `executable_test` since it leads to
binaries with too-new minimum deployment targets getting executed on older host OSes.
2020-03-02 12:38:32 -08:00
Mike Ash
76a6f88b3a [Test] Mark Reflection/existentials.swift as unsupported when testing against the OS stdlib, as the test looks for a recent Remote Mirror addition to print the mangled name of a typeref.
rdar://problem/58939662
2020-01-27 21:04:32 -05:00
swift-ci
72229ba355 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-24 16:43:36 -08:00
Slava Pestov
305620b354 ClangImporter: Reconcile Clang declaration hidden-ness between loadAllMembers() and lazy loading
Lazy loading checked if the ClangDecl was hidden, but loading all
members did not. Let's make loadAllMembers() behave like the lazy
path, and fix some of the mock SDKs in the test suite.
2020-01-24 17:07:08 -05:00
Adrian Prantl
ea2b5eced9 Reflection: Implement a TypeRef -> Demangle tree adapter.
To allow more pervasive use of TypeRefs in LLDB, we need a way to build mangled
names from TypeRef pointers to allow round-tripping between TypeRefs and AST
types. The goal is to experiment with making lldb::CompilerType backed by
TypeRefs instead of AST types.

<rdar://problem/55412775>
2020-01-14 17:50:01 -08:00
Joe Groff
509735ea66 IRGen: Work around RemoteMirror bug generating reflection info for empty builtin types.
The RemoteMirror library in shipping versions of macOS/iOS/tvOS/watchOS crashes if the compiler
emits a BuiltinTypeDescriptor with size zero. Although this is fixed in top-of-tree RemoteMirror,
we want binaries built with the new compiler to still be inspectable when run on older OSes.
Generate the metadata as an empty struct with no fields when deploying back to these older
platforms, which should be functionally equivalent for most purposes.
Fixes rdar://problem/57924984.
2020-01-06 19:32:43 -08:00
Mike Ash
8e7c6a5c14 [Test] Disable reflect_Enum_(254|Two)CaseNoPayloads.swift when testing the OS stdlib.
rdar://problem/58087442
2019-12-19 15:41:29 -05:00
tbkka
2b5ada11cb Correctly calculate extra inhabitants for no-payload enums (#28830)
In particular, this fixes the size calculation for nested enums,
specifically enums within Optionals.  Without this, the
reflection library computes `v` below as requiring two bytes
instead of one.

```
enum E {
case a
case b
}

let v = Optional<E>
```

This also adds a number of test cases for enums alone and
wrapped in optionals, including:
* Zero-case enums are allocated zero size and have zero extra inhabitants
* Zero-case enums in optionals also get zero size
* One-case no-payload enums are allocated zero size and have zero extra inhabitants
* One-case no-payload enums in optionals get one byte allocated and have zero extra inhabitants
* 254-case enums have only two extra inhabitants, so putting them in thrice-nested optionals requires an extra byte
* Various cases where each nested optional gets an extra byte

Resolves rdar://31154770
2019-12-17 14:52:35 -08:00
Mike Ash
e7163006ee [Reflection] Accept BuiltinTypeDescriptors with zero size.
rdar://problem/56784375
2019-11-14 16:43:51 -05:00
Mike Ash
c81141af1d [Reflection] Add a test for reflecting empty structs.
rdar://problem/56784375
2019-11-14 16:22:32 -05:00
Jordan Rose
056979680d Revert "[reflection] Fix tests with bitwise_takable output"
This reverts commit b906348665.
2019-10-16 16:09:56 -07:00
Ivan Smetanin
b906348665 [reflection] Fix tests with bitwise_takable output 2019-10-16 09:03:55 +03:00
Mike Ash
3e7307b5ce [Reflection] Reenable inherits_ObjCClasses and inherits_NSObject tests on watchOS.
These are working again. I suspect that they were caused by a linker bug we've since worked around.

rdar://problem/50898688
2019-09-04 11:33:30 -04:00
Karoy Lorentey
b90e2ef776 [test] Denineninenineninify behavioral tests added for 5.1 2019-08-27 15:44:04 -07:00
Joe Groff
33e7ed74bc ReflectionContext: Keep read range properly-aligned.
If a Mach-O image got emitted in just the wrong way, the range of `__TEXT,__swift*` sections to
read could end up starting at an unaligned address (because things like type refs have only one
byte alignment), and this would cause the reflection context to read an unaligned chunk of the
remote memory, causing alignment errors when addresses are mapped to the local copy. Keep the ranges
at least 8-byte-aligned to stave off the alignment issues we might run into with any metadata
structures, which are generally at most pointer aligned. Fixes rdar://problem/54556791
2019-08-26 16:24:26 -07:00
Arnold Schwaighofer
818d0f5c3d FAIL test on armv7k
It fails on a bot
rdar://54556791
2019-08-22 09:47:21 -07:00
Michael Gottesman
6f42934462 [test] Disable inherits_NSObject.swift on watchOS.
This was failing alongside inherits_ObjCClasses.swift (they were failing at the
same time).

Until MikeA has time to look at this disable this as well.

rdar://problem/50898688
2019-05-24 10:14:32 -07:00
Mike Ash
5bcdb3c75c [Test] Disable inherits_ObjCClasses.swift on watchOS.
It's failing and it's going to take some more time to figure out why.

rdar://problem/50898688
2019-05-21 17:07:34 -04:00
Mike Ash
d15a651094 [Test] Disable existentials_objc.swift when testing against OS libraries, as the 5.0 libraries don't support it.
rdar://problem/50175995
2019-05-20 15:31:25 -04:00
Slava Pestov
dc3abd14c3 MetadataReader: Add support for Objective-C tagged pointers (#22498)
This allows Remote Mirrors and RemoteAST to inspect existentials
containing instances of imported classes.
2019-02-10 12:23:37 -05:00
Michael Ilseman
5a6d2dfa59 [String] Switch ABI to only use 4 discriminator bits.
In anticipation of potential future HW features, e.g. armv8.5 memory
tagging, only use the high 4 bytes as discriminator bits in
_BridgeObject rather than the top 8 bits. Utilize two perf flags to
cover this instead. This requires shifting around a fair amount of
internal complexity.
2018-12-19 13:54:50 -08:00
Stephen Canon
fb8b9e143d SIMD into stdlib
Implements SE-0229.

Also updates simd module types in the Apple SDKs to use the new types, and updates a couple tests to work with the new types and protocols.
2018-11-29 17:09:01 -05:00
Karoy Lorentey
3b748933f1 [stdlib] _StringObject: Use a full 8-bit discriminator on 32-bit platforms
We now have plenty of extra inhabitants in the variant enum, so we can get rid of the 7-bit hack.

It’d also be possible now to increase small string capacity to a spacious 11 bytes; however this needs a full overhaul of the 32-bit representation, so it needs a little bit more time in the oven.
2018-11-16 18:36:03 +00:00
Joe Groff
ca402f19b1 Give multi-payload enums extra inhabitants.
Previously, they would forward their unused spare bits to be used by other multi-payload enums, but
did not implement anything for single-payload extra inhabitants.
2018-11-13 18:08:01 -08:00
Joe Groff
ff7afcdfd7 Give more extra inhabitants to BridgeObject.
The standard library never ended up needing the low extra inhabitants (<4G on 64-bit Darwin,
<4K elsewhere), so BridgeObject can have the same set of extra inhabitants as the other refcounted
types, allowing `String?????` and `Array??????????` to still use optimized representations.
rdar://problem/45881464
2018-11-07 19:03:22 -08:00
Slava Pestov
00c1279dbb Reflection: Compute if types are bitwise takable
Bitwise takability is now part of the layout of a type, because
non-bitwise takable types are never stored inline in an
existential or resilient global's buffer, even if they would
fit.

The basic rule is that weak references, unknown-refcounted
unowned references, and aggregates that contain them, are not
bitwise takable, whereas everything else is bitwise takable.

Also, since the bitwise takable for an unowned reference
depends on the reference counting style, we have to record the
superclass of a protocol, if any, to correctly determine the
reference counting style of the protocol existential.
2018-11-07 00:32:12 -05:00
Karoy Lorentey
40aae6b235 [String] 32-bit platform support
Add support for 32-bit platforms for UTF-8 backed String.
2018-11-04 10:42:41 -08:00
Michael Ilseman
e6582c37ee [test] Adjust String tests for UTF-8 representation.
Adjust tests for the UTF-8 representation, in preparation for 32-bit
support. Includes UTF-8 literal update.
2018-11-04 10:42:41 -08:00
Karoy Lorentey
aba15a1151 [test] Set and Dictionary now has an extra inhabitant (32-bit) 2018-10-06 01:47:09 +01:00
Karoy Lorentey
3665294d1e [test] Set and Dictionary now has an extra inhabitant 2018-10-05 12:33:25 +01:00
Joe Groff
93d85997e8 Generalize extra inhabitants of tuples.
Like we did for structs, make it so that tuple types can also get extra inhabitants from whichever element with the most, not only the first. This lets us move all of the extra inhabitant handling functionality between structs and tuples in IRGen up to the common RecordTypeInfo CRTP base.
2018-09-20 15:39:44 -07:00
Joe Groff
b4abe8503a Give opaque existential containers extra inhabitants.
We can use the extra inhabitants of the type metadata field as extra inhabitants of the entire
existential container, allowing `Any?` and similar types to be the same size as non-optional
existentials.
2018-09-14 12:07:58 -07:00
Jordan Rose
b7aacec9ce [test] Fix swift-reflection-test issues for all test run environments (#19171)
I stopped trying to guess and actually tested them all, including the
Apple-internal tool I keep breaking. As a bonus, the RUN lines in
validation-test/Reflection/ go back to being simple.

rdar://problem/44154961
2018-09-06 16:05:56 -07:00
Jordan Rose
7ec1db9aa3 Re-apply "[test] Yet more tweaks to remote-run" (#19150) 2018-09-05 19:24:51 -07:00
Jordan Rose
1377722f86 Revert "[test] Yet more tweaks to remote-run" 2018-09-05 10:29:01 -07:00
Jordan Rose
c52809be0f [test] One last tweak to "%target-run-reflection-test"
Copy %target-swift-reflection-test into %t instead of using a hard
link. The problem with hard links is that they can be overwritten when
the test fails, which would then truncate the original executable to
an empty file!
2018-09-04 18:25:24 -07:00
Jordan Rose
e3f3e939cb [test] Fix target-based reflection tests for real (#19098)
- Hard-link %target-swift-reflection-test into %t/ for %target-run
  implementations that copy executables, like remote-run.
- Use DYLD_LIBRARY_PATH to undo that for %target-run implementations
  that run the executable in place (host and simulators)

rdar://problem/43809613
2018-09-04 08:45:25 -07:00
Doug Gregor
ecf752d54b Revert "Revert " [Foundation] Collapse (SignedInteger|UnsignedInteger) reqts into FixedWidthInteger"" 2018-08-29 13:18:44 -07:00
Jordan Rose
11bddb49a0 [test] Temporarily disable Reflection tests on non-macOS (#19031)
utils/remote-run will only run things in %t.
An Apple-internal tool doesn't follow symlinks.
Normal macOS and simulator runs find the support libraries relative to
the binary.

I'm not sure what to do yet, but for now let's unbreak the
Apple-internal bots I broke in 01a0de2.
2018-08-29 11:38:27 -07:00