Skip to content

Swift: vendored grammar predates SE-0458 unsafe expressions and typed-throws initializers — files index partially and lose CALLS edges #2377

Open

Description

@Studnicky

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.

  1. Strict memory safety, unsafe expressions (SE-0458, Swift 6.2). Packages built with .strictMemorySafety() must write unsafe before expressions that use unsafe constructs. The grammar reads unsafe as an identifier: unsafe readValue(buffer) becomes a call_expression whose callee is unsafe, and the real callee sits in an ERROR node. The function using the marker ends up with no CALLS edges at all.
  2. Typed throws (SE-0413). init() throws(LoadError) { ... } does not parse and is reported as partial. The same holds for func ... throws(E) and do 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:

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: 2
  • check_index_coverage: Marked.swift partial at lines 5–6, TypedThrows.swift partial at line 7
  • query_graph CALLS 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.c at 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 upstream scanner.c at 187fd4d; 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.c cases, failing on the current pin, that assert CALLS edges through each unsafe form (prefix, let, nested, try/await ordering, closure and defer bodies, for unsafe, @unsafe/@safe, and parity with the unmarked code), plus clean parses and extracted calls for typed-throws initializers, functions, closures and do blocks.

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

  1. added
    bugSomething isn't working
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    and removed
    windowsWindows-specific issues
    on Oct 19, 2026
  2. DeusData commented on Oct 19, 2026

    @DeusData
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparsing/qualityGraph extraction bugs, false positives, missing edgespriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions