[PR #3089] [MERGED] fix(native): classify every Swift mangling prefix as invalid when undecodable #5606

Closed
opened 2026-10-31 01:07:56 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3089
Author: @kaoru0822-kitauji
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/swift-demangle-invalid-prefixes


📝 Commits (3)

  • a3cea59 fix(native): classify every Swift mangling prefix as invalid when undecodable
  • 546d168 test(native): expect only toolchain-portable Swift manglings to demangle
  • 9aab0dc Merge remote-tracking branch 'origin/main' into fix/swift-demangle-invalid-prefixes

📊 Changes

3 files changed (+71 additions, -16 deletions)

View changed files

📝 src/native/parsers/demangle.test.ts (+17 -15)
📝 src/native/parsers/demangle.ts (+17 -1)
📝 tests/boundary/mcp/nativeDemangleMcp.test.ts (+37 -0)

📄 Description

Problem

demangle_swift derives each symbol's status from swift-demangle --compact output. When the output equals the input, the symbol is reported as invalid only if it starts with $s or _$s. swift-demangle also accepts _T0 (Swift 4), $S/_$S (Swift 4.x), @__swiftmacro_ (macro file names) and $e/_$e (Embedded Swift). An undecodable symbol with one of those prefixes was reported as unchanged, which means a non-Swift name. In fact it is a Swift mangling the demangler rejected.

Observed with the real CLI on macOS (Command Line Tools swift-demangle):

before: $SBogus,$SBogus,unchanged   _T0Bogus,_T0Bogus,unchanged   $eBogus,$eBogus,unchanged
after:  $SBogus,$SBogus,invalid     _T0Bogus,_T0Bogus,invalid     $eBogus,$eBogus,invalid

Fix

A single prefix list in the parser decides when an unchanged output means invalid. Legacy Swift 3 _T is left out: an undecodable _T… input such as _Tprintf is also an ordinary C symbol spelling, so it stays unchanged. Valid demanglings and non-Swift names are unaffected.

Validation

  • The new MCP boundary case runs on macOS and calls the real swift-demangle through demangle_swift. Valid _T0, $S, _$S, $e and _$e symbols demangle, undecodable ones are invalid, and _Tprintf is unchanged. It fails before the fix and passes after.
  • The parser unit test covers all eight prefixes plus _Tprintf. It fails before the fix and passes after.
  • npm run test:focused -- src/native/parsers/demangle.test.ts tests/boundary/mcp/nativeDemangleMcp.test.ts: 9 passed.
  • npm run check:fast passes.

Performance: a constant prefix check per unchanged symbol, with no extra process calls.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/3089 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/swift-demangle-invalid-prefixes` --- ### 📝 Commits (3) - [`a3cea59`](https://github.com/morluto/rea/commit/a3cea599fb5ffe398abd90b528169e322ec79285) fix(native): classify every Swift mangling prefix as invalid when undecodable - [`546d168`](https://github.com/morluto/rea/commit/546d1689b61443dd4e6130539cbc6180bc68b577) test(native): expect only toolchain-portable Swift manglings to demangle - [`9aab0dc`](https://github.com/morluto/rea/commit/9aab0dc6a4009def5e4874a8c74fd08eb512ebc4) Merge remote-tracking branch 'origin/main' into fix/swift-demangle-invalid-prefixes ### 📊 Changes **3 files changed** (+71 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `src/native/parsers/demangle.test.ts` (+17 -15) 📝 `src/native/parsers/demangle.ts` (+17 -1) 📝 `tests/boundary/mcp/nativeDemangleMcp.test.ts` (+37 -0) </details> ### 📄 Description ## Problem `demangle_swift` derives each symbol's status from `swift-demangle --compact` output. When the output equals the input, the symbol is reported as `invalid` only if it starts with `$s` or `_$s`. `swift-demangle` also accepts `_T0` (Swift 4), `$S`/`_$S` (Swift 4.x), `@__swiftmacro_` (macro file names) and `$e`/`_$e` (Embedded Swift). An undecodable symbol with one of those prefixes was reported as `unchanged`, which means a non-Swift name. In fact it is a Swift mangling the demangler rejected. Observed with the real CLI on macOS (Command Line Tools `swift-demangle`): ``` before: $SBogus,$SBogus,unchanged _T0Bogus,_T0Bogus,unchanged $eBogus,$eBogus,unchanged after: $SBogus,$SBogus,invalid _T0Bogus,_T0Bogus,invalid $eBogus,$eBogus,invalid ``` ## Fix A single prefix list in the parser decides when an unchanged output means `invalid`. Legacy Swift 3 `_T` is left out: an undecodable `_T…` input such as `_Tprintf` is also an ordinary C symbol spelling, so it stays `unchanged`. Valid demanglings and non-Swift names are unaffected. ## Validation - The new MCP boundary case runs on macOS and calls the real `swift-demangle` through `demangle_swift`. Valid `_T0`, `$S`, `_$S`, `$e` and `_$e` symbols demangle, undecodable ones are `invalid`, and `_Tprintf` is `unchanged`. It fails before the fix and passes after. - The parser unit test covers all eight prefixes plus `_Tprintf`. It fails before the fix and passes after. - `npm run test:focused -- src/native/parsers/demangle.test.ts tests/boundary/mcp/nativeDemangleMcp.test.ts`: 9 passed. - `npm run check:fast` passes. Performance: a constant prefix check per unchanged symbol, with no extra process calls. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:07:56 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5606
No description provided.