Commit Graph

672 Commits

Author SHA1 Message Date
Fred Riss e3ae0756a1 Fix use-after-free in Demangler caused by Words[] not saved across nested demangle calls
DemangleInitRAII saves and restores NumWords but not the Words[] array
itself. When a nested demangleSymbol/demangleType call processes
identifiers, it overwrites Words[] entries with StringRefs pointing
into its own Text buffer. After ~DemangleInitRAII restores the outer
NumWords, those entries still reference the inner (now-destroyed)
buffer. The outer demangling then hits a word substitution and reads
freed memory through the stale StringRef.

In practice this is triggered by MetadataReader::demangle(): the
symbolic reference resolver calls buildContextManglingForSymbol which
calls dem.demangleSymbol() on the same Demangler. The inner symbol's
identifiers overwrite Words[] with pointers into the
ParentContextDescriptorRef's temporary string. When the resolver
returns and the PCCDR is destroyed, the outer demangleType accesses
dangling Words[] entries via word substitution identifiers.

The fix adds Words[] to DemangleInitRAII's saved/restored state.

rdar://172223904

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 10:34:00 -07:00
Pavel Yaskevich 5b6a29fd8a [Frontend] Use @caller_isolated to represent nonisolated(nonsending) isolation of SIL function type
`nonisolated(nonsending)` is a modifier and it's really hard to
work with in SIL because most of the things are represented as
attributes there.
2026-04-13 14:18:53 -07:00
Pavel Yaskevich aa59c1aaf3 [Mangling/SIL] Mangling support for nonisolated(nonsending) isolation in SIL function types 2026-04-10 09:35:30 -07:00
Saleem Abdulrasool d1f6a09135 Demangling,Runtime: rename source files (NFC)
This just renames two `Errors.cpp` to different names to accomodate the
compaction of `libDemangling` into `swiftCoreRuntime`. This is important
as when statically linked we end up with two members with the same name
which produces a linker issue:
```
libswiftCore.lib(Errors.cpp.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
```
2026-02-11 14:14:31 -08:00
Mike Ash 3dce226714 Merge pull request #87052 from mikeash/checked-objc-async-completion-name-collision-fix
[Concurrency] Emit a distinct mangling for checked ObjC async completion handlers.
2026-02-11 10:40:53 -05:00
Kavon Farvardin d49ebd5a58 Merge pull request #87066 from kavon/supp-assoc-interfaces
SuppressedAssociatedTypesWithDefaults: swiftinterface and mangling support
2026-02-10 03:04:16 -08:00
Kavon Farvardin bc44d42f11 Demangler: inverse assoc type demangling
The spec is already in Mangling.rst
and most of the support was already
in place from 757ebe2979.
2026-02-09 16:09:59 -08:00
Mike Ash 2abf087e71 [Concurrency] Emit a distinct mangling for checked ObjC async completion handlers.
This avoids coalescing checked and unchecked handlers with the same types, which results in runtime crashes as they are not compatible.

We have a separate mangling for predefined handlers, TZ, which is unused. Repurpose this for checked handlers. Unchecked handlers keep their existing mangling with Tz.

rdar://152263818
2026-02-06 17:45:43 -05:00
Hamish Knight abd29f6478 Merge pull request #86982 from hamishknight/prop-rec
[Sema] Correctly handle properties in nested macros
2026-02-05 11:13:02 +00:00
Hamish Knight 4542ea9904 [Remangler] Fix remangling of peer macro expansions
There may be 3 or 4 children here dependending on whether the peer
expansion is being used as the context for another macro expansion,
make sure the discriminator in these cases always comes after the
operator. No test case as it's covered by the next commit.
2026-02-04 15:25:31 +00:00
Hamish Knight 63aeaba436 [Remangler] NFC: Factor out mangleAttachedMacro 2026-02-04 15:25:31 +00:00
Kavon Farvardin ed65f8bb55 Mangling: support Self in associated conformance descriptor
For reparenting, we rely on a default associated conformance witness accessor
to build the witness table for 'Self: NewParent' at runtime. This means that
when mangling the symbol for such a descriptor, we need support for there
being no associated type at all; it's just tau_0_0 aka Self as the subject.

This patch extends _default_ associated conformance witness accessor mangling
to support a GenericTypeParamType for the subject, as the non-default accessors
already quietly did have support; see `mangleAssociatedConformanceDescriptor`.
It was quiet in the sense that there was no demangling support for it, nor
documentation about it either. So I've brought both kinds of witness accessor
manglings up-to-par, without extending the `assoc-type-name` grammar itself.
2026-02-03 16:39:19 -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
Tim Kientzle 8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Erik Eckstein 4c09fa6805 Mangling: add a specialization mangling for changing the function type representation of a function 2025-11-26 16:23:47 +01:00
Meghana Gupta 25f0e2f934 [NFC] Replace @guaranteed_addr by @guaranteed_address 2025-10-20 09:05:37 -07:00
Meghana Gupta 06eb315612 Update mangling for borrow and mutate accessors 2025-10-20 09:05:36 -07:00
Michael Gottesman 2fa3908e94 [concurrency] Add a new type Builtin.ImplicitActor.
This is currently not wired up to anything. I am going to wire it up in
subsequent commits.

The reason why we are introducing this new Builtin type is to represent that we
are going to start stealing bits from the protocol witness table pointer of the
Optional<any Actor> that this type is bitwise compatible with. The type will
ensure that this value is only used in places where we know that it will be
properly masked out giving us certainty that this value will not be used in any
manner without it first being bit cleared and transformed back to Optional<any
Actor>.
2025-10-16 10:51:13 -07:00
Erik Eckstein 89bba668e2 Mangling: add a closure specialization mangling for arguments which specialize for the same closure as a previous argument
For example:
```
  %1 = partial_apply %closure
  apply %f(%1, %1)    // first argument: `.closure(%1)`
                      // second argument: `.previousArgumentIndex(0)`
```
2025-10-06 09:47:41 +02:00
swift-ci 0d2c4ca9be Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 10:29:21 -07:00
Meghana Gupta 28c4595735 Add mangling support for borrow/mutate accessors 2025-09-09 14:30:34 -07:00
Anthony Latsis e1450e011e Manually merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
*	utils/build_swift/build_swift/defaults.py
2025-09-04 14:07:50 +01:00
Erik Eckstein 1a4bd76f95 Mangling: add specialization mangling for more complex constant propagated function arguments
So far, constant propagated arguments could only be builtin literals.
Now we support arbitrary structs (with constant arguments), e.g. `Int`.
This requires a small addition in the mangling scheme for function specializations.
Also, the de-mangling tree now looks a bit different to support a "tree" of structs and literals.
2025-09-04 08:15:44 +02:00
swift-ci 255ee32c29 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-03 13:48:19 -07:00
Adrian Prantl 75bee892be Add LLDB and swift-reflection-dump support for WebAssembly
This patch adds parsing and extracting of the Swift reflection
metadata data segments from within the WebAssembly DATA section and
tests it using swift-reflection-dump. This is needed to allow LLDB to
acces Swift reflection metadata when attached to WebAssembly
processes.

rdar://159217213
2025-08-27 17:14:17 -07:00
Janat Baig 798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
JanBaig ff894c4d01 [Format] Apply clang-format to recent changes 2025-08-09 12:46:18 -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
JanBaig 988a3dcf25 [SIL] Introduce new SILDeclRef 2025-07-29 21:16:11 -04:00
Charles Zablit 0fc436fa9d [NFC][demangling] switch to using NodePrinter::printFunctionName 2025-07-02 19:15:34 +01:00
Slava Pestov 9033198674 ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
We sometimes mangle SILFunctionTypes when generating debug info
for reabstraction thunks, and these can have various exotic
parameter and result attributes. Two recent additions were
never plumbed through the mangler, causing assertion failures
when emitting debug info.

Fixes rdar://153730847.
2025-06-27 10:56:12 -04:00
Charles Zablit 1a598665b9 [demangling] add new wrapper API 2025-06-26 12:16:51 +01:00
Charles Zablit e8ea37b681 remove unused API 2025-06-24 13:03:32 +01:00
Charles Zablit 479e664a04 add new methods to the NodePrinter to enable range tracking possibilities when demangling a name 2025-06-20 15:30:19 +02:00
Charles Zablit fdde2a395d move NodePrinter declarations to a header 2025-06-18 12:21:59 +01:00
Pavel Yaskevich 8e49860349 [Demangle] Implement missing Node::Kind::OutlinedInitializeWithTakeNoValueWitness
Implements de/remangler support for `WOB` manglings.
2025-06-05 14:07:05 -07:00
Hamish Knight 5d1f219acb Change InlineArray sugar separator x -> of 2025-05-30 13:50:22 +01:00
Erik Eckstein 774d869517 Fix some compiler warnings 2025-05-06 12:32:56 +02:00
Ludwig Hollmann 39aa950660 Update file header comments for headers in lib. 2025-05-04 22:26:26 +02:00
Mike Ash 6ccfe7e213 [Runtime] Shrink RemanglerBuffer's SubstitutionEntry.
We stack-allocate 512 of these entries for a temporary cache, so the entry size matters a great deal. Shrink it from 3 words to 2 by storing treatAsIdentifier in the low bit of the node pointer.

rdar://149685318
2025-04-24 15:44:46 -04:00
Slava Pestov 5e23a4c2c0 Demangle: Implement missing Node::Kind::DependentProtocolConformanceOpaque
If a retroactive conformance is conditional and the subject type of a
conditional requirement is an opaque archetype, the mangler would
emit a mangling using the "HO" operator which the demangler did not
understand.

Implement de/remangler support for the "HO" operator.

Fixes rdar://149801864.
2025-04-23 16:39:16 -04:00
Pavel Yaskevich 07ff063ae3 [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-11 15:59:25 -07:00
Erik Eckstein aec1046895 swift-demangle: fix a crash for invalid input
When fed with invalid input, the swift-demangle tool crashed.

rdar://148754959
2025-04-09 08:51:30 +02:00
Artem Chikin 281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Nate Chandler 5eacbfd9d9 [DefaultOverrides] Mangling. 2025-03-25 07:22:14 -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
Holly Borla be670da373 Merge pull request #79980 from hborla/closure-body-macro
[Macros] Implement support for function body macros on closures.
2025-03-21 06:19:36 -07:00
Amritpan Kaur 555a486cda [Mangler] Add new mangling schemes. 2025-03-19 10:54:06 -07:00
Holly Borla 31d4f661fc [Macros] Support function body macros on closures. 2025-03-18 20:50:47 -07:00
Konrad `ktoso` Malawski 8c4dea9802 Revert "[concurrency] Add support for HopToMainActorIfNeededThunk." (#79938)
* Revert "[concurrency] Add support for HopToMainActorIfNeededThunk."

This reverts commit 0e0665bfbd.

* remove some last bits of 0e0665b
2025-03-13 06:48:03 +09:00