mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-28 05:57:29 +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:
co-authored by
Claude Opus 5.5
parent
22e9f7b337
commit
c58f0417c6
@@ -86,4 +86,30 @@ fn main() {
|
||||
dart.flag_if_supported("-utf-8"); // msvc
|
||||
dart.compile("tree-sitter-dart");
|
||||
println!("cargo:rerun-if-changed=grammars/dart");
|
||||
|
||||
// Swift grammar — vendored C (fifth vendored-grammar-C language): the
|
||||
// crates.io tree-sitter-swift 0.7.3 tarball's src/, the same sources the
|
||||
// vendored wasm is built from (swift checklist §Grammar prep), with
|
||||
// docs/grammars/tree-sitter-swift.patch applied to scanner.c. The crate's
|
||||
// scanner builds `1UL << FAKE_TRY_BANG` (bit 32) into a constant table;
|
||||
// where `unsigned long` is 32 bits that overflows — MSVC folds it to 0,
|
||||
// so the Windows kernels read the `!` of every `try!` as a logical not
|
||||
// and `try! Foo()` called `!Foo`. Upstream 0.7.4 writes `1ULL`; a bump to
|
||||
// a fixed release can return to the crate (and the wasm moves with it).
|
||||
// parser.c d3edff6effe31b9a507f496577407987343b101b23eb7bee7a9b050e8ab5d27a
|
||||
// scanner.c f3d6271d64f58c39eed544104a70ca2cf9ecbf80c5d900620f1afd38836542cb
|
||||
// scanner.c 8acafef098ea4a52ebfc4cdf2fe26706113a22ac8ba2faf7d952755ff350cad6 (patched)
|
||||
// Flags crib the tarball's own bindings/rust/build.rs (c11). parser.c is
|
||||
// ~20 MB.
|
||||
let mut swift = cc::Build::new();
|
||||
swift.std("c11");
|
||||
swift.include("grammars/swift");
|
||||
swift.file("grammars/swift/parser.c");
|
||||
swift.file("grammars/swift/scanner.c");
|
||||
swift.flag_if_supported("-Wno-unused-parameter");
|
||||
swift.flag_if_supported("-Wno-unused-but-set-variable");
|
||||
swift.flag_if_supported("-Wno-trigraphs");
|
||||
swift.flag_if_supported("-utf-8"); // msvc
|
||||
swift.compile("tree-sitter-swift");
|
||||
println!("cargo:rerun-if-changed=grammars/swift");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user