Repository navigation
Swift: vendored grammar predates SE-0458 unsafe expressions and typed-throws initializers — files index partially and lose CALLS edges #2377
Description
Version
codebase-memory-mcp 0.11.0
Platform
macOS (Apple Silicon)
Install channel
GitHub release archive / install.sh / install.ps1
Binary variant
standard
What happened, and what did you expect?
The vendored Swift grammar (alex-pinkus/tree-sitter-swift at 8abb3e8b3325, 2026-03-20) predates two Swift language features. Files that use them are indexed partially, and calls inside them drop out of the graph.
- Strict memory safety,
unsafeexpressions (SE-0458, Swift 6.2). Packages built with.strictMemorySafety()must writeunsafebefore expressions that use unsafe constructs. The grammar readsunsafeas an identifier:unsafe readValue(buffer)becomes acall_expressionwhose callee isunsafe, and the real callee sits in an ERROR node. The function using the marker ends up with no CALLS edges at all. - Typed throws (SE-0413).
init() throws(LoadError) { ... }does not parse and is reported as partial. The same holds forfunc ... throws(E)anddo throws(E); those happen to keep their CALLS edges, because the error region sits inside a declaration that is still extracted.
Expected: both files fully covered, with CALLS edges from marked to makeBuffer and readValue.
(Separately, a call inside any Swift init, typed throws or not, is attributed to the file rather than to the initializer. That comes from extraction, not the grammar, and is tracked in #2379.)
Both are fixed upstream:
- SE-0458: Swift 6.2 strict memory safety
unsafeexpressions (SE-0458) fail to parse alex-pinkus/tree-sitter-swift#626, fixed by Add strict memory safety syntax -- SE-0458 alex-pinkus/tree-sitter-swift#625, merged as187fd4d. - SE-0413 typed throws:
c354345anded1196c, both after the current pin.
Parsed directly with tree-sitter-cli 0.23.0:
| Source | Pin 8abb3e8b3325 |
Upstream 187fd4d |
|---|---|---|
let v = unsafe readValue(buffer) |
call_expression(simple_identifier, ERROR, call_suffix) |
unsafe_expression(call_expression(...)) |
init() throws(E) { ... } |
ERROR | parses |
init?() throws(E) { ... } |
ERROR | parses |
func f() async throws(E) -> Int { ... } |
ERROR | parses |
do throws(E) { } |
ERROR | parses |
Reproduction
Dummy package (Package.swift enables .strictMemorySafety(); the indexer's result does not depend on it):
Sources/Demo/Marked.swift
func readValue(_ pointer: UnsafePointer<Int>) -> Int { pointer.pointee }
func makeBuffer() -> UnsafeMutablePointer<Int> { .allocate(capacity: 1) }
func marked() -> Int {
let buffer = unsafe makeBuffer()
return unsafe readValue(buffer)
}
func unmarked() -> Int {
let buffer = makeBuffer()
return readValue(buffer)
}Sources/Demo/TypedThrows.swift
enum LoadError: Error { case missing }
func helper() -> Int { 1 }
struct Loader {
let value: Int
init() throws(LoadError) {
value = helper()
}
}Commands:
codebase-memory-mcp cli --json index_repository '{"repo_path":"<dir>"}'
codebase-memory-mcp cli --json check_index_coverage '{"project":"<project>","paths":["Sources/Demo/Marked.swift","Sources/Demo/TypedThrows.swift"],"format":"json"}'
codebase-memory-mcp cli --json query_graph '{"project":"<project>","query":"MATCH (a)-[:CALLS]->(b) RETURN a.name AS caller, b.name AS callee ORDER BY caller, callee","format":"json"}'Result on 0.11.0:
index_repository:parse_partial_count: 2check_index_coverage:Marked.swiftpartial at lines 5–6,TypedThrows.swiftpartial at line 7query_graphCALLS rows:
["Sources/Demo/TypedThrows.swift", "helper"]
["unmarked", "makeBuffer"]
["unmarked", "readValue"]
marked has no edges. unmarked is the same code without the markers and has both. TypedThrows.swift is reported as partial at the init line.
Logs
No response
Diagnostics trajectory (memory / performance / leak issues)
No response
Project scale (if relevant)
2 files, 19 nodes, 20 edges
Confirmations
- I searched existing issues and this is not a duplicate.
- My reproduction uses shareable code (a dummy snippet or a public OSS repository), not proprietary code.
Proposed fix. Re-vendor internal/cbm/vendored/grammars/swift at 187fd4d:
- Generate
parser.cat ABI 14, the same ABI as the current pin, so no runtime change is needed. - Delete the Swift local-patch row in
MANIFEST.md. Both UBSan shifts it backports (fb63a7004f07,6ab8d1d74ebd) are in upstreamscanner.cat187fd4d; the row itself says a re-vendor past 2026-08-10 should delete it. - Update the pin row and regenerate the ABI summary and
scripts/vendored-checksums.txt. - Add
tests/test_extraction.ccases, failing on the current pin, that assert CALLS edges through eachunsafeform (prefix,let, nested,try/awaitordering, closure anddeferbodies,for unsafe,@unsafe/@safe, and parity with the unmarked code), plus clean parses and extracted calls for typed-throws initializers, functions, closures anddoblocks.
No extraction code changes appear to be needed: the unified walk already descends into wrapper nodes, the same way it reaches calls under await_expression.
Since this changes a vendored dependency, I'd like your go-ahead before opening the PR, and your preference on the pin: 187fd4d on upstream main (untagged, like the mojo entry), or the next tree-sitter-swift tag once it's cut.
Related but separate: #43 and #1893 are resolution issues with parsed Swift code; this issue is code the grammar can't parse at all.
Prepared with AI assistance; I reviewed and verified the reproduction and results.
Activity
DeusData commentedon Oct 19, 2026
Thank you for the upstream grammar comparison and for separating it from initializer extraction in #2379. The vendored pin choice and update direction need a maintainer decision before I can give the requested go-ahead. No dependency update is approved by this triage.