Skip to content

feat(plan): preserve literal numeric precision via raw bytes - #11

Merged
tdakkota merged 1 commit into
mainfrom
feat/literal-raw-precision
Jul 20, 2026
Merged

feat(plan): preserve literal numeric precision via raw bytes#11
tdakkota merged 1 commit into
mainfrom
feat/literal-raw-precision

Conversation

@tdakkota

Copy link
Copy Markdown
Contributor

Summary

Closes #4. Literal dedup was already precise (raw-bytes comparison via internal/jsonequal), but the plan output still lost precision: plan.LiteralCase.Value carries only the decoded float64, so integers past 2^53 and exact decimals were lossy for a backend emitting literals.

frontend.Value.Rawir.Literal.Raw were already preserved; this threads the raw bytes the last mile into the plan.

Changes

  • plan.LiteralCase gains Raw []byte — the exact JSON source bytes (nil for synthesized literals, where Value stays authoritative). This is the single lossy plan-output surface (verified: no Representation carries a const/enum value, and there are no Default/Example fields in plan/).
  • Threaded Raw through the planner's intermediate discCase and all six construction sites: literalCases, propertyDispatchCases, buildLiteralDispatch, buildPropertyDispatch, and both single-const paths in representation.go (buildScalar, buildLiteral). Both LiteralDispatch.Cases and PropertyDispatch.Cases now carry it.

Tests

Three planner tests using 9007199254740993 (2^53 + 1, not float64-representable), covering the bare-const path, the union/discCase path, and numeric property-dispatch cases — each asserts Raw holds the exact bytes.

Out of scope

The dump renderer (internal/dump/plan.go) still prints the decoded Value; left unchanged to keep this surgical (the plan struct is the backend contract, the dump is a debug view). Easy follow-up if raw output in dumps is wanted.

Verification

  • go build ./..., go test ./... (incl. conformance), golangci-lint run ./... → 0 issues

🤖 Generated with Claude Code

Add LiteralCase.Raw (exact JSON source bytes) and thread ir.Literal.Raw
through the planner's discCase and every LiteralCase construction site.
LiteralCase.Value keeps the decoded float64, which is lossy for integers
past 2^53 and exact decimals; a backend can now emit the literal precisely
from Raw. Raw is nil for synthesized literals, where Value stays authoritative.

Closes #4

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.43%. Comparing base (cdebc6a) to head (3a6bf52).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #11      +/-   ##
==========================================
- Coverage   75.54%   75.43%   -0.12%     
==========================================
  Files          42       42              
  Lines        3051     3143      +92     
==========================================
+ Hits         2305     2371      +66     
- Misses        613      629      +16     
- Partials      133      143      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tdakkota
tdakkota merged commit 38e2577 into main Jul 20, 2026
15 checks passed
@tdakkota
tdakkota deleted the feat/literal-raw-precision branch July 20, 2026 14:42
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.

preserve numeric precision of literals in the plan output

1 participant