Commit Graph

81 Commits

Author SHA1 Message Date
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
Michael Gottesman
112071e57d [sending] Remove transferring.
Out of an abundance of caution, we:

1. Left in parsing support for transferring but internally made it rely on the
internals of sending.

2. Added a warning to tell people that transferring was going to
be removed very soon.

Now that we have given people some time, remove support for parsing
transferring.

rdar://130253724
2024-06-21 16:03:21 -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
3895908c67 Sanity: Don't spend too much time (or memory) on rediculously large enums
RemoteMirror gets called on lots of malformed type information,
due to memory corruption bugs or even clients that ask RemoteMirror
to decode a chunk of memory to test whether or not it might be
valid type data.  In any case, we need to be a little cautious here.

In this case, I've chosen to ignore any enum whose in-memory size
(according to the metadata) is over 1 MiB.  We can easily adjust
this limit up if experience shows there really are legitimate enums
this large in the wild.
2024-06-05 16:00:05 -07:00
Tim Kientzle
346d5b22c4 Correct handling of nonsensical Int types
If an Int type makes no sense (it has a nonsensical number
of extra inhabitants, for example), ignore it rather than
treating it as a non-Int type.

Rename `isIntType()` to `intTypeBitSize()` to better document
what this function actually returns.
2024-06-05 14:58:46 -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
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
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
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
Dave Lee
d7426e2e75 [RemoteInspection] Fix format of dumped spare bit mask (#73231)
Even with `std::hex`, the `uint8_t` values are being printed as characters, not hex 
values. This change casts the value to `int`, which results in the hex representation 
being properly printed.
2024-04-25 09:51:22 -07:00
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07:00
Ben Barham
cbcfc85777 Merge pull request #72323 from bnbarham/rename-startswith
Rename startswith to starts_with
2024-03-14 09:06:54 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Tim Kientzle
afb75e631f Fix off-by-one error in maskForCount, comment more carefully 2024-03-13 10:35:35 -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
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