mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-21 16:57:09 +08:00
fix(swift): a call written after try! links what it calls on Windows (#2683)
The Windows kernels read the `!` of every `try!` as a logical not, so `try! Message2(data: d)` became a call of `! Message2` that never resolves, and a call through a receiver lost it: `try! Settings.Defaults.load()` was a bare `load`. The cause is the grammar's C, not the walker. tree-sitter-swift 0.7.3's external scanner steps aside for the `!` of `try!` through a 64-bit mask whose entry is built as `1UL << FAKE_TRY_BANG`, bit 32. `unsigned long` is 32 bits on Windows and MSVC folds the overflowing shift to 0 (warning C4293), so the scanner never stepped aside: `try` parsed alone, then a prefix `!` on the callee. macOS and Linux have 64-bit longs, and clang's wasm32 build folds the shift to bit 31 (`_directive_endif`, valid at every expression start), so the wasm and the other kernels have always read `try!` right. The kernel now compiles the crate tarball's src/ itself, from codegraph-kernel/grammars/swift, with upstream 0.7.4's one-line fix (`1ULL`), as it already does for the Kotlin, Lua, Scala and Dart grammars. The patch and its provenance are in docs/grammars/tree-sitter-swift.patch and .md. parser.c is unchanged, so the node-kind and field tables still match the wasm, which is untouched. TortureTry.swift pins calls after try!, try? and try on both engines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,12 @@ extern "C" {
|
||||
extern "C" {
|
||||
fn tree_sitter_dart() -> *const ();
|
||||
}
|
||||
// Vendored swift grammar (build.rs-compiled C — crate 0.7.3's src/ with a
|
||||
// one-line scanner fix the crate's own build lacks on Windows; see
|
||||
// grammars/swift and docs/grammars/tree-sitter-swift.md).
|
||||
extern "C" {
|
||||
fn tree_sitter_swift() -> *const ();
|
||||
}
|
||||
|
||||
/// Languages this kernel binary can extract (reported by contractInfo;
|
||||
/// TS-side routing policy decides what actually routes).
|
||||
@@ -65,9 +71,12 @@ pub fn grammar_for(language: &str) -> Option<Language> {
|
||||
// R7b: v0.24.2, the full HTML-interleaving variant — LANGUAGE_PHP,
|
||||
// NEVER LANGUAGE_PHP_ONLY (which errors on leading HTML).
|
||||
"php" => Some(tree_sitter_php::LANGUAGE_PHP.into()),
|
||||
// R7b: crate 0.7.3 — the vendored wasm is built from this crate's own
|
||||
// tarball src/ (table identity by construction; see grammars.ts).
|
||||
"swift" => Some(tree_sitter_swift::LANGUAGE.into()),
|
||||
// R7b: crate 0.7.3's src/, the sources the vendored wasm is built
|
||||
// from (table identity by construction; see grammars.ts), compiled in
|
||||
// build.rs with the scanner's `try!` fix (`1ULL << FAKE_TRY_BANG`).
|
||||
"swift" => {
|
||||
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_swift) }.into())
|
||||
}
|
||||
// R7b: fwcd 0.3.8, vendored C compiled in build.rs (crate unusable).
|
||||
"kotlin" => {
|
||||
Some(unsafe { tree_sitter_language::LanguageFn::from_raw(tree_sitter_kotlin) }.into())
|
||||
|
||||
Reference in New Issue
Block a user