Commit Graph

228 Commits

Author SHA1 Message Date
LamTrinh.Dev
999e287d99 Update existentials_objc.swift
Adding comment for "// REQUIRES: reflection_test_support"
2024-07-29 22:56:41 +07:00
LamTrinh.Dev
1684a50966 Update inherits_Swift.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 18:05:08 +07:00
LamTrinh.Dev
35c050df37 Update inherits_ObjCClasses.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 18:04:31 +07:00
LamTrinh.Dev
129126d5f1 Update inherits_NSObject.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 18:04:03 +07:00
LamTrinh.Dev
58ed9e7fd3 Update functions_objc.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 18:03:43 +07:00
LamTrinh.Dev
5db4317811 Update functions.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 18:03:18 +07:00
LamTrinh.Dev
971048907b Update existentials.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 17:59:08 +07:00
LamTrinh.Dev
86dc6271fe Update existentials_objc.swift
Adding more comment for "UNSUPPORTED: asan".
2024-07-27 17:55:48 +07:00
Tim Kientzle
cbd0c14407 New reflect_Actor test 2024-07-26 17:17:29 -07:00
Tim Kientzle
f73cfa7396 Reflection tests are incompatible with ASAN 2024-07-26 09:55:08 -07:00
Tim Kientzle
8d22ae449c More MPE improvements
This fills in a number of missing cases:
* MPEs with closure payloads
* MPEs with many non-payload cases
* MPEs with class existential payloads
* MPEs with existential metatype payloads

Resolves rdar://132270733
Resolves rdar://128705332
2024-07-23 16:08:57 -07:00
Tim Kientzle
eba980af03 Limit this test to macOS 2024-06-05 17:47:30 -07:00
Tim Kientzle
40eb3c084d Expand the work from #73491 to support more MPE layouts. This also switches the
MPE layout code to exclusively use the new code.  The key observation: existing
reflection metadata seems to already provide enough information in all cases, so
we can abandon an earlier effort to add spare bitmask data.

Resolves rdar://129281368
2024-06-05 10:15:58 -07:00
Tim Kientzle
ea87a273d7 Redesign the spare bit mask calculation
This adds a `getSpareBits` method to all the TypeInfo classes
that returns a suitable bitmask indicating the spare bits available
in values of this type.  This gives us a way to recursively explore
the type tree and build up a full spare bit mask for an arbitrary type.

Happily, it appears we actually do have enough information to do this
calculation entirely from first principles, without requiring additional
reflection information.  So once this is stable, we should remove my
earlier incomplete effort to publish spare bit mask info in the reflection
data, as that adds unnecessary metadata to every binary.

This doubtless still has plenty of holes, but seems sufficient
to handle a few basic enum types, including the stdlib DecodingError
which was used as an example to work out some key issues.
2024-05-07 14:17:00 -07:00
Tim Kientzle
35a98aad20 Fix enum inspection of a no-payload enum inside another enum
When a no-payload enum is stored inside a multi-payload enum,
the outer enum may be using some of the extra high-order bits.
So when we examine the inner enum, we should just strip those bits.
2024-03-13 09:14:37 -07:00
Tim Kientzle
5d4c29cd09 Fix a bunch of reflection tests to be correct for Ubuntu
These tests had Darwin-specific code in them, mostly unnecessary,
that caused them to break on non-Darwin platforms.

Only one (reflect_Enum_SingleCaseCFPayload.swift) was actually
specific to Darwin.  That one has been disabled.  For the rest,
just delete the unnecessary `import Darwin` and similar.
2023-10-24 06:58:41 -07:00
Tim Kientzle
8bb3a55702 [RemoteInspection] Allow enums to be trivial even with a formal payload
A "trivial" enum is one that carries no information.
The previous logic asserted that a trivial enum had only one
case and that case had no payload.
But this is also a trivial payload:
```
// Trivial, so zero-sized
enum MyFormatVersion {
  case v4
}
// Also trivial, since the payload carries no information
enum Format {
  case MyFormat(MyFormatVersion)
}
```

This commit adds a test case similar to the above
and corrects the assertions for trivial enums to
assert that there is either no payload, or that the
payload is zero-sized.

Resolves rdar://116406504
2023-10-03 14:06:12 -07:00
Hiroshi Yamauchi
ed58501ecd Account for the generic zero-sized payload enum cases.
Disable the assert:

    // At least one payload is non-empty (otherwise this                                                                                                                  // would get laid out as a non-payload enum)                                                                                                                          assert(getNumNonEmptyPayloadCases() > 0);

in TaggedMultiPayloadEnumTypeInfo because it fails when you have
generic but zero-sized payload enum cases.

Also remove unnecessary "REQUIRES: objc_interop" lines from the enum
reflection tests.
2023-09-21 09:31:24 -07:00
Tim Kientzle
a897fcb47c Correctly project enums with zero-sized payloads
I earlier overhauled the enum layout logic to correctly consider
enums with generic cases and cases that have zero size.
This updates the enum projection logic to use that information
as well.

In particular, this fixes a bug where an MPE with zero-sized cases
would be incorrectly projected by RemoteMirror (with consequences
for the `leaks` tool and lldb).

Resolves rdar://111705059
2023-07-12 08:46:32 -07:00
Tim Kientzle
3f70b051a3 Fix this on 32 bit targets 2023-05-01 12:03:26 -07:00
Tim Kientzle
5d67b814f5 Fix case calculation for SPE with zero-sized payload 2023-04-25 15:00:51 -07:00
Tim Kientzle
8da561c8cb More tests! 2023-04-24 16:42:08 -07:00
Tim Kientzle
9bfe1b1691 Merge branch 'main' into tbkka-RemoteMirror-MPE-zero-sized-plus-generics 2023-04-24 08:22:38 -07:00
Tim Kientzle
ed28d8e4eb Add a test case where the innermost type has no generic parameters 2023-04-22 11:52:31 -07:00
Tim Kientzle
16c0729492 Correct and simplify the test from PR #62854
The new logic no longer includes non-generic parent types as part
of the type reference.

This also combines the 32- and 64-bit tests validations, since they
were identical for this test anyway.
2023-04-20 14:31:06 -07:00
Tim Kientzle
02160e68a0 Recursively reconstruct nested generics, skipping non-generic
This is a more correct fix for the issue that inspired PR #62854.
In particular, this does not change the numbering of generic
argument levels, and so does not break generic type parameter
lookups.

Added a new test case to verify that nested types that mix
generics and non-generics in different ways consistently identify
the correct generic argument labels.
2023-04-20 14:31:06 -07:00
Tim Kientzle
894f116189 Remove a test that is not actually ready; it was just an experiment 2023-04-12 17:24:12 -07:00
Tim Kientzle
a6ff81345a Make some tests work better on varying platforms.
In particular, the exactly internal layout of Array<> is quite
different between macOS and Linux, which makes it impractical
for use in tests like this.  An empty class is still a reference
and doesn't introduce so many complications.
2023-04-12 16:40:44 -07:00
Tim Kientzle
ef0eafc84f Generalize a test to work correctly on Linux aarch64 2023-04-11 17:40:07 -07:00
Tim Kientzle
2f27e06591 Generalize tests that already work for 32 bits 2023-04-06 13:27:06 -07:00
Tim Kientzle
3bb9285d45 Accurately distinguish generic and non-generic cases.
A "generic" case is any case whose payload type depends
on generic type parameters for the enum or any enclosing type.
Some examples:

```
struct S<T> {
  enum E {
    case a        // Non-generic case
    case b(Int)   // Non-generic case
    case c(T)     // Generic case
    case d([U])   // Generic case
    case e([Int]) // Non-generic case
  }
}
```

This is important for correctly distinguishing MPE versus
SPE layouts.  A case is considered "empty" only if it
is either a non-payload case (`case a`) or if the payload
is zero-sized and non-generic.  Generic cases are always
treated as non-zero-sized for purposes of determining
the layout strategy.

Correctly testing this is tricky, since some of the
layout strategies differ only in whether they export
extra tag values as XIs.  The easiest way to verify is
to check whether wrapping the result in an `Optional<>`
adds another byte to the overall size.
2023-04-03 17:17:59 -07:00
Tim Kientzle
e573366a53 Fix handling of generic MPEs
This exercises a number of cases that the previous logic got
wrong, including cases where MPEs are laid out like SPEs,
and cases where we use the SPE or MPE layout strategies for enums
that have no non-empty payloads.  (These cases are superficially
similar but differ in how they handle XIs.)

These new tests allowed me to correct a number logical flaws
about how layouts are selected.  In particular, cases with
generic payloads are always considered to be non-empty for
purposes of selecting a layout strategy.  Only cases that
are statically known to be empty are considered empty for
layout purposes.
2023-04-02 21:09:24 -07:00
Tim Kientzle
791d780da4 Merge pull request #59488 from tbkka/tbkka-remoteMirrorIndirectEnums
Test support for indirect enums in RemoteMirror
2023-02-15 10:30:08 -08:00
Tim Kientzle
017373b899 Add more detail to test 2023-02-14 10:41:15 -08:00
Tim Kientzle
a959161707 Fill in the missing 32-bit checks for this test 2023-01-26 14:29:03 -08:00
Tim Kientzle
693c276313 Disable this test on watchOS
I've not been able to fill in the 32-bit expectations here yet.
Until I can do that, this won't work on any 32-bit platforms.
2023-01-19 12:58:01 -08:00
Tim Kientzle
d969611ec5 Merge pull request #62614 from tbkka/tbkka-92945673-RemoteMirror-MPE
[RemoteMirror] Fix handling of zero-sized payloads and extra inhabitant calculations
2023-01-09 16:41:21 -08:00
Tim Kientzle
f087b5e0fb This PR aligns RemoteMirror more closely with the compiler's handling of enums
that contain zero-sized payloads, which should resolve a number of issues with
RemoteMirror incorrectly reflecting enum cases and/or measuring the layout of
structures containing enums.

Background: Enum cases that have zero-sized payloads are handled
differently from other payload-bearing cases.

1. For layout purposes, they're treated as
   non-payload cases.  This can cause an MPE to
   actually get represented in memory as a single-payload
   or non-payload enum.

2. However, zero-sized payloads are still considered for
   extra inhabitant calculations.  Since they have no
   extra inhabitants, this tends to cause such enums to
   also not expose extra inhabitants to containing enums.

This commit makes several change to how RemoteMirror determines
enum layout:

* The various "*EnumTypeInfo" classes now represent
  layout mechanisms -- as described in (1) above,
  this can differ from the source code concept.

* An Enum "kind" is separately computed to reflect the
  source code concept; this ensures that the dumped
  type information reflects the source code.

* For single-payload and no-payload _layouts_,
  the extra inhabitant calculation has been adjusted
  to ensure that zero-sized payloads are correctly
  considered.

Resolves: rdar://92945673
2023-01-06 11:16:07 -08:00
Augusto Noronha
893d83ba0a Fix wrong calculation of generic params per level when building decl
Fix computation of generic params per level when a generic type is
nested in  a non-generic one. For example, for the following code:

```
class A {
  class B<T, U> {
  }
}
```
Fix the array of generic params per level from [2] to [0, 2].

rdar://103457629
2023-01-06 10:41:41 -08:00
Nuri Amari
48604ca729 Merge pull request #61819 from NuriAmari/remote-ast-runtime-type-mismatch
Fix issues with runtime reporting incorrect types for nested generics
2022-11-07 14:01:38 -08:00
Nuri Amari
66f993194a Fix issues with runtime reporting incorrect types for nested generics
Fixes: https://github.com/apple/swift/issues/60565
2022-11-04 09:43:26 -07:00
Augusto Noronha
2ae06446a4 Add the reflect_Optional_Bool validation test
Bools are special in that they only need 1 bit of storage, and have many
extra inhabitants available. This adds a test to check that an optional
whose payload is a bool is reflected correctly.
2022-11-02 10:20:24 -07:00
Mike Ash
4945a56344 [Reflection] Put a recursion limit on readTypeFromMetadata.
We can end up with a stack overflow if we encounter a very deeply nested type, or bad data that looks like one. Fail gracefully for types that are nested beyond a limit. By default, the limit is 50.

rdar://100847548
2022-10-25 10:35:51 -04:00
Tim Kientzle
ea54c3ba40 First sketch of indirect enum support
This is basically an attempt to expand the test harness
to fully dump indirect enums using the existing RemoteMirror
facilities.
2022-06-16 09:54:49 -07:00
Doug Gregor
c76a99ba02 [SE-0352] Enable implicit opening of existentials by default 2022-04-20 17:51:04 -07:00
Tim Kientzle
1232424b44 RemoteMirror generic multi-payload-enum fixes (#41903)
Apparently, RemoteMirror chokes on certain MPEs with generic payload types.
It does not recognize the generic payload type so ends up defaulting to a
zero size.  This causes the overall enum size to be miscalculated unless there
is another non-generic payload that's at least as large.

The case below requires us to reprocess the metatype to "thicken" it.
That process inadvertently lost information about the depth of generic
nesting, which caused the RemoteMirror to be unable to resolve the type of
`C.E.t` at runtime.
```
  class C<T> {
    enum E<T> {
    case t(T)
    case u(Int)
    }
    var e: E<T>?
  }
```

Solution: add code to the thickening logic to recursively thicken
parent types to preserve the nesting of generics.

Resolves rdar://90490128
2022-03-28 14:47:17 -07:00
Tim Kientzle
4d91b45988 [RemoteMirror] Get spare bit info from reflection records (#40906)
This adds a new reflection record type carrying spare bit information for multi-payload enums.

The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask.

A few notes:
 * The internal calculation is not perfect.  In particular, it does not support MPEs that contain other enums (e.g., optionals).  It should accurately refuse to project any MPE that it does not correctly support.
 * The new reflection field is designed to be expandable; this might someday avoid the need for a new section.

Resolves rdar://61158214
2022-02-21 17:06:14 -08:00
Karoy Lorentey
e2cfab4f28 [stdlib][test] Adopt availability macros in tests 2021-10-31 15:00:58 -07:00
Augusto Noronha
f41d192b48 Implement projectExistentialAndUnwrapClass
Implement a version of projectExistential tailored for LLDB. There are 2
differences when projecting existentials for LLDB:

1 - When it comes to existentials, LLDB stores the address of the error
    pointer, which must be dereferenced.
2 - When the existential wraps a class type, LLDB expects the address
    returned is the class instance itself and not the address of the
    reference.

This patch also adapts the swift reflection test machinery to test
projectExistentialAndUnwrapClass as well. This is done by exposing
the new functionality from swift reflection test.  It is tested in
existentials.swift, and ensures that the typeref information is
exactly the same as what is expected from projectExistential,
except the out address.

(cherry picked from commit 55e971e06750c3ba29722d558cc5400298f6bdaf)
2021-06-16 08:54:50 -03:00
tbkka
f2544aafcc Release node factory storage after each demangling operation (#35961)
* Release node factory storage after each demangling operation

This adds missing clear() operations to a number of places in
RemoteMirror in order to reclaim memory after (de)mangling results
are no longer needed.

Before this, the RemoteMirror library had an unfortunate tendency to use
excessive amounts of memory as the demangler kept appending data to its
internal slab allocator.

Resolves rdar://72958641

* Include payload cases even if we cannot retrieve the typeinfo

Otherwise, we end up with inconsistent counts of payload and non-payload
cases, which screws up some of the enum management.

* Add a very basic check of enum with CF payload.
2021-03-09 16:37:39 -08:00