Commit Graph

87 Commits

Author SHA1 Message Date
Saleem Abdulrasool
5df0be0247 RemoteInspection: clean up CMakeLists.txt slightly (NFC)
Inline single use variable, inline CPP definition, and reflow some text.
2024-02-27 14:31:26 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Augusto Noronha
b42752a900 Add interface for lookup of external MultiPayloadEnumDescriptor
This is a follow up patch that allows for external DescriptorFinders to
provide MultiPayloadEnumDescriptors (this is done to support embedded
Swift debugging, which encodes the equivalent of Swift metadata as
DWARF).
2024-02-20 15:38:54 -08:00
Joe Groff
b9f91144d1 Fix ABI breakage caused by ValueOwnership order change.
The `ABI` headers had accidentally grown an `#include` into compiler headers,
allowing the enum constant values of the `ValueOwnership` enum to leak into
the runtime ABI. Sever this inappropriate relationship by declaring a separate
`ParameterOwnership` enum with ABI-stable values in the ABI headers, and
explicitly converting between the AST and ABI representation where needed.
Fixes rdar://122435628.
2024-02-20 07:55:16 -08:00
Michael Gottesman
f4efcec55c [transferring] Add mangling support for transferring.
This includes runtime support for instantiating transferring param/result in
function types. This is especially important since that is how we instantiate
function types like: typealias Fn = (transferring X) -> ().

rdar://123118061
2024-02-19 12:11:57 -08:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Alastair Houghton
0bbb270d27 [RemoteInspection] Pass through null returns from TypeRefVisitor.
If `TypeRefVisitor<DemanglingForTypeRef, Demangle,NodePointer>::visit`
returns `nullptr`, we should pass it through.  The callers of
`TypeRef::getDemangling()` are already prepared to cope with `nullptr`
returns, so this should be fine and avoids hitting an assertion
failure in that case.

rdar://120941628
2024-01-19 10:22:02 +00:00
Augusto Noronha
e05e3ae7f0 Add interface for lookup of externally stored field descriptors
This is a follow up patch that wraps field descriptors and field records
in an abstract interface, and allows descriptor finders to look them up.
2023-11-09 12:33:34 -08:00
Augusto Noronha
f09f518abc Add interface for lookup up of externally stored type descriptors
Currently, TypeRefBuilder knows how to parse type descriptors from
reflection metadata. We aim to store the same information that lives
in type descriptors externally, as an effort to support embedded Swift
debugging. In order to take advantage of all of the existing type
information parsing code that exists today in remote mirrors, add an
interface for external lookup of type descriptors, and replace all the
usages of type descriptors with their generic counterpart (this patch
only adds support for builtin descriptors, but follow up patches will
add support for other descriptor types).
2023-11-08 15:57:05 -08:00
Augusto Noronha
260c3d9fcd [NFC] Extract descriptor finder from the rest of TypeRefBuilder
Separate the functionality that reads descriptors from reflection
information into its own class.
2023-11-04 10:52:37 -07:00
Doug Gregor
40e07cf900 [Typed throws] IR generation and runtime support for function type metadata
Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.

Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.

Introduce all of the runtime mangling/demangling support needed for
thrown error types.
2023-10-29 09:12:32 -07:00
Doug Gregor
4da1032f93 Add name mangling support for functions with a thrown error type 2023-10-29 09:12:32 -07:00
Augusto Noronha
e2fa23a49d Add a method that produces a string from a TypeRef 2023-10-23 16:10:21 -07:00
swift-ci
f4763297d3 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 07:54:35 -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
swift-ci
daeae9870d Merge remote-tracking branch 'origin/main' into rebranch 2023-09-25 21:51:57 -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
Augusto Noronha
a6be181ae5 Don't trust the external cache when looking for field descriptors
When looking for field descriptors for a typeref, we should iterate over
every image info available, even those that the cache claimed to have
processed, as a last ditch effort.

rdar://114567246
2023-09-19 13:57:58 -07:00
Ben Troller
f93f7ad849 [RemoteMirror] Speed up Remote Mirror significantly by caching two additional
calculations in TypeRefBuilder.
2023-09-05 11:04:23 -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
Slava Pestov
f303207aec RemoteMirror: Don't store StringRefs to temporary std::strings 2023-07-05 23:07:11 -04:00
Slava Pestov
338cb7ccb9 TypeDecoder: Change createTupleType() to take labels as ArrayRef<StringRef> instead of std::string 2023-07-05 16:33:43 -04:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Tim Kientzle
1898e58a40 Implement DependentMemberTypeRef support for the typeref->demangle translation
* Risk: Without this, RemoteMirror (and hence client apps) crash on certain inputs
* Resolves: rdar://108809238
* Testing:  Ran a client app with a custom-built library to verify it no longer crashes.  I've not been able to figure out how to build a unit test that hits this specific code path (in all my unit tests, dependent members seem to get fully substituted before we get to this section of code).
2023-05-02 13:44:51 -07:00
Tim Kientzle
5d67b814f5 Fix case calculation for SPE with zero-sized payload 2023-04-25 15:00:51 -07:00
Tim Kientzle
ed2e6b6e0f The number of cases stored in the payload area depends on the payload area size 2023-04-24 16:41:42 -07:00
Tim Kientzle
9bfe1b1691 Merge branch 'main' into tbkka-RemoteMirror-MPE-zero-sized-plus-generics 2023-04-24 08:22:38 -07:00
Dave Lee
af733e7905 [RemoteInspection] Specify precise return type of RecordTypeInfo (NFC) 2023-04-14 11:18:50 -06: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
Mike Ash
fbc3f69ebf [RemoteMirror] Fix demangle node corruption caused by excessively eager clearing of the NodeFactory.
We clear the NodeFactory to prevent unbounded buildup of allocated memory, but this is done too eagerly. In particular, normalizeReflectionName can end up clearing the factory while the calling code is still using nodes that were allocated from it.

To keep peak memory usage low while avoiding this problem, we introduce a checkpoint mechanism in NodeFactory. A checkpoint can be pushed and then subsequently popped. When a checkpoint is popped, only the nodes allocated since the checkpoint was pushed are invalidated and the memory reclaimed. This allows us to quickly clear short-lived nodes like those created in normalizeReflectionName, while preserving longer-lived nodes used in code calling it. Uses of clearNodeFactory are replaced with this checkpoint mechanism.

rdar://106547092
2023-03-29 16:59:21 -04:00
Mike Ash
ae926bdc7d [RemoteMirror] Fix getEmptyTypeInfo() not allocating a BuiltinTypeInfo.
Allocate an empty BuiltinTypeInfo. The code previously allocated a TypeInfo but set its kind to Builtin, which led to calling code doing an incorrect cast and reading an invalid value for the Name field.

rdar://106563125
2023-03-16 16:11:35 -04:00
Augusto Noronha
b1c763d954 Allow TypeInfoProviders to identify themselves
TypeInfoProvider's address was used as part of the key to cache type
infos. This can cause the unnecessary recomputation of type infos, as
different instances of TypeInfoProviders may provide the exact same type
infos. Allow TypeInfoProviders to provide an id which can be used for
caching purposes.

rdar://80001304
2023-03-02 21:54:10 -08:00
Tim Kientzle
283c65669f Match the earlier behavior when we lack typeinfo
for a particular payload.  This should fix a test
crash that occurred on x86_64 with CF payloads.
2023-01-06 11:16:07 -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
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00