Skip to content

The parse cache is bypassed while any setting is scoped - #2480

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fix/parse-cache-under-settings
Nov 16, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
fix/parse-cache-under-settings

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

MathS.FromString cached parses in process-wide tables keyed by the string's reference and split only by ExplicitParsingOnly and DowncastingEnabled. 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:

  • a literal's downcast in Real.Create: PrecisionErrorZeroRange, DecimalPrecisionContext, MaxAbsNumeratorOrDenominatorValue, FloatToRationalIterCount, DowncastingEnabled;
  • the parser itself: ExplicitParsingOnly;
  • what is computed while parsing: det, transpose, trace, dot, cross and matrix entries (through InnerSimplified) and resultant (through MathS.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, and ClearFromStringCache now clears all of it (it missed the two non-downcasting tables). <remarks> on FromString and on Settings say that inside a scope every call parses afresh.

string object parsed first under then under was (2.7.0) now
defaults PrecisionErrorZeroRange = 1e-10 "1e-20" is 1E-20 0, as the uncached parse
PrecisionErrorZeroRange = 1e-10 defaults "1e-20" is 0 1E-20
defaults DecimalPrecisionContext, 20 digits "0.333333333333333333333333" a Real 1/3
defaults PrecisionErrorZeroRange = 1e-10 "1.00000000001" is 1.00000000001 1
defaults MaxAbsNumeratorOrDenominatorValue = 100 "0.12345679" is 12345679/100000000 0.12345679
— DowncastingEnabled off "0", "1", "-1" are Integer (a cache shortcut), every other whole number a Real Real, as the uncached parse

Recorded in BREAKING-CHANGES.md, measured on the 2.7.0 package. Tests in NumericsRegressionTest: 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

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

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.96%. Comparing base (147ac04) to head (976c1dd).

Files with missing lines Patch % Lines
...ience/UnsafeAndInternal/MathS.UnsafeAndInternal.cs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.49% <95.83%> (+0.01%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 39.95% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 91.42% <100.00%> (+0.48%) ⬆️
Sources/AngouriMath/Convenience/SettingClass.cs 93.90% <100.00%> (+1.04%) ⬆️
...ience/UnsafeAndInternal/MathS.UnsafeAndInternal.cs 72.72% <0.00%> (ø)

... and 7 files with indirect coverage changes

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

@Rafael-SOWNet
Rafael-SOWNet merged commit 31cc3f0 into master Nov 16, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 16, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix/parse-cache-under-settings branch November 16, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The parse cache returns a literal parsed under other precision settings

1 participant