feat(plan): preserve literal numeric precision via raw bytes - #11
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #4. Literal dedup was already precise (raw-bytes comparison via
internal/jsonequal), but the plan output still lost precision:plan.LiteralCase.Valuecarries only the decodedfloat64, so integers past 2^53 and exact decimals were lossy for a backend emitting literals.frontend.Value.Raw→ir.Literal.Rawwere already preserved; this threads the raw bytes the last mile into the plan.Changes
plan.LiteralCasegainsRaw []byte— the exact JSON source bytes (nil for synthesized literals, whereValuestays authoritative). This is the single lossy plan-output surface (verified: noRepresentationcarries a const/enum value, and there are noDefault/Examplefields inplan/).Rawthrough the planner's intermediatediscCaseand all six construction sites:literalCases,propertyDispatchCases,buildLiteralDispatch,buildPropertyDispatch, and both single-const paths inrepresentation.go(buildScalar,buildLiteral). BothLiteralDispatch.CasesandPropertyDispatch.Casesnow carry it.Tests
Three planner tests using
9007199254740993(2^53 + 1, not float64-representable), covering the bare-const path, the union/discCasepath, and numeric property-dispatch cases — each assertsRawholds the exact bytes.Out of scope
The dump renderer (
internal/dump/plan.go) still prints the decodedValue; 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