Commit Graph

111 Commits

Author SHA1 Message Date
Dave Lee
c51e10a827 RemoteInspection: Update DefaultActorImpl layout (#80278)
The definition of `DefautlActorImpl` changed in https://github.com/swiftlang/swift/pull/73998. This change reflects those changes on to RemoteInspection's platform independent definition.
2025-03-25 15:42:46 -07:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Dave Lee
967249430b RemoteInspection: Add IsComplete flag to AsyncTaskInfo (#80183)
This will be used by lldb. I'd like to add it to swift-inspect too, but that will require figuring out how to evolve the swift runtime's ABI.

rdar://147448235
2025-03-21 13:19:40 -07:00
Konrad `ktoso` Malawski
92ead521b8 [Concurrency] Fix swift-inspect and remote mirror build (#79715) 2025-03-04 07:04:42 +09:00
Adrian Prantl
58c01bef79 [reflection] Generalize the implementation of getInstanceTypeInfo()
This is being indirectly tested by the LLDB testsuite.
2025-02-28 12:35:59 -08:00
Adrian Prantl
30defa2569 Add an accessor for LLDB (NFC) 2025-01-31 14:51:23 -08:00
Saleem Abdulrasool
d4c2e1cedb Basic: fix a small corner case for ODR violations
When building the runtime we define `SWIFT_RUNTIME`. `swiftCore_EXPORTS`
is only defined when building swiftCore as a shared library. This would
thus allow the ODR violations to appear in a static library form of the
standard library. This was uncovered with the new runtime build system.
2025-01-17 10:41:07 -08:00
Dave Lee
3e05e0bbf4 RemoteInspection: Append ResumeAsyncContext field to AsyncTaskInfo (#78645)
Expose a `Task`'s resume context via the `AsyncTaskInfo` struct.

This will be used by lldb, but since this data is not specific to lldb it seems reasonable to include it generally.
2025-01-15 11:41:41 -08: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
Alejandro Alonso
82743d7427 Add TypeDecoding for Builtin.FixedArray 2024-10-28 17:29:03 -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
Dave Lee
b8f1876d0d RemoteInspection: Handle ObjC typerefs in computeUnalignedFieldStartOffset (#76678)
This change is part of a fix for a regression that wasn't noticed because lldb has a 
fallback to using ASTContexts when type metadata resolution fails.

For any Swift class that directly or indirectly inherits from an ObjC class (such as 
`NSObject`, `NSView`, etc), the function `computeUnalignedFieldStartOffset` will fail 
to compute the start offset. To compute the start offset, it traverses the parent 
classes and uses their sizes. Once the traversal reaches an ObjC class, the 
RemoteInspection does not know the size. The fix here is to get the size from the 
`TypeInfo` returned by the external `TypeInfoProvider` (which in LLDB is 
`LLDBTypeInforProvider`).

Depended on by https://github.com/swiftlang/llvm-project/pull/9320
2024-09-27 11:12:06 -07:00
Alejandro Alonso
c1dd957c75 Use intptr_t more consistently 2024-09-04 15:13:50 -07:00
Alejandro Alonso
71f1bb3760 Fix compile error in TypeRefBuilder 2024-09-04 15:13:28 -07:00
Alejandro Alonso
7c85261a77 Add runtime support 2024-09-04 15:13:27 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -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
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
9a34c68746 Merge pull request #74716 from tbkka/tbkka-mpe-descriptor-deorbit
Do not require overriding this method
2024-07-10 14:22:29 -07:00
Erik Eckstein
7fe2befd31 Demangler: handle errors in demangleType
Makes sure that invalid runtime type strings result in errors and not fail silently.
In worst case this could lead to wrong reconstructed metatypes which can result in all kind of memory corruption.

relates to rdar://129861211
2024-07-05 11:37:15 +02:00
Tim Kientzle
da5d639eb2 Do not require overriding this method
I'm working to fully remove this method, but because it's
used and/or implemented in a few places, I'm backing it out
incrementally. This just changes the abstract method so I can
delete the implementors in a subsequent PR without breaking
anything.
2024-06-25 15:21:24 -07:00
Tim Kientzle
05c74e0d90 Revert "Merge pull request #74394 from tbkka/tbkka-remotemirror-no-more-mpe-metadata-partial"
This reverts commit a1708ef8b1, reversing
changes made to b5930625be.
2024-06-14 15:32:39 -07:00
Tim Kientzle
c20ef6de2a Remove RemoteInspection code to fetch no-longer-used reflection metadata
without relying on spare bit information in the reflection metadata
(which was added in #40906).  As a result, we can remove the
code from #40906.

This is the first step in such removal.  It removes the RemoteMirror
code for looking up such metadata.  It leaves behind:

* Sufficient stubs for LLDB to continue to build.  Once LLDB is updated, these stubs can be removed as well.

* The compiler code to emit such metadata.  This allows new binaries to still reflect MPEs on older runtimes.  This will need to be kept for a transitional period.
2024-06-13 09:34:43 -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
Augusto Noronha
dd39730d74 Merge pull request #73723 from augusto2112/default-actor-ti-main
[RemoteInspection] Hardcode DefaultActorStorage's type info
2024-05-22 11:14:47 -07:00
Michael Gottesman
d759ec97ea Merge pull request #73696 from gottesmm/rdar128216574
[sending] Add support for 'sending'
2024-05-18 05:42:41 -04:00
Augusto Noronha
4417786be4 [RemoteInspection] Hardcode DefaultActorStorage's type info
No metadata is emitted for the builtin DefaultActorStorage type. Since
its layout is fixed, hardcode its definition in Remote Mirrors.

rdar://128032250
2024-05-17 14:29:25 -07:00
Michael Gottesman
e3e78ad6bb [sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new
'sending' syntax by first validating that this internal change does not mess up
the current transferring impl since we want both to keep working for now.

rdar://128216574
2024-05-16 12:20:45 -07:00
Augusto Noronha
03b422b810 [RemoteInspection] Add TypeInfoProvider to ReflectionContext function
Pass in a TypeInfoProvider parameter to computeUnalignedFieldStartOffset
because it calls getClassInstanceTypeInfo which might need the external
type info provider to find clang types.

rdar://128141491
2024-05-15 14:43:45 -07:00
Tim Kientzle
03ea6a1225 Merge pull request #73491 from tbkka/tbkka-mpe-sparebits
Calculate spare bits for multi-payload enums from first principles
2024-05-10 13:15:07 -07:00
Tim Kientzle
febc128330 Whitespace 2024-05-07 14:21:16 -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
e546684e9a Extract the BitMask support to a separate file 2024-04-29 16:50:58 -07:00
Alastair Houghton
f5b1ef77a6 [RemoteInspection] Change "return false" to "return {}".
There are a number of instances in `ReflectionContext.h` where we
are doing `return false` with an `std::optional<...>` where it seems
we really mean to return an empty optional instead.

(The way to do this is either `return {}` or `return std::nullopt`.)

rdar://123504095
2024-04-29 10:48:23 +01:00
Alastair Houghton
bc64f6df9f [RemoteInspection] Add a big comment to ReflectionContext.h.
Add a comment to ReflectionContext.h explaining the situation regarding
`SHF_GNU_RETAIN` and the reflection metadata sections.

rdar://123504095
2024-04-29 10:48:22 +01:00
Alastair Houghton
cb4fd88ece [RemoteInspection] Use bool instead of !!.
Since this is adjacent to a `!=` operator, explicitly using `bool` seems clearer.

Co-authored-by: Evan Wilde <etceterawilde@gmail.com>
2024-04-29 10:48:22 +01:00
Alastair Houghton
c9dcee2774 [RemoteInspection] Update ReflectionContext to cope with multiple sections.
When linking with `gold`, we can end up with two separate sections
for each of the reflection sections; this happens because `swiftrt.o`
declares them with `SHF_GNU_RETAIN` set (to stop them from vanishing
when section GC is enabled), but if the compiler is set to allow the
reflection information to be stripped then *it* will generate them
*without* `SHF_GNU_RETAIN`.

The other Linux linkers will coalesce the two sections and leave the
`SHF_GNU_RETAIN` flag set, but `gold` does not, and adds both of them
separately to the output.

The upshot is that we want `ReflectionContext` to look for both the
retained and non-retained sections and read the data from both of
them.

rdar://123504095
2024-04-29 10:48:22 +01:00
Mike Ash
545441e2d1 [RemoteInspection] Ignore MetadataSource records with NULL source pointer.
We'd crash on a call to getKind(). Ignore them instead by returning false from isMetadataSourceReady. If this causes getClosureContextInfo to fail to make forward progress, then it will in turn fail and return nullptr to its caller.

rdar://126866747
2024-04-23 12:02:38 -04:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Anton Korobeynikov
c7a216058f [AutoDiff] First cut of coroutines differentiation (#71461)
This PR implements first set of changes required to support autodiff for coroutines. It mostly targeted to `_modify` accessors in standard library (and beyond), but overall implementation is quite generic.

There are some specifics of implementation and known limitations:
 - Only `@yield_once` coroutines are naturally supported
 - VJP is a coroutine itself: it yields the results *and* returns a pullback closure as a normal return. This allows us to capture values produced in resume part of a coroutine (this is required for defers and other cleanups / commits)
 - Pullback is a coroutine, we assume that coroutine cannot abort and therefore we execute the original coroutine in reverse from return via yield and then back to the entry
 - It seems there is no semantically sane way to support `_read` coroutines (as we will need to "accept" adjoints via yields), therefore only coroutines with inout yields are supported (`_modify` accessors). Pullbacks of such coroutines take adjoint buffer as input argument, yield this buffer (to accumulate adjoint values in the caller) and finally return the adjoints indirectly.
 - Coroutines (as opposed to normal functions) are not first-class values: there is no AST type for them, one cannot e.g. store them into tuples, etc. So, everywhere where AST type is required, we have to hack around.
 - As there is no AST type for coroutines, there is no way one could register custom derivative for coroutines. So far only compiler-produced derivatives are supported
 - There are lots of common things wrt normal function apply's, but still there are subtle but important differences. I tried to organize the code to enable code reuse, still it was not always possible, so some code duplication could be seen
 - The order of how pullback closures are produced in VJP is a bit different: for normal apply's VJP produces both value and pullback closure via a single nested VJP apply. This is not so anymore with coroutine VJP's: yielded values are produced at `begin_apply` site and pullback closure is available only from `end_apply`, so we need to track the order in which pullbacks are produced (and arrange consumption of the values accordingly – effectively delay them)
 - On the way some complementary changes were required in e.g. mangler / demangler

This patch covers the generation of derivatives up to SIL level, however, it is not enough as codegen of `partial_apply` of a coroutine is completely broken. The fix for this will be submitted separately as it is not directly autodiff-related.

---------

Co-authored-by: Andrew Savonichev <andrew.savonichev@gmail.com>
Co-authored-by: Richard Wei <rxwei@apple.com>
2024-04-04 17:24:55 -07:00
Doug Gregor
735e28b551 Merge pull request #72336 from DougGregor/demangle-inverse-requirements-to-ast
Demangle inverse requirements when building AST types
2024-03-14 17:30:49 -07:00
Doug Gregor
a2ae2149e8 Demangle inverse requirements when building AST types
Extend TypeDecoder with support for inverse requirements, passing them
along to the type builder. Then implement support for inverse
requirements within the AST demangler, which addresses the round-trip
demangling failures we've been seeing.

The runtime and remote inspection facilities still need metadata to
deal with inverse requirements.

Fixes rdar://124564447.
2024-03-14 14:01:53 -07:00
Erik Eckstein
3c76464c1c rename withConcurrent -> withSendable
That was missed when "concurrent" was renamed to "sendable"
2024-03-13 09:58:31 +01:00
Konrad `ktoso` Malawski
1d44e2e8e0 [Distributed] Undo new record and mangling scheme for dist.p.witnesses (#71801) 2024-02-22 23:02:29 +09: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
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