Skip to content

Commit 29b8040

Browse files
committed
progress
1 parent c7d27e6 commit 29b8040

File tree

285 files changed

+16800
-2028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+16800
-2028
lines changed

Cargo.lock.main

Lines changed: 5704 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agentic/pretty_printer.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ pub(super) fn emit_select_stmt(e: &mut EventEmitter, n: &SelectStmt) {
747747
- [x] ArrayCoerceExpr (array coercions that simply forward the inner expression)
748748
- [x] BitString
749749
- [x] Boolean
750-
- [x] BoolExpr (AND/OR/NOT)
750+
- [x] BoolExpr (AND/OR/NOT; precedence-aware parentheses preservation to maintain AST shape)
751751
- [x] BooleanTest (IS TRUE/FALSE/UNKNOWN and negations)
752752
- [x] CallStmt (CALL procedure)
753753
- [x] CaseExpr (CASE WHEN ... THEN ... ELSE ... END)
@@ -939,6 +939,9 @@ Keep this section focused on durable guidance. When you add new insights, summar
939939
- Render symbolic operator names (composed purely of punctuation) without quoting and force a space before parentheses so DROP/ALTER statements remain parseable.
940940
- Drop `LineType::SoftOrSpace` before optional DML clauses so compact statements stay single-line while long lists can wrap cleanly.
941941
- Drop `LineType::SoftOrSpace` before `OVER` clauses and each window spec segment so inline window functions can wrap without blowing per-line limits while still re-parsing to the same AST.
942+
- Preserve explicit parentheses in arithmetic expressions by wrapping child `AExpr` nodes whenever their operator precedence is lower than the parent or a left-associative parent holds a right-nested operand; otherwise constructs like `100 * 3 + (vs.i - 1) * 3` lose grouping and fail AST equality.
943+
- Wrap `BoolExpr` children whose precedence is lower than their parent (e.g. OR under AND, AND/OR under NOT) so expressions like `(a OR b) AND c` retain explicit parentheses and keep the original AST structure.
944+
- Use `emit_clause_condition` to indent boolean clause bodies (`WHERE`, `HAVING`, planner filters) so wrapped predicates align under their keywords instead of hugging the left margin.
942945
943946
**Node-Specific Patterns**:
944947
- Respect `CoercionForm` when emitting row constructors; implicit casts must stay bare tuples or the planner-visible `row_format` flag changes.
@@ -948,6 +951,7 @@ Keep this section focused on durable guidance. When you add new insights, summar
948951
- Decode window frame bitmasks to render RANGE/ROWS/GROUPS with the correct UNBOUNDED/CURRENT/OFFSET bounds and guard PRECEDING/FOLLOWING against missing offsets.
949952
- Ordered-set aggregates must render `WITHIN GROUP (ORDER BY ...)` outside the argument list and emit `FILTER (WHERE ...)` ahead of any `OVER` clause so planner fallbacks reuse the same surface layout.
950953
- For `MergeStmt`, only append `BY TARGET` when the clause has no predicate (the `DO NOTHING` branch); conditional branches should stay as bare `WHEN NOT MATCHED` so we don't rewrite user intent.
954+
- When a binary comparison must wrap, keep the operator attached to the left expression and indent the right-hand side behind a `LineType::SoftOrSpace` break. This avoids the renderer splitting each token onto its own line once the surrounding group has already broken.
951955
952956
**Planner Nodes (CRITICAL - Read Carefully)**:
953957
- **NEVER create synthetic nodes or wrap nodes in SELECT statements for deparse round-trips**. This violates the architecture and breaks AST preservation.
@@ -1009,7 +1013,8 @@ just ready
10091013
10101014
## Next Steps
10111015
1012-
1. Investigate the remaining line-length failure in `test_multi__window_60`; the embedded `CREATE FUNCTION` body still emits a long SQL string that blows past the 60-column budget, so we either need a smarter break in the ViewStmt emitter or a harness carve-out for multiline literals.
1016+
1. Investigate why `ResTarget` aliases are still quoted even when lowercase-only, and adjust the identifier helper if we can emit bare aliases without breaking AST equality.
1017+
2. Audit rename/owner emitters so non-table object types (FDWs, conversions, operator families) carry their specific keywords and reshape lists like `USING` clauses without falling back to `ALTER TABLE`.
10131018
10141019
## Summary: Key Points
10151020

agentic/session_log.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,81 @@ For current implementation status and guidance, see [pretty_printer.md](./pretty
66

77
## Session History
88

9+
---
10+
**Date**: 2025-10-31 (Session 67)
11+
**Nodes Implemented/Fixed**: `emit_clause_condition`, `emit_aexpr_op` spacing tweaks, snapshot updates
12+
**Progress**: 192/270 → 192/270
13+
**Tests**: `cargo test -p pgls_pretty_print test_single__update_with_cte_returning_0_60 -- --show-output`; `cargo test -p pgls_pretty_print test_multi__float4_60 -- --show-output`
14+
**Key Changes**:
15+
- Reworked `emit_clause_condition` and `emit_aexpr_op` so binary comparisons keep their operator with the left-hand side while permitting the right-hand side to wrap with indentation, preventing per-token line splitting.
16+
- Reviewed and accepted snapshot churn after the clause helper landed, ensuring the layout changes are captured for SELECT/UPDATE predicates and JSON-heavy fixtures.
17+
- Documented the wrapping pattern and queued follow-up work for rename/owner emitters that still fall back to `ALTER TABLE`.
18+
19+
**Learnings**:
20+
- The current renderer breaks every `SoftOrSpace` once a group overflows, so grouping the left operand and operator together is critical to avoid fragmented predicates.
21+
- Owner/rename emitters for non-table object types still need bespoke formatting to keep AST equality—worth calling out explicitly in durable guidance and Next Steps.
22+
23+
**Next Steps**:
24+
- Expand rename/owner support so conversions, FDWs, and operator families emit their proper keywords rather than defaulting to `ALTER TABLE`.
25+
- Re-run the full pretty-print suite once the rename emitters are tightened.
26+
---
27+
28+
---
29+
**Date**: 2025-10-30 (Session 66)
30+
**Nodes Implemented/Fixed**: Clause body indentation helper; WHERE/HAVING emitters
31+
**Progress**: 192/270 → 192/270
32+
**Tests**: cargo test -p pgls_pretty_print test_single__complex_select_0_60 -- --show-output (expected line-length panic pre-existing); cargo test -p pgls_pretty_print test_single__update_with_cte_returning_0_60 -- --show-output (snapshot pending)
33+
**Key Changes**:
34+
- Introduced `emit_clause_condition` and rewired WHERE/HAVING, planner filters, and related clauses to use it so wrapped predicates indent beneath their clause keyword.
35+
- Updated durable guidance to document the helper and removed the completed Next Step on clause indentation.
36+
- Verified new layout on targeted fixtures; snapshots remain to be refreshed once the broader suite is reviewed.
37+
38+
**Learnings**:
39+
- Centralising boolean clause formatting behind a shared helper keeps indentation consistent across statement emitters and simplifies future adjustments.
40+
- Planner FILTER clauses (Aggref/FuncCall/WindowFunc) benefit from the same indentation logic, avoiding bespoke spacing tweaks.
41+
42+
**Next Steps**:
43+
- Review snapshot fallout from clause indentation and accept once output looks stable across multi-statement fixtures.
44+
- Resume investigation into emitting bare lowercase `ResTarget` aliases without reintroducing AST churn.
45+
---
46+
47+
---
48+
**Date**: 2025-10-30 (Session 65)
49+
**Nodes Implemented/Fixed**: BoolExpr precedence guarding; Added targeted pretty-print fixtures
50+
**Progress**: 192/270 → 192/270
51+
**Tests**: cargo test -p pgls_pretty_print test_single__bool_expr_parentheses_0_80 -- --show-output; cargo test -p pgls_pretty_print test_single__aexpr_precedence_parentheses_0_80 -- --show-output; cargo insta accept
52+
**Key Changes**:
53+
- Added precedence-aware parentheses handling in `emit_bool_expr` so nested OR/AND/NOT combinations keep the original grouping.
54+
- Introduced `bool_expr_parentheses_0_80.sql` and `aexpr_precedence_parentheses_0_80.sql` single-statement fixtures and accepted their snapshots to lock in coverage.
55+
- Updated durable guidance and Next Steps to track indentation follow-ups and alias-quoting investigations.
56+
57+
**Learnings**:
58+
- BoolExpr trees rely on operator precedence rather than explicit markers; wrapping lower-precedence children is required to preserve `(a OR b) AND c`-style groupings during pretty printing.
59+
- Clearing lingering `.snap.new` files via `cargo insta accept` prevents legacy snapshot churn from obscuring new regressions.
60+
61+
**Next Steps**:
62+
- Explore clause-level indentation helpers so multiline WHERE/HAVING predicates align cleanly.
63+
- Review identifier emission for ResTarget aliases to avoid quoting simple lowercase names unless required.
64+
---
65+
66+
---
67+
**Date**: 2025-10-24 (Session 64)
68+
**Nodes Implemented/Fixed**: AExpr precedence-aware parentheses emission
69+
**Progress**: 192/270 → 192/270
70+
**Tests**: cargo test -p pgls_pretty_print test_multi__window_60 -- --nocapture
71+
**Key Changes**:
72+
- Added operator-precedence analysis in `emit_aexpr_op` so lower-precedence or right-nested operands are wrapped, restoring parentheses for expressions like `100 * 3 + (vs.i - 1) * 3`.
73+
- Updated the `window_60` snapshot to reflect the restored grouping and verified the multi-statement harness now passes without AST diffs.
74+
- Captured durable guidance about preserving explicit arithmetic parentheses in `agentic/pretty_printer.md` and refreshed the Next Steps queue.
75+
76+
**Learnings**:
77+
- Preserving AST structure for arithmetic requires checking both precedence and associativity; wrapping only lower-precedence children is insufficient when left-associative parents hold right-nested operands.
78+
79+
**Next Steps**:
80+
- Extend `BoolExpr` emission to keep user-written parentheses when mixing AND/OR so precedence alone doesn't change the tree shape.
81+
- Add focused fixtures exercising the new `AExpr` precedence guard to prevent regressions.
82+
---
83+
984
---
1085
**Date**: 2025-10-23 (Session 63)
1186
**Nodes Implemented/Fixed**: MergeStmt emitter tweaks; JSON_TABLE and ordered-set coverage

crates/pgls_pretty_print/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ edition.workspace = true
66
homepage.workspace = true
77
keywords.workspace = true
88
license.workspace = true
9-
name = "pgt_pretty_print"
9+
name = "pgls_pretty_print"
1010
repository.workspace = true
1111
version = "0.0.0"
1212

1313

1414
[dependencies]
15-
pgt_pretty_print_codegen.workspace = true
16-
pgt_query.workspace = true
15+
pgls_pretty_print_codegen.workspace = true
16+
pgls_query.workspace = true
1717

1818
[dev-dependencies]
19-
camino.workspace = true
20-
dir-test.workspace = true
21-
insta.workspace = true
22-
pgt_statement_splitter.workspace = true
19+
camino.workspace = true
20+
dir-test.workspace = true
21+
insta.workspace = true
22+
pgls_statement_splitter.workspace = true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pgt_pretty_print_codegen::group_kind_codegen!();
1+
pgls_pretty_print_codegen::group_kind_codegen!();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pgt_pretty_print_codegen::token_kind_codegen!();
1+
pgls_pretty_print_codegen::token_kind_codegen!();

crates/pgls_pretty_print/src/nodes/a_array_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pgt_query::protobuf::AArrayExpr;
1+
use pgls_query::protobuf::AArrayExpr;
22

33
use crate::{
44
TokenKind,

crates/pgls_pretty_print/src/nodes/a_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use pgt_query::protobuf::AConst;
2-
use pgt_query::protobuf::a_const::Val;
1+
use pgls_query::protobuf::AConst;
2+
use pgls_query::protobuf::a_const::Val;
33

44
use crate::{
55
TokenKind,

0 commit comments

Comments
 (0)