Skip to content

Rakuast codex - #603

Draft
FCO wants to merge 9 commits into
masterfrom
rakuast-codex
Draft

FCO wants to merge 9 commits into
masterfrom
rakuast-codex

Conversation

@FCO

@FCO FCO commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

FCO added 9 commits October 24, 2026 10:00
Keep infix expressions parenthesized when string casts feed concatenation. SQLite must evaluate arithmetic before concatenating it into a JSON array path, including the repeated expression used to identify negative indexes.

Preserve bind values and their ordering. Add regressions for calculated indexes, negative results and captured offsets; compiler interpolation coverage follows with the compiler integration.

Validation: compile Red and run the complete default SQLite suite at this commit.
Introduce red-compile for explicitly opted-in compilation units. Translate supported map, grep, first and sort callbacks into specialized Red::AST factories and validators during CHECK, without executing the original callback.

Preserve the resolved comparison operators, including numeric/textual coercions and SQL casts. Bind runtime captures once per query, preserve native receiver dispatch and lexical operator scope, and retain symbolic fallback for unsupported syntax or subjects. Buffer update effects so abandoned templates cannot leak assignments into fallback. Support projections, JSON access and updates, scalar locals, membership and interpolation.

Register compiler modules, scope the unsupported-template exception under X::Red, document activation and limitations, and add compiler benchmarks and dedicated PostgreSQL CI coverage.

Validation: complete default SQLite suite plus RakuAST compiler, scope, template-reuse and direct-factory regression suites.
…ings

Cache connection-independent SQL plans and direct field/scalar comparison predicates while retaining private capture snapshots. Prepare a fresh statement for every execution and preserve transaction lifetime checks and current diagnostic comments.

Use ordinary factories when a source comparison requires scalar coercion. Fingerprint query state and metadata, partition plans by driver identity, and bypass reuse for unsupported values or custom deflators. Detect cyclic positional and associative values, and retain parameter groups inside uncached CASE branches. Add bounded synchronized LRU storage with constant-time hit bookkeeping and correct zero-capacity behavior.

Persist symbolic comparison prototypes in module precompilation, never runtime captures or connections. Add driver opt-in APIs, PostgreSQL parameter typing, runtime diagnostics and a cache-disable switch. Cover mutation, pagination, driver changes, concurrent cursors, precompilation and fallback; add cache and query-plan benchmarks.

Validation: default SQLite JSON, projection and cache regressions, plus RakuAST compiler/cache regressions. Both complete SQLite suites are verified on the final branch.
Read column names and key membership without allocating temporary Red::Column objects, while continuing to observe live metadata changes. Specialize single-column dirty tracking and retain assignment validation and per-instance state.

Build hydration lookup maps in one pass, resolve target types from column metadata and use native candidate matching for driver inflation. This also handles SQL column names that differ from attribute names.

Add model access, persistence, metadata and aliased-inflation regressions plus a focused benchmark. Reload created fixtures before testing clean state so the checks apply across SQLite, PostgreSQL and MySQL.

Validation: default SQLite JSON, projection, cache and model regressions, plus their RakuAST coverage. Both complete SQLite suites are verified on the final branch.
Create parameterized query classes for temporary projection storage only when requested through the metamodel, model queries or the ResultSeq package symbol. Serialize composition and publish one class per storage model.

Reuse generic storage methods while keeping column metadata, constructor wrappers, captured expressions, row data and dirty/saved state private. Install projection initializers directly and avoid materializing query classes for intermediate projections. Preserve the existing composition path for declared models and custom metaclasses.

Test class identity, read-only package access, constructor isolation, pagination boundaries and concurrent first access. Document the lifecycle and add a construction benchmark.

Validation: default SQLite JSON, cache, model and projection regressions, plus their RakuAST coverage. Both complete SQLite suites are verified on the final branch.
Forward the original argument Capture to compiled Red queries, preserving the dynamic operator allowance in the calling scope. Strip internal metadata only for native receivers and retain writable return values.

Stop compiler member searches after the first match, return an explicitly bound database driver directly, and replace literal snake/kebab separators without regex matching. Add formatter regressions for repeated separators, empty strings and Unicode input.

Validation: compile Red and run both complete SQLite suites, with and without the RakuAST frontend.
@FCO
FCO requested a balanced review from Copilot October 27, 2026 03:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved correctness bugs can produce incorrect query results, reuse stale SQL and bindings, miss nested JSON updates, and cause filtered row creation to fail.

6 open issues
What changed in this PR

This PR adds an optional RakuAST compiler and runtime query-plan caching to Red, alongside model-loading optimizations and broader collection dirty tracking.

Changes:

  • Compile supported query callbacks into reusable AST factories, with guarded fallback and diagnostics.
  • Cache SQL plans, defer projection query classes, and streamline model access and hydration.
  • Track in-place collection mutations, promote three experimental features, and add tests, benchmarks, documentation, and CI coverage.
File Description
tools/​benchmark-query-plans.raku Measures query construction, translation, execution, and predicate reuse.
tools/​benchmark-query-construction.raku Benchmarks filter and projection construction.
tools/​benchmark-query-cache.raku Measures cache hits and eviction costs.
tools/​benchmark-model-access.raku Benchmarks model loading, reads, and writes.
tools/​benchmark-compiler.raku Compares interpreted and direct AST factories.
t/​lib/​QueryPlanCompilerFixture.rakumod Supplies a precompiled query fixture.
t/​95-direct-ast-factories.rakutest Tests direct factories, validation, and buffered updates.
t/​94-template-reuse.rakutest Tests template reuse and capture isolation.
t/​93-rakuast-scope.rakutest Checks lexical operator scope preservation.
t/​92-rakuast-compiler.rakutest Covers compiled queries, fallback, dispatch, and mutations.
t/​87-json-operations.rakutest Adds arithmetic JSON-index regressions.
t/​67-enums.rakutest Removes the refreshable opt-in.
t/​56-refreshable.rakutest Tests refresh without an experimental flag.
t/​45-is-handling.rakutest Tests handling without an experimental flag.
t/​35-create.rakutest Removes the has-one opt-in.
t/​107-dirty-collections.rakutest Tests persistence of in-place collection mutations.
t/​106-compiler-warnings.rakutest Tests fallback warnings and configuration precedence.
t/​105-lazy-projection-resultseq.rakutest Tests deferred query classes and projection isolation.
t/​104-name-formatters.rakutest Tests literal separator replacement.
t/​103-model-access.rakutest Covers model access, dirty state, and hydration.
t/​102-query-plans.rakutest Tests plan caching, private bindings, and execution isolation.
t/​100-single-relationship-create.rakutest Removes the has-one opt-in.
META6.json Registers compiler and query-plan modules.
lib/​X/​Red/​Exceptions.rakumod Adds the unsupported-template exception.
lib/​Red/​Utils.rakumod Replaces separator regexes with literal substitutions.
lib/​Red/​Traits.rakumod Promotes handling and removes has-one guards.
lib/​Red/​ResultSeq/​Iterator.rakumod Integrates cached SQL plans into execution.
lib/​Red/​ResultSeq.rakumod Integrates compiled callbacks and fallback warnings.
lib/​Red/​QueryPlan/​Cache.rakumod Adds a bounded, synchronized cache.
lib/​Red/​QueryPlan.rakumod Adds plan fingerprinting, compilation, and preparation.
lib/​Red/​Driver/​SQLite.rakumod Preserves arithmetic grouping in JSON paths.
lib/​Red/​Driver/​Pg.rakumod Adds typed casts for bound parameters.
lib/​Red/​Driver/​CommonSQL.rakumod Supports query plans, parameter slots, and cast grouping.
lib/​Red/​Driver.rakumod Adds driver query-plan interfaces.
lib/​Red/​DB.rakumod Simplifies dynamic driver lookup.
lib/​Red/​Compiler/​Template.rakumod Implements binding, evaluation, validation, and predicate reuse.
lib/​Red/​Compiler/​Runtime.rakumod Dispatches instrumented calls without leaking metadata.
lib/​Red/​Compiler/​RakuAST.rakumod Translates and instruments callbacks during CHECK.
lib/​Red/​Compiler/​Emitter.rakumod Builds specialized AST factories and validators.
lib/​Red/​Column.rakumod Exposes attribute inflator resolution.
lib/​Red/​Attr/​Column.rakumod Adds lightweight hydration and metadata accessors.
lib/​Red/​AST/​BoundFilter.rakumod Defines shared predicates and private parameter bindings.
lib/​Red.rakumod Promotes features and documents handling and refresh.
lib/​MetamodelX/​Red/​Specialisable.rakumod Defers projection query classes under shared composition locking.
lib/​MetamodelX/​Red/​Relationship.rakumod Removes the has-one experimental guard.
lib/​MetamodelX/​Red/​Model.rakumod Optimizes projections and hydration; integrates refresh and collection sync.
lib/​MetamodelX/​Red/​Id.rakumod Uses lightweight primary-key metadata access.
lib/​MetamodelX/​Red/​Dirtable.rakumod Adds collection snapshots and streamlines dirty tracking.
docs/​tutorials/​relationship.md Documents stable has-one relationships and related-row creation.
docs/​tutorials/​rakuast.md Documents compilation, caching, diagnostics, and benchmarks.
docs/​tutorials/​experimental.md Updates experimental and promoted feature lists.
docs/​index.md Links the RakuAST tutorial.
Changes Records compiler, caching, model, and feature updates.
.github/​workflows/​matrix.yaml Adds a PostgreSQL-backed RakuAST test job.

Review effort: Balanced

}
return clone
}
v
Comment on lines +39 to +42
method not { Red::AST::Not.new(self) }
method returns { Bool }
method args { $!filter }
method find-column-name { $!filter.find-column-name }
Comment on lines +300 to +304
my @comparison = $operator eq any('==', '!=', '<', '<=', '>', '>=',
'eq', 'ne', 'lt', 'le', 'gt', 'ge')
?? [$operator, &implementation] !! [];
return ['op', %operators{$operator}, self.expression($value.left),
self.expression($value.right), |@comparison];
self.unsupported('Unsupported prefix operator')
unless $operator eq any(<- +>)
|| ($operator eq any(<! not so>) && $!predicate);
return self.expression($value.operand) if $operator eq '+';
try {
@plan = $translation.translate(@args[0]);
sub check-effects(@part, Bool $conditional = False) {
return if @part[0] eq any(<literal capture local>);
Comment thread lib/Red/QueryPlan.rakumod
Comment on lines +32 to +33
return 'model:' ~ $value.WHICH.Str ~ ':' ~ $value.^table ~ ':' ~ $value.^as
if $value ~~ $model-type && $value.HOW.^can('table');

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants