Record Wasm-GC mutable capture anti-pattern
ober
52a7723f24dce7ccac79511ebc0f498a2613496a
--- a/data/anti-patterns.sexp +++ b/data/anti-patterns.sexp @@ -4532,3 +4532,24 @@ "jerboa_request_advisor" "rg vendor/ChezScheme/c/thread.c" "make check-docs")) + (("advice" + . + "Analyze each function body for assigned variables and variables captured by nested lambdas. Store those locals in a mutable Wasm-GC box struct, capture the box reference in closure environments, read through struct.get, and implement set! with struct.set. letrec can then lower to boxed placeholder bindings followed by set! initializers.") + ("avoid" + . + "Do not lower captured locals as plain values when they can be assigned or used for letrec placeholders. Capturing the current value gives closures stale state, makes set! inside a closure unsupported or incorrect, and breaks recursive local closures that need to see the closure after initialization.") + ("id" . "wasm-gc-capture-mutable-by-value") + ("kinds" "module" "debug-error" "test") + ("pattern" + . + "closure.*capture.*(set!|mutable|letrec)|capture.*by value") + ("severity" . "high") + ("tags" "wasm-gc" "closures" "set!" "letrec" "boxes" + "mutation") + ("title" + . + "Do Not Capture Mutable Closure Variables By Value") + ("tools" + "scripts/test-wasm-gc.sh" + "node support/wasm-gc/run-export.mjs" + "rg")))