Commit Graph

105 Commits

Author SHA1 Message Date
Augusto Noronha 0d82d03e93 [RemoteInspection] Fix generic typealiases in DemanglingForTypeRef
When a typealias or associated type is declared inside a protocol, the
mangling of an access like S.A (for `typealias A` in `protocol P` and
`struct S : P`) wraps the protocol in a BoundGenericProtocol whose
single generic argument is the conforming Self type:

  BoundGenericProtocol
  |
  --> Protocol: P
  |
  --> TypeList:
      |
      --> Structure: S

DemanglingForTypeRef was substituting the richer parent wholesale in
place of the Protocol, losing the BoundGenericProtocol entirely and
producing a mangled tree that looks as if A were declared directly
on S rather than inside P.

Assisted-by: claude

rdar://160408523
2026-05-15 07:30:07 -07:00
Mike Ash 23fac72075 Merge pull request #88933 from mikeash/remote-mirror-inline-array
[Reflection] Support inspection of InlineArray.
2026-05-14 19:53:11 -04:00
Augusto Noronha e5873e820b [RemoteInspection] Fix handling of extensions in DemanglingForTypeRef
Typically, the first node of a nested type is the type that contains it.
For example:

```
Demangling for $s7ModBase5OuterV5InnerC
kind=Global
  kind=Class
    kind=Structure
      kind=Module, text="ModBase"
      kind=Identifier, text="Outer"
    kind=Identifier, text="Inner"
$s7ModBase5OuterV5InnerC ---> ModBase.Outer.Inner
```

However, when a type is declared inside an extension of "Outer", that
becomes part of the mangled name too. For example:

```
Demangling for $s7ModBase5OuterV6ModExtE5InnerC
kind=Global
  kind=Class
    kind=Extension
      kind=Module, text="ModExt"
      kind=Structure
        kind=Module, text="ModBase"
        kind=Identifier, text="Outer"
    kind=Identifier, text="Inner"
$s7ModBase5OuterV6ModExtE5InnerC ---> (extension in ModExt):ModBase.Outer.Inner
````

DemanglingForTypeRef did not treat the extension case correctly, and was
losing the extension information. This patch fixes it.

Assisted-by: claude

rdar://176586425
2026-05-13 11:06:13 -07:00
Augusto Noronha cd4e937294 [RemoteInspection] Handle lowering existential constrained metatype
RemoteInspection was failing to produce type info for metatypes of
constrained existentials (any SomeType<ConstraintHere>.Type)

A constrained existential has the same layout as a regular protocol
composition, so we can use that instead.

rdar://176586637
2026-05-08 17:58:03 -07:00
Mike Ash 2bcfe0b092 [Reflection] Support inspection of InlineArray.
Report the array count as NumFields, and report the same info for each child since InlineArray is homogeneous.

rdar://176382725
2026-05-07 14:39:05 -04:00
Augusto Noronha c0da3a8e8a Merge pull request #88770 from augusto2112/fix-unamanged-pointer
[RemoteInspection] Fix rebuildStorageTypeInfo for unmanaged types
2026-05-04 20:04:55 -07:00
Augusto Noronha 32e8e96979 [RemoteInspection] Treat ObjC class metatypes as thick
Also adds a reflection test covering an ObjC class metatype stored as a
struct field.

assisted-by: claude

rdar://175382517
2026-04-30 17:01:37 -07:00
Augusto Noronha 5f36f9e71a [RemoteInspection] Fix rebuildStorageTypeInfo for unmanaged types
rebuildStorageTypeInfo only handled ReferenceTypeInfo and
RecordKind::ClassExistential inner types for unmanaged_storage, but
failed for imported unmanaged types which are imported behind a
pointer (which is a struct).

rdar://175379963
2026-04-30 14:45:33 -07:00
Konrad Malawski a6617f8801 rename isNonisolatedNonsendingCaller -> isNonisolatedNonsending 2026-04-28 09:21:46 -07:00
Konrad Malawski 2b8026dd94 rename isNonIsolatedCaller -> isNonisolatedNonsendingCaller 2026-04-28 09:21:46 -07:00
Augusto Noronha 7590ecc0fa [RemoteInspection] Store the payload TypeRef of indirect enum payloads
EnumTypeInfoBuilder will build FieldInfos of indirect enum payloads with
the TypeRef set to Builtin.NativeObject.

EnumTypeInfoBuilder has access to the typeref of the type behind the
pointer, which currently isn't saved anywhere.

RemoteInspection clients like LLDB have to re-query it, and read
metadata to find out what the type behind the reference it.

This patch adds a field to FieldInfo with the payload TypeRef, the
one behind the reference.

rdar://170684760
2026-02-26 12:04:53 -08:00
Joe Groff ce605004f2 Reflection: Support for Builtin.Borrow.
Plumb the `BitwiseBorrowable` and `AddressableForDependencies` layout
properties through reflection TypeLowering, and implement type layout
for `Builtin.Borrow` based on those properties.
2026-02-13 10:03:48 -08:00
Joe Groff bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Augusto Noronha 52c8b7975a [NFC][RemoteInspection] Use existing cache to build conformance table
There is an existing cache which is built when looking up
FieldDescriptors. collectAllConformances ignored this cache and would
parse every FieldDescriptor again. Use the existing cache mechanism.

rdar://166098516
2025-12-08 16:34:45 -08:00
Adrian Prantl 90f4b4fc8e [LLDB] Replace more instances of the DEBUG_LOG macro with setError
This allows LLDB to query the last error and produce more helpful
diagnostics. This is NFC for the runtime.
2025-12-02 16:32:02 -08:00
Mike Ash 513f5fb17a [swift-inspect] Add a mode to search for and dump generic metadata without metadata iteration enabled.
We scan the target's initial allocation pool, and all 16kB heap allocations. We check each pointer-aligned offset within those areas, and try to read it as Swift metadata and get a name from it. If that fails, quietly move on. It's very unlikely for some random memory to look enough like Swift metadata for this to produce a name, so this works very well to print the generic metadata instantiated in the remote process without requiring `SWIFT_DEBUG_ENABLE_METADATA_ALLOCATION_ITERATION`.

rdar://161120936
2025-09-26 10:52:35 -04:00
Adrian Prantl eabcf41a54 Implement reflection support for Symbolic Extended Existential types.
This patch adds a new SymbolicExtendedExistentialTypeRef kind, and
wires it up in TypeDecoder, TypeRefBuilder, TypeLowering, and
ASTDemangler.

This is tested indirectly via the matching LLDB commit.
2025-08-04 08:36:37 -07:00
Augusto Noronha c97dfd6b05 [RemoteAddress] Handle comparison of addresses in different spaces
Sometimes it makes sense to compares addresses from different address
spaces.

rdar://148361743
2025-07-11 10:05:16 -07:00
Augusto Noronha 58df5534d2 [NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
Add an extra opaque field to AddressSpace, which can be used by clients
of RemoteInspection to distinguish between different address spaces.

LLDB employs an optimization where it reads memory from files instead of
the running process whenever it can to speed up memory reads (these can
be slow when debugging something over a network). To do this, it needs
to keep track whether an address originated from a process or a file. It
currently distinguishes addresses by setting an unused high bit on the
address, but because of pointer authentication this is not a reliable
solution. In order to keep this optimization working, this patch adds an
extra opaque AddressSpace field to RemoteAddress, which LLDB can use on
its own implementation of MemoryReader to distinguish between addresses.

This patch is NFC for the other RemoteInspection clients, as it adds
extra information to RemoteAddress, which is entirely optional and if
unused should not change the behavior of the library.

Although this patch is quite big the changes are largely mechanical,
replacing threading StoredPointer with RemoteAddress.

rdar://148361743
2025-07-09 14:52:42 -07:00
Adrian Prantl 45198dc0ee [reflection] Fine-tune error messages 2025-06-18 16:29:39 -07:00
Adrian Prantl 868c9912aa [Reflection] Add lightweight error handling to ReflectionContext
Reflection metadata lookup failures are notoriously difficult to debug
because there is no error handling in TypeLowering outside of
compile-time #ifdef'd fprintf(stderr) calls. The nicest thing to do
would be to adopt llvm::Expected<> but TypeLowering is also included
in the standard library, which only has access to a tiny subset of the
LLVM Support library. This patch adds a place to store a pointer to
the first encountered error, which can then be converted to an
llvm::Error at the API level.
2025-06-17 09:47:11 -07:00
Slava Pestov 70b413dc56 RemoteInspection: Support for parameter packs 2025-05-09 14:49:37 -04:00
Slava Pestov c205c802f6 RemoteInspection: Remove 'DidSubstitute' form of TypeRef::subst() 2025-05-05 14:59:45 -04:00
Slava Pestov 31947d0617 RemoteInspection: Fix latent bug in TypeRefIsConcrete::visitOpaqueArchetypeTypeRef() 2025-05-05 14:59:45 -04:00
Pavel Yaskevich 1067ead82c [Mangling] Mangle presence of @execution(caller) in a function type
If `@execution(caller)` attribute is present on a function type,
mark its presence in the mangling with `YC` suffix.
2025-02-19 16:48:41 -08:00
Tim Kientzle 674c76274e Merge pull request #77062 from tbkka/tbkka-remotemirror-133890406
Let indirect enum cases export spare bits
2025-01-24 19:52:59 -08:00
Alejandro Alonso 09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
John McCall fa932e736c Fix the demangling of sending result types when combined with isolation
Fixes the immediate problem, but the presence of demangling code in the
runtime means that we'll need a follow-up to fix the compiler so that it
doesn't try to use the demangler to materialize metadata for function types
that have both isolation and a sending result.

rdar://142443925
2025-01-10 21:11:45 -05:00
Alejandro Alonso cedea94b4c Test fixes and review feedback 2025-01-09 15:54:54 -08:00
Alejandro Alonso c62e851e38 Implement RemoteInspection support for Builtin.FixedArray 2025-01-08 10:37:17 -08:00
Kuba Mracek 9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Tim Kientzle 689ffbe28b A separate "indirect case" counter didn't properly distinguish generic indirect vs. non-generic indirect.
Counting indirect cases as regular non-empty cases is a better fit.
2024-10-17 08:49:08 -07:00
Tim Kientzle fe90ad5684 Let indirect enum cases export spare bits
To determine the correct enum layout, we first count various
categories of cases.  Before, we counted indirect generic cases as
"generic", but regular "generic" cases can't export spare bits.

Change this to count "indirect" cases as a separate category.
In particular, this ensures that fully-indirect enums use
spare bits from the pointers even when some or all of the cases
are generic.

Resolves rdar://133890406
2024-10-16 18:31:28 -07:00
Tim Kientzle cfc7b2ef2e Use SWIFT_FALLTHROUGH 2024-10-16 17:02:47 -07:00
Tim Kientzle 502941ca5a More arcana about MPEs carrying class existentials
The first word in a class existential is the class pointer itself.
This pointer exposes spare bits differently depending
on the platform, which becomes apparent when you try to reflect
an Optional carrying such an MPE.

Add new test cases and some logic to zero out the first
word of spare bit information only on platforms with 8-byte pointers.
2024-10-16 16:06:37 -07:00
Tim Kientzle a105cf5323 Fix multi-payload enums with Class Existential payloads on 32-bit targets
Class existentials expose spare bits from all of the pointers, not just the first one.
Due to a bad bug here, we were properly exposing spare bits from the first pointer,
but then claiming that all bits of subsequent pointers were spare.
This accidentally resulted in the correct operation on 64-bit targets
(it picked the highest-order spare bit, which happened to be spare
in both the broken mask and the correct mask).  But on 32-bit targets,
this exposed the high-order bits of pointers, which is incorrect.

Expand the test a bit while we're here as well.

Resolves rdar://132715829
2024-10-15 09:28:01 -07:00
Ben Troller 5c032d91d0 Merge pull request #75993 from btroller/btroller-134364958-optimize-brute-force-search-in-readTypeRef
[RemoteMirror] Optmize brute-force search in TypeRefBuilder::ReflectionTypeDescriptorFinder::readTypeRef().
2024-10-11 11:08:51 -07:00
Tim Kientzle da5383c4c3 Better support CoreFoundation types in RemoteMirror
This plugs a hole where we failed to recognize a CF type when it
appeared as the payload of an enum stored as a property.  Curiously,
RemoteMirror is able to reflect this when the enum appears by itself,
just not when it's stored as a property.

The simplest fix is to hook into the TypeInfo calculation which
computes a TypeInfo (basically, the tree of fields) from a TypeRef
(basically, the name of the type, including generic context).
Specifically, we sometimes end up here with a "type alias" that
none of the lookup support seems to be able to handle.  Fortunately,
these aliases demangle into a pretty predictable shape, so this
just pattern-matches the specific demangle tree shape to recognize
these as "type aliases in the `__C` module whose name starts with `CF`
and ends with `Ref`".

Resolves rdar://82465109
2024-09-19 13:50:41 -07:00
Ben Troller 666178fb0f [RemoteMirror] Optimize brute-force search in getCaptureDescriptor() 2024-08-20 17:54:28 -07:00
Ben Troller 6b23b07f56 [RemoteMirror] Optmiize brute-force search in readTypeRef() 2024-08-20 14:19:23 -07:00
Tim Kientzle 9debfbc08c Merge pull request #75607 from tbkka/tbkka-remotemirror-unsafecontinuation
[RemoteMirror] Handle UnsafeContinuation
2024-08-01 13:46:09 -07:00
Tim Kientzle 4bad739ad4 Remove FIXME since this is actually right! 2024-08-01 07:27:43 -07:00
Tim Kientzle 9e1dcd6c9f [RemoteMirror] Handle UnsafeContinuation
UnsafeContinuations can be stored in variables or properties,
so it's important for RemoteMirror to be able to at least minimally
recognize them.

This just treats an UnsafeContinuation as a refcounted pointer.
Which might be "good enough" for now.

Working towards rdar://110351406
2024-07-31 18:15:27 -07:00
Tim Kientzle 039e78d31a [RemoteMirror] Fix generic depth calculation
The "generic depth" is used to match up generic type variables.
For example:
```
struct Foo<T> { // `T` at generic depth 0
  struct Bar {
    struct Baz<U> { // 'U' at generic depth 1
      ...
}}}
```

Note in the above that `Bar` is not counted in the
generic depth.  The previous logic did count `Bar` in
the generic depth calculation, leading to mismatches
when trying to associate references to generic variables.

This adds a new test with cases like the above and of course
corrects the calculation.

Resolves rdar://127450037
2024-07-31 07:08:08 -07:00
Tim Kientzle 3ffc3e8444 Use TC.targetPointerSize() for the pointer size 2024-07-24 16:23:17 -07:00
Tim Kientzle 706b0b0ed1 Whitespace changes to better match clang-format style 2024-07-24 09:08:51 -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
Alexander Cyon c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02:00
Michael Gottesman 34195ff213 Merge pull request #74610 from gottesmm/pr-324fd70c13e87a329334341aae4667f2d1be152c
[sending] Remove transferring.
2024-07-02 14:02:18 -07:00
Ben Barham d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00