fix(transform): single routing pass via claims; namespace-aware handlers; statement spans on facts - #323
Merged
Merged
Conversation
…lers, statement spans
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stage 1 of the AST convergence plan (constructive-planning #1323). Three tightly-coupled changes to
@pgsql/transform:1. Fixes a live double-routing bug. Every "the walker does NOT auto-recurse into X" comment in
transform.tsis false —@pgsql/traversetag-synthesizes concrete typed fields (CreateStmt.relation,Constraint.pktable,TypeCast.typeName,CallStmt.funccall, …), verified empirically for all ~24 claimed cases. So each site was routed twice: once by the statement handler, once by the generic child visitor. Idempotent for acyclic mappings, but a cyclic mapping (a→b, b→a) swapped back and the leftover-validator threw:Fix is a claim registry: each routable site (RangeVar / name-list array /
(container, field)) is resolved through the router at most once per result —claimSite(result, site, field)guarded insidetransformRelation/transformNameList/transformSchemaNameField/rewriteSchemaField. Since the walker is pre-order, the most context-aware handler claims first (e.g.DropStmtroutingObjectWithArgs.objnamewith nsfunctionbeats the genericObjectWithArgsvisitor's nsunknown).2. Deletes ~20 redundant statement handlers (pure duplicates of the generic
RangeVar/TypeName/FuncCallvisitors) and trims partial ones (CreateFunctionStmtreturn/param type loops,CreateTrigStmt.relation,AlterSeqStmt.sequence,CreateCastStmttype blocks, …). Handlers that carry real context stay — and several now pass their namespace instead of defaulting tounknown:so object-level routes now apply to
ALTER FUNCTION ... OWNER TO,... SET SCHEMA,RENAME, andCOMMENT ONforms (new test: a function-only route rewritesALTER FUNCTION a.f(int) OWNER TO u).3. Adds
spantoStatementFacts:sql.slice(span.start, span.start + span.len)is the statement's verbatim source, so downstream consumers (pgpm/slice exclusion, the upcoming PgpmProgramAst statement layer) never need a second parse just to recover locations.Net:
transform.tsshrinks by ~200 lines; 234 tests green (228 existing + 6 new inrouting-claims.test.ts); no API changes beyond the additivespanfield.Link to Devin session: https://app.devin.ai/sessions/025fb88043964fdbb335ac5e39df2478
Requested by: @pyramation