Commit Graph

132 Commits

Author SHA1 Message Date
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
Konrad `ktoso` Malawski
e9c7f3c382 [Distributed] Target identifiers for protocol calls (#70928) 2024-02-16 07:19:20 -08:00
Adrian Prantl
09da198c93 Add ExternalTypeInfoProvider the the key of the ReflectionContext TypeInfo cache
This change is analogous to the TypeInfo cache in TypeLowering, which does the
exact same thing. In LLDB the ExternalTypeInfoProvider may gain new information
throughout the life of a process, and more importantly, it may return
context-dependent results.

rdar://122432501
2024-02-09 17:24:04 -08:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Augusto Noronha
e2d516f3c9 Merge pull request #71328 from augusto2112/instance-start-typeref
Implement ReflectionContext::readInstanceStartFromTypeRef
2024-02-02 18:31:05 -08:00
Augusto Noronha
18a80f8941 Implement computeUnalignedFieldStartOffset
Implement computeUnalignedFieldStartOffset as an alternative way to
finding out the start of the fields that belong to the instance when
reading the field's start from binary is not possible (for example,
embedded Swift doesn't emit any reflection metadata on the binary).
2024-02-02 15:38:58 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Mike Ash
4bc7726d43 Merge pull request #70900 from mikeash/swift-generic-metadata-builder-out-of-process
[Tools] Add a library to build specialized generic metadata out of process.
2024-01-26 10:50:34 -05:00
John McCall
b0fb03d8c7 Create a uniform representation for function type isolation.
Not quite NFC because apparently the representation bleeds into what's
accepted in some situations where we're supposed to be warning about
conflicts and then making an arbitrary choice.  But what we're doing
is nonsense, so we definitely need to break behavior here.

This is setting up for isolated(any) and isolated(caller).  I tried
to keep that out of the patch as much as possible, though.
2024-01-25 22:11:01 -05:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Mike Ash
4341102c92 [Tools] Add a library to build specialized generic metadata out of process.
This library uses GenericMetadataBuilder with a ReaderWriter that can read data and resolve pointers from MachO files, and emit a JSON representation of a dylib containing the built metadata.

We use LLVM's binary file readers to parse the MachO files and resolve fixups so we can follow pointers. This code is somewhat MachO specific, but could be generalized to other formats that LLVM supports.

rdar://116592577
2024-01-24 20:45:50 -05:00
Tony Allevato
0eb0aed6be [C++20] Two very minor C++20 fixes.
- Remove `std::` from `std::size_t` where we're importing `stddef.h`
  instead of `cstddef`.
- Add an inclusion of `<cstdlib>` where needed because libc++ has
  cleaned up some of their transitive inclusions.
2023-12-08 09:13:39 -05: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
9f33d3e242 Merge pull request #69556 from augusto2112/builtin-interface
Add interface for lookup up of externally stored type descriptors
2023-11-09 08:43:53 -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
b677767715 [NFC] Prepend "StringRef" with "llvm" namespace in Records.h
Records.h relies on the includer to use the llvm namespace. Some
includers might not want include it, so use the full llvm::StringRef
name.
2023-11-07 11:11:03 -08:00
Augusto Noronha
6663dc0e89 [NFC] Rename DF -> RDF 2023-11-04 10:58:32 -07:00
Augusto Noronha
c2d73fd6a3 [NFC] clang-format TypeRefBuilder.h 2023-11-04 10:55:03 -07: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
Emre Celebi
2b594b20db Merge pull request #69488 from w6sec/mangled
[swift-inspect]  Add an option to print mangled names while dumping generic metadata.
2023-10-31 18:39:26 -07:00
Emre Celebi
b6f77a46be [swift-inspect] Add an option to print mangled names while dumping generic metadata. 2023-10-30 23:39:42 -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
Mike Ash
9f76c1977d Merge pull request #68938 from mikeash/reflectioncontext-data-auth-segments
[Reflection] Look for __AUTH segments as well as __DATA segments.
2023-10-04 10:46:47 -04:00
swift-ci
6cf1f90e79 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 04:35:13 -07:00
Tony Allevato
5f5b24f96e [C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator
with its arguments reversed to ease commutativity. This reversed
version is ambiguous with the hand-written operator when the
argument is const but `this` isn't.
2023-10-03 17:10:57 -04:00
Mike Ash
238d1cdc6c [Reflection] Look for __AUTH segments as well as __DATA segments.
Some data is stored in __AUTH, which we need to add to our list of data segments so that `ownsAddress` works correctly.

rdar://116363531
2023-10-03 12:54:08 -04:00
swift-ci
01085510f0 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-22 16:42:20 -07:00
Slava Pestov
57b702be07 ASTDemangler: Fix round-tripping of SILBoxTypeWithLayout
The more awkward setup with pushGenericParams()/popGenericParams()
is required so that when demangling requirements and field types
we get the correct pack-ness for each type parameter. The pack-ness
is encoded as part of the generic signature, and not as part of
the type parameter mangling itself.

Fixes the ASTDemangler issue from rdar://problem/115459973.
2023-09-22 11:27:18 -04:00