Repository navigation
The parse cache is bypassed while any setting is scoped - #2480
Merged
Merged
Conversation
FromString cached a parse by the string object and returned it under whatever settings were in force later, on any thread, though a literal is rounded as it is parsed: 1e-20 parsed at the defaults stayed 1E-20 inside a PrecisionErrorZeroRange = 1e-10 scope, where the parse is 0, and a parse made inside a scope came back at the defaults. The cache was keyed by ExplicitParsingOnly and DowncastingEnabled only, while the parse also reads PrecisionErrorZeroRange, DecimalPrecisionContext, MaxAbsNumeratorOrDenominatorValue and FloatToRationalIterCount, and computes det, trace, dot, cross, entries and resultant under every setting those read. The cache now holds only parses made with every setting at its default; with a scope of any setting open in the calling flow it is neither read nor written. SettingsState.AnyScopeOpen is one flag read until any scope has ever been opened, then one async-local read per setting that has been scoped. The four tables become one, and ClearFromStringCache now clears all of it (it left the two non-downcasting tables). 0, 1 and -1 with downcasting off are now Real, as the uncached parse gives, where the shortcut answered Integer. Part of #2478 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2480 +/- ##
==========================================
+ Coverage 86.95% 86.96% +0.01%
==========================================
Files 326 326
Lines 72284 72292 +8
Branches 21049 21052 +3
==========================================
+ Hits 62855 62871 +16
+ Misses 5076 5070 -6
+ Partials 4353 4351 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Nov 16, 2026
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.
MathS.FromStringcached parses in process-wide tables keyed by the string's reference and split only byExplicitParsingOnlyandDowncastingEnabled. A parse also depends on settings the key left out, so once a string had been parsed, every later parse of the same string object got that first result, under any settings and on any thread (#2478).The parse reads more settings than any list would stay in step with:
Real.Create:PrecisionErrorZeroRange,DecimalPrecisionContext,MaxAbsNumeratorOrDenominatorValue,FloatToRationalIterCount,DowncastingEnabled;ExplicitParsingOnly;det,transpose,trace,dot,crossand matrix entries (throughInnerSimplified) andresultant(throughMathS.Polynomials.Resultant), which read whatever evaluation and the polynomial code read.So the cache is now neither read nor written while any setting is scoped in the calling flow (
SettingsState.AnyScopeOpen(): one volatile flag read until a scope has ever been opened, then one async-local read per setting ever scoped). Callers at default settings keep the cache. The four tables become one, since the other three were reachable only inside a scope, andClearFromStringCachenow clears all of it (it missed the two non-downcasting tables).<remarks>onFromStringand onSettingssay that inside a scope every call parses afresh.PrecisionErrorZeroRange = 1e-10"1e-20"is1E-200, as the uncached parsePrecisionErrorZeroRange = 1e-10"1e-20"is01E-20DecimalPrecisionContext, 20 digits"0.333333333333333333333333"aReal1/3PrecisionErrorZeroRange = 1e-10"1.00000000001"is1.000000000011MaxAbsNumeratorOrDenominatorValue = 100"0.12345679"is12345679/1000000000.12345679DowncastingEnabledoff"0","1","-1"areInteger(a cache shortcut), every other whole number aRealReal, as the uncached parseRecorded in
BREAKING-CHANGES.md, measured on the 2.7.0 package. Tests inNumericsRegressionTest: ten rows, each parsed defaults-then-scope and scope-then-defaults on a fresh string object and on the interned literal, and a two-thread case in both orders; 10 of the 11 fail on master.UnicodeOutput(#2469) changes printing only, not parsing.The kernel performance gate locally: passed, every gated row at 0.0% allocation; ParseEasy 18,354 → 18,360 and ParseHard 59,449 → 59,472 B/op, under its 128 B floor.
Full check: 20,748 unit tests, 0 failed; MCP 452, Terminal 69, F# 135, Interactive 19; AOT 78/78; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, SimpSweep 10463/10463, RuleCheck clean, CanonCheck, Confluence and ModenovCorpus at their baselines.
Evaled's own cache has the same defect, filed as #2479 and fixed separately.Closes #2478.
🤖 Generated with Claude Code