You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
repr: unify fixed-width integer types into Int/UInt at the repr layer
Extends the "repr types" approach (where TEXT/VARCHAR/CHAR collapse to a
single ReprScalarType::String once we reach MIR) to the fixed-width
integers. At the repr/MIR layer there are now only two integer types:
Datum::Int16/Int32/Int64 -> Datum::Int(i64)
Datum::UInt8/UInt16/UInt32/UInt64 -> Datum::UInt(u64)
ReprScalarType::{Int16,Int32,Int64} -> ReprScalarType::Int
ReprScalarType::{UInt8,UInt16,UInt32,UInt64} -> ReprScalarType::UInt
SqlScalarType keeps all widths, so OIDs, type names, pg compatibility,
the catalog proto, and the on-disk (Arrow/Parquet) layout are unchanged;
the declared width lives on the column type, not the value.
How it stays low-blast-radius:
- The #[sqlfunc] marshalling (Input/OutputDatumType) narrows on input and
widens on output, and AsColumnType still reports the width-specific SQL
type, so the ~100+ integer arithmetic/cast function bodies are unchanged.
- unwrap_int32 etc. keep their names (narrow with an invariant assert).
- Egress guardrails narrow the unified value back to the declared width at
the Arrow encoder, arrow-util builder, and pgwire (Value::from_datum).
- Row byte-tag encode/decode reads all legacy integer tags (backward
compatible) and writes via the 64-bit variable-length tag families.
Widening cast elision: same-sign widening casts (int2->int4, int2->int8,
int4->int8, and the unsigned analogs) are now is_eliminable_cast, since on
the unified Datum they are the identity; lowering drops them like the
unbounded-VarChar cast. Narrowing and cross-sign casts remain real checked
functions, preserving overflow semantics.
Adds src/sql/tests/int_cast_elimination.rs, an in-process test that lowers
a widening and a narrowing cast and asserts the widening one is eliminated
while the narrowing one is preserved.
KNOWN INCOMPLETE (intentionally pushed for CI):
- Range canonicalization (adt/range.rs) is stubbed to i64: the unified
Datum::Int no longer distinguishes int4range from int8range, which is
wrong at the i32 boundary. This is a pre-existing piece of slop (the only
place an integer Datum tag was semantically load-bearing); the real fix
threads the element SqlScalarType into canonicalize and will land against
main independently.
- Inline #[cfg(test)] modules are not yet migrated off the old Datum
variants, so `cargo test`/`clippy --all-targets` do not build yet; the
workspace library builds clean.
- ~40 SLT EXPLAIN expected outputs (dominated by integer_to_bigint) need
regeneration via --rewrite-results now that widening casts are elided.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments