Repository navigation
ir: one decimal-literal grammar for BigVal, bound comparison and YAML integers #786
Copy link
Copy link
Closed
Labels
priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatsRefactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatstype:choreRefactor or cleanup, no behavior changeRefactor or cleanup, no behavior change
Description
Problem
The grammar of a decimal numeric literal is scanned in three places, and the comments in two of them say they have drifted before.
ir/bigval.go:isDecimalLiteral,scanMantissa,scanExponentandcanonicalDecimalvalidate and canonicalize forNewBigVal.compilers/openapi/internal/annotation/decimal.go:parseDecimalBoundsplits sign, digits and exponent a second time forBigValEqual. Its doc says "the two grammars live in different packages and have already moved apart once", andTestBigValGrammarStaysWithinTheDecimalReadingexists to hold them together.compilers/openapi/internal/value/value.go:isPlainDecimaldecides which!!intspellings are already base 10.
ir/irverify/bigval.go re-checks through NewBigVal, so it is not a fourth copy.
A grammar with one definition and derived predicates cannot disagree with itself; a grammar scanned three times needs a test that it still agrees.
Constraints
irimports the standard library only, so the shared piece lives inirand is stdlib-only. That also rules out a decimal library for the grammar itself.- Comparison must stay total for exponents
math/bigwill not build:1e1000001is legal in a spec, and openapi/merge: equal bounds past big.Rat's range are reported as a conflict #287 was a conflict reported for equal bounds pastbig.Rat's range. The comparison reads sign, digits and exponent; it never materializes10^exp. NewBigValkeeps preserving every significant digit and the exponent's text; only JSON-invalid affixes are normalized.
Proposed direction
ir exposes one parse of a validated literal into its sign, significant digits and decimal exponent. NewBigVal's canonical form, an ordering (Cmp or equivalent) and the equality BigValEqual needs all derive from it. annotation/decimal.go keeps no scanner. isPlainDecimal either uses the same parse or states why a YAML base prefix makes it a different question.
Acceptance
- One scanner remains in the repository;
grep -rn 'scanMantissa\|parseDecimalBound' --include='*.go' .finds one definition. - A fuzz test compares the ordering against
big.Ratover inputs whose exponentsbig.Ratcan build, and against sign/exponent reasoning beyond them. 1e1000001,10e1000000,-0.0,5e1and50keep their current equalities.- Exported
iradditions are additive; no existing signature changes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatsRefactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatstype:choreRefactor or cleanup, no behavior changeRefactor or cleanup, no behavior change
Activity