Skip to content

Swift AST extraction aborts on if let x = await <non-call> and if let x = try await ..., silently dropping most of the file #3540

Open

Description

@goatemail

Summary

Swift AST extraction aborts partway through a file when an if let optional binding has an await operand that is not a direct function call. The parser emits a syntax error at that line and silently drops most declarations after it, so the resulting graph is missing a large fraction of a valid file's symbols.

guard let with the same await operand parses fine, so this looks specific to the if let binding rule.

Repro matrix

Each file is valid Swift (compiles under Swift 6 / Xcode 26.3). Only the binding line differs:

binding result
if let r = await fetchRings() ok
if let r = try await mint() syntax error
if let r = await pending (an async let variable) syntax error
if let r = await box.rings (actor member access) syntax error
guard let r = await pending else { ... } ok

So await + direct call is handled; try await + call, await + bare identifier, and await + member access are not.

Minimal failing file

import Foundation

struct Rings { let move: Double = 0 }

func fetchRings() async -> Rings? { nil }

func load() async {
    async let pending = fetchRings()
    if let r = await pending {
        print(r.move)
    }
}

struct SentinelType { let marker = 1 }
from graphify.extract import extract
from pathlib import Path

r = extract([Path("repro.swift")], cache_root=Path("."), parallel=False)
print(sorted(n["label"] for n in r["nodes"]))
warning: 1 file(s) had syntax errors and may be partially extracted:
  repro.swift (first error at line 9, 6 symbol(s) extracted)

Changing line 9 to guard let r = await pending else { return } removes the warning.

Impact on a real corpus

Building a graph over a ~240-file iOS monorepo, two files tripped this and lost most of their symbols:

file symbols in graph approx. symbols in source
WidgetShared.swift (201 lines) 15 ~53
FatSecret.swift (412 lines) 59 ~87

The failing lines were if let rings = await rings { and if let fresh = try await requestToken(creds: creds, scope: scope) { — one of each failing variant above.

The warning is printed, which is good, but it's easy to miss in a large run and the graph is quietly incomplete. Re-extracting those two files with an LLM pass and merging recovered 94 nodes and 155 edges.

Environment

graphifyy          0.9.61
tree-sitter        0.25.2
tree-sitter-swift  0.7.3
Python             3.12.8
OS                 macOS 15.7.2 (x86_64)

Notes

This may well be an upstream tree-sitter-swift grammar limitation rather than a graphify bug. If so, two things might still be worth doing here:

  1. Make the partial-extraction warning harder to miss — e.g. surface it in GRAPH_REPORT.md alongside the corpus stats, not only on stdout during extraction, so a graph built in CI records that it is incomplete.
  2. Consider falling back to semantic/LLM extraction for files where the AST pass reports a syntax error, since those files are exactly the ones the structural pass under-covers.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions