Skip to content

Swift semantic adapter, and name the test holding a human wait - #792

Merged
yogthos merged 2 commits into
mainfrom
swift-adapter-and-flake-diagnostic
Aug 15, 2026
Merged

Swift semantic adapter, and name the test holding a human wait#792
yogthos merged 2 commits into
mainfrom
swift-adapter-and-flake-diagnostic

Conversation

@yogthos

@yogthos yogthos commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

The two follow-ups filed from #791.

Swift semantic adapter (dirge-3cfq)

find_definition, list_symbols and get_symbol_body are tree-sitter backed, not LSP backed, so a model asked to find a Swift symbol got nothing while the lsp tool answered the same question correctly. And the pre-write syntax gate did not cover .swift at all.

tree-sitter-swift folds struct, class, enum, actor and extension into one class_declaration kind, so the node shapes here were dumped from the parser rather than guessed. Two calls worth stating:

  • An extension is not emitted as a type — it declares none, and emitting one means "where is Greeter defined" returns two answers, one of them wrong. Its members do attribute to the type it extends.
  • Swift's default access level is internal, so only public/open/package count as exported. Treating unmarked declarations as exported would make exports meaningless, since most Swift carries no modifier.

Registering .swift in the syntax gate is a hard write block, so the grammar was measured before wiring it in — async/await, actors, generics with where, property wrappers, result builders, @main, multi-line strings, custom operators, subscripts, enums with associated values: no false errors. That measurement is now a test, so a grammar regression reports itself instead of silently refusing valid Swift.

The fourth table

The gate keeps its own extension→grammar map, separate from the adapter registry, with nothing to notice a language present in one and absent from the other. That is the same shape as the three-table LSP bug in #791, and it is why .swift could have an adapter and no gate coverage.

Adapter extensions must now be either gated or listed in GATE_EXCLUSIONS with a reason, checked against the registry — which is itself now a single default_adapters() list rather than a copy inside the manager. The check immediately found .h: claimed by the C adapter, ungated, and correctly so — C++ in a header is ordinary and tree-sitter-c would refuse it on a hard block. Now that is a written decision rather than an accident. .sql, .ex/.exs/.heex and .dfy are likewise recorded, the last three honestly marked "not assessed" rather than pretending they were considered.

The human-wait flake (dirge-lfux) — diagnostic only

No fix, deliberately. Nine full-suite runs (six default, three at --test-threads=32) with instrumentation would not reproduce it; both original occurrences were under heavy machine load.

The first fix I tried was unsound and is worth recording: making the assertions relative (baseline, act, compare) fails just as hard, because the baseline is read at T0 and a concurrent guard lands at T1. It turned an occasional flake into a deterministic failure. A delta over a shared mutable global is no more sound than a level over one.

What ships is HOLDERS, a test-build-only record of which thread holds each wait, named in every assertion failure. Cargo names test threads after the test, so the next occurrence prints the culprit instead of an unattributable flake. The remaining decision — sweep every test that can raise the counter into TEST_GATE, or make the watchdog's input injectable so tests stop sharing one counter — is written up on the bead.

Verification

Against the real SwiftPM package from #791:

  • find_definition greetGreeter.swift:3 [method] public func greet(_ name: String) -> String
  • list_symbols → the type and its members, with export flags
  • writing invalid Swift → Syntax check failed … 1 error(s) detected by tree-sitter, and no file written

Full suite 5621 pass, four clippy configs and fmt clean.

Yogthos added 2 commits August 15, 2026 12:30
The Swift adapter (GH #778 follow-up). tree-sitter-swift folds struct, class,
enum, actor AND extension into one `class_declaration` kind, so the shapes are
read from a parser dump rather than guessed: an extension declares no type and
is not emitted as one, but its members attribute to the type it extends, which
is where someone looking for them expects to find them. Swift's default access
level is internal, so only public/open/package count as exported.

Registering it in the syntax gate is a HARD write block, so the grammar was
measured first against async/await, actors, generics with where-clauses,
property wrappers, result builders, @main, multi-line strings, custom operators
and enums with associated values — no false errors. That evidence is a test, so
a grammar regression says so before a user finds their valid Swift refused.

The gate keeps its own extension table, separate from the adapter registry, with
nothing to notice a language in one and not the other — the fourth such table
this week. Adapter extensions must now be gated or listed in GATE_EXCLUSIONS
with a reason; the check derives from the registry, which is itself now one
list (default_adapters) rather than a copy in the manager. It immediately found
`.h`: claimed by the C adapter, ungated, and correctly so — C++ in a header is
ordinary and tree-sitter-c would refuse it on a hard block. Now that is written
down instead of being an accident.

For dirge-lfux, the human-wait flake: no fix, because nine full-suite runs with
instrumentation would not reproduce it, and the relative-assertion fix I tried
first was unsound — a baseline over a shared global is no better than a level
over one. What ships is HOLDERS, a test-only record of which thread holds each
wait, named in every assertion failure. Cargo names test threads after the test,
so the next occurrence prints the culprit rather than an unattributable flake.
@yogthos
yogthos merged commit bfeb9a7 into main Aug 15, 2026
16 checks passed
@yogthos
yogthos deleted the swift-adapter-and-flake-diagnostic branch August 15, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant