Skip to content

Lift the alias and quoting traits into the vocabulary layer - #1553

Draft
trueqbit wants to merge 11 commits into
refactor/operators-under-astfrom
refactor/lift-alias-and-quoting-traits
Draft

trueqbit wants to merge 11 commits into
refactor/operators-under-astfrom
refactor/lift-alias-and-quoting-traits

Conversation

@trueqbit

@trueqbit trueqbit commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1552.

Summary

The open-work item "lift the remaining traits into the vocabulary layer" of docs/internals/vocabulary-layer.md, for everything below ast/: the alias traits and those of table references, table-valued expressions and literals were declared and defined in their own headers, alias_holder and alias_column_t had no trait, and consumers pattern-matched them - along with column_pointer.

  • alias.h, column_pointer.h, literal.h and table_reference.h move to dev/ast/.
  • Declared in grammar_traits_fwd.h (new "Alias traits" section): is_alias, is_column_alias, is_recordset_alias, is_table_alias, is_cte_moniker, is_table_valued_expression, and the new is_alias_holder and is_alias_column. Declared in structural_traits_fwd.h (quoting): is_literal, is_table_reference. The alias traits stay defined in alias_traits.h next to alias_tag, since aliases are user-definable rather than sqlite_orm nodes; the others are defined right after their nodes.
  • Consumers now matching by trait: node_tuple (column alias and alias holder in one, table-valued expression), column_result_t (alias column, column pointer), statement_serializer (alias holder, column alias, alias column), ast_iterator, cte_storage.h, cte_column_names_collector.h, table_name_collector.h, storage_impl.h (materialize_column_pointer(), find_column_name()), the multi ORDER BY streaming in serializing_util.h, and unpacked_arg in ast/app_function.h.
  • The column pointer referring to a CTE column alias used to be a partial specialization refining the one for column_pointer<T, F> (in column_result_t, and as overloads in storage_impl.h) - which is why they matched the template rather than a trait. They are now told apart by the column pointer's field_type being an alias holder.
  • Fix: the type trait is_column_alias derived from is_alias, and thus held for record set aliases as well, unlike is_column_alias_v. It now agrees with the variable template - which affects as<A>(), explicit CTE columns and the ast_iterator skipping aliases, none of which is meant to see a record set alias.
  • The open-work item is closed. Neither remaining is_*_v belongs in the traits layer: is_rtree_table_element_or_constraint is an admissibility composite and moves beside its base and FTS5 siblings in vocabulary/algorithms/ddl_predicates.h, and is_dbo_name_literal_v recognizes a reflection annotation that never becomes a node, so it stays in schema/dbo_name.h. The guidance on which is_*_v qualify moves to "Deciding where something goes".

Test plan

  • tests/static_tests/expression_classification.cpp: new "aliases and quoting" section - the alias traits including is_column_alias against a record set alias, is_alias_holder, is_alias_column, is_literal, is_table_reference, is_table_valued_expression, and the node tuples of a column alias and an alias holder.
  • The CTE, alias and column pointer static tests and the CTE storage tests exercise the rewritten column pointer paths.

🤖 Generated with Claude Code

@trueqbit
trueqbit force-pushed the refactor/operators-under-ast branch from 7732cd7 to 70022e6 Compare September 28, 2026 17:00
@trueqbit
trueqbit force-pushed the refactor/lift-alias-and-quoting-traits branch 3 times, most recently from e07344d to 0d8f0c5 Compare September 28, 2026 17:14
The alias traits and those of the table reference, table-valued
expression and literal were declared and defined in their own headers,
alias_holder and alias_column_t had no trait at all, and the consumers
pattern-matched them along with column_pointer.

- alias.h, column_pointer.h, literal.h and table_reference.h move to ast/.
- `is_alias`, `is_column_alias`, `is_recordset_alias`, `is_table_alias`,
  `is_cte_moniker` and `is_table_valued_expression` are declared in
  grammar_traits_fwd.h, `is_literal` and `is_table_reference` in
  structural_traits_fwd.h; the alias traits stay defined next to
  `alias_tag`, since aliases are user-definable.
- New grammar traits `is_alias_holder` and `is_alias_column`.
- node_tuple, column_result_t, statement_serializer, the CTE storage, the
  table name and CTE column name collectors, `materialize_column_pointer()`
  and `find_column_name()`, the multi ORDER BY streaming and
  `unpacked_arg` match by trait. The column pointer referring to a CTE
  column alias is told apart by its `field_type`, no longer by a
  partial specialization refining the one for column pointers.
- Fix: the type trait `is_column_alias` derived from `is_alias`, and thus
  held for record set aliases too, unlike `is_column_alias_v`.

Co-Authored-By: Claude Opus 5.5
@trueqbit
trueqbit force-pushed the refactor/lift-alias-and-quoting-traits branch from 0d8f0c5 to ec16f4e Compare September 28, 2026 17:32
…and-quoting-traits

Co-Authored-By: Claude Opus 5.5
The serializer was the last consumer still matching `literal_holder` by
its template; it now goes by `is_literal` like the other consumers.

Co-Authored-By: Claude Opus 5
`is_rtree_table_element_or_constraint_v` is an admissibility composite
over `is_column`, like the base and FTS5 table checks; it now lives as an
alias beside them in `vocabulary/algorithms/ddl_predicates.h`.

That leaves nothing of the open-work item about schema-level traits:
`is_dbo_name_literal_v` recognizes a reflection annotation that is read
out and filtered away while a table or view definition is built, and
never becomes a node, so it stays with the code consuming it. The
guidance on which `is_*_v` belong in the layer moves to "Deciding where
something goes", without the removed `is_builtin_window_function_v`.

Co-Authored-By: Claude Opus 5
…and-quoting-traits

Resolved:
- This branch moved alias.h, column_pointer.h, literal.h and
  table_reference.h into ast/, while dev moved the vtabs/ headers and the
  schema table into builtin/dbos/ and split core_functions.h into
  builtin/functions/. Includes of the four headers take dev's location of
  the including file and this branch's location of the included one - in
  builtin/dbos/, builtin/functions/core.h and the ast/ headers.
- core_functions.h, whose includes this branch adjusted, is gone on dev.
- column_expression.h includes ast/alias.h and, for
  schema_mapped_column_field_expressions, schema/algorithms/table_lookup.h.
- The vocabulary doc's open-work section loses both the trait lift, done
  here, and storage_traits.h, done on dev.

Co-Authored-By: Claude Opus 5.5
…and-quoting-traits

The merged branches bring dev's move of the statement serializer and its
helpers into serialization/ (#1562).

Resolved:
- serializing_util.h, statement_serializer.h and table_name_collector.h
  take their paths relative to serialization/, and include alias.h,
  column_pointer.h, literal.h and table_reference.h from ast/, where this
  branch moved them.
- cte_column_names_collector.h, which this branch adjusted at its old
  place, was rewritten and moved by #1562: its new version includes
  ast/alias.h and tests is_alias_holder_v, like this branch's.

Co-Authored-By: Claude Opus 5.5
…and-quoting-traits

Co-Authored-By: Claude Opus 5.5
…and-quoting-traits

Co-Authored-By: Claude Opus 5.5
…and-quoting-traits

# Conflicts:
#	dev/ast_iterator.h
#	include/sqlite_orm/sqlite_orm.h

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.

1 participant