Skip to content

Conversation

@jongleb
Copy link
Collaborator

@jongleb jongleb commented Dec 24, 2025

Description

This PR eliminates indirection in the parser that previously relied on Parser_state.Dialect_feature to remember dialect-specific tokens for deferred processing. Instead, the frontend AST is now enriched to carry all necessary information directly.

Details

Previously, the parser used a mutable state module Parser_state.Dialect_feature to track dialect-specific features during parsing:
When encountering features like STRAIGHT_JOIN, REPLACE INTO, ON DUPLICATE KEY, collations, unsigned types, etc., the parser would call functions like set_straight_join, set_collation, set_unsigned_types to store feature markers in a global ref
These markers were later processed separately from the AST
This created an indirect flow where AST construction and dialect feature collection were decoupled, making the code harder to reason about and maintain.

Some type information is only relevant for dialect checking and should not propagate into the unification/resolution phase (res_expr) or code generation stage.
For example, UInt32 needs to be tracked for dialect validation, but at runtime it's always represented as int64 in OCaml. We don't want this distinction to leak into type inference or generated code.
To address this, we introduce Source_type.t:

 type kind = Infer of Type.kind | UInt32  type t = { t : kind; nullability : Type.nullability; }   

The naming Source_type (open to discussion) emphasizes that these types exist only at the "source" level — in the frontend AST — and are converted to regular Type.t before entering unification. This keeps dialect-specific details contained in the parsing/validation layer without polluting the core type system.

@jongleb jongleb force-pushed the redisign-dialect-check branch from 204c9e6 to 00542cf Compare December 28, 2025 11:37
@jongleb jongleb force-pushed the redisign-dialect-check branch from 19fa4ca to 37d13ad Compare January 6, 2026 08:02
capture default expr
@jongleb jongleb force-pushed the redisign-dialect-check branch from 37d13ad to ca851a0 Compare January 6, 2026 08:03
@jongleb jongleb requested a review from ygrek January 6, 2026 08:53
@jongleb jongleb marked this pull request as ready for review January 6, 2026 08:53
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