Repository navigation
Fingerprint: keep per-node functions out of _fingerprintNode's stack frame - #23
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. No issues found. This PR tightens the normalize/fingerprint depth handling in libpg_query: the recursion walker now guards the depth-limited recursion with a single ERRCODE_STATEMENT_TOO_COMPLEX check, while the WASM depth test exercises much deeper nesting and CI updates the fingerprint/overflow variants accordingly.
Two candidate findings were reviewed and both fell below the confidence threshold for reporting; no review-worthy defects remain. Reviewed commit: cd792c3 |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Summary
In the WASM build on Node.js 20, once V8 has moved the module to its optimizing compiler (TurboFan),
pg_query_fingerprintoverflows the native stack at about 30 chained terms, 13 nested function calls or 6 nested subqueries.pg_query_normalizefingerprints the query too, so it stops at the same depths. Published 18.1.5 behaves the same; it is easy to miss because a fresh instance runs on the baseline compiler, where depths are in the thousands.Cause: each
_fingerprint<NodeType>function has exactly one caller, theswitchin_fingerprintNode. Binaryen's one-caller inlining merges all ~260 of them into_fingerprintNode, and Node 20's TurboFan gives that single function a native frame of roughly 30 kB per level.Fix: the generated
switchcalls each function through apg_noinlinehelper that takes the function pointer, so nothing can be merged into_fingerprintNode:scripts/generate_fingerprint_outfuncs.rbemits this;pg_query_fingerprint_conds.cis the regenerated output. The cast differs only in the pointee type of the node pointer, the same convention as Postgres'tree_walker_callback. Fingerprints are unchanged (make testpasses). No memory, stack or link setting changes.Measured with the libpg-query-node v18 build, deepest input handled (TurboFan only / baseline only):
Parse depths are unchanged. A link-time alternative (
--one-caller-inline-max-function-size) fixes fingerprint as well but changes inlining in the parser and lowered some parse depths, so it was rejected.Test first: the first commit adds a
fingerprintmode totest/wasm_depth.c(1,000 nested subqueries, 2,000 nested function calls) and runs it inbuild_wasmwithnode --no-liftoff;build_wasmfailed on that commit and passes with the fix.Implemented in session Audit WASM memory history and verify full-stack depth
Review with Devin · Open in Devin Desktop