Skip to content

Merge the scalar and element marshallers into ReadZ3Value - #109

Merged
HowardvanRooijen merged 1 commit into
feature/assert-dispatch-helperfrom
feature/marshalling-reader
Oct 28, 2026
Merged

HowardvanRooijen merged 1 commit into
feature/assert-dispatch-helperfrom
feature/marshalling-reader

Conversation

@HowardvanRooijen

@HowardvanRooijen HowardvanRooijen commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Third and largest of the three flagged dedup refactors, and the one worth the most: reading a solved
symbol back from the Z3 model was written twice - once for a scalar member, once per collection
element - as two ~35-line switch (typeCode) statements that were arm-for-arm identical. Same casts,
same checked integer conversions, same DateTime-from-ticks, same trailing-? decimal-string parse;
they differed only in which Expr they read (val vs the selected element) and which "unsupported
type" message they threw.

One ReadZ3Value(Expr, TypeCode, symbolName, elementType) now owns the reader, and a small
ParseZ3Decimal owns the shared decimal parse. Net -64 lines, and a type that reads back wrong now
has one place to fix rather than two that had to be kept in lock-step (exactly the kind of drift that
produced #55).

  • The element path passes its element type, so the array-specific diagnostic is preserved; null
    there selects the scalar message. No test couples to either message, but both are kept exactly.
  • The collection loop now reads its element type code once, not on every element.

Verified

  • dotnet build solutions/Z3.Linq.slnx -c Release - clean, TreatWarningsAsErrors and documentation
    generation on.
  • 322/322 tests green - every scalar type and every collection-element type is covered, so the
    identical pass is the behaviour-preservation evidence.
  • Mutation check: perturbing the shared Int32 arm (+ 1) fails 111 tests, spanning both the
    scalar and the collection paths - the merged reader is genuinely exercised, and a regression in it
    is caught.
  • Allocation-neutral (the per-arm boxing is unchanged), confirmed with Z3.Linq.Benchmarks
    (short job, MemoryDiagnoser): every shape within run-to-run rounding of its prior figure
    (Collection 4.57 KB, ScalarSymbols 3.30 KB, ...).
  • ./build.ps1 -Configuration Release - 46 tasks, 0 errors, 0 warnings.

No public-API or behaviour change - an internal readability/maintainability refactor. Releases remain
on hold under #60 regardless.

🤖 Generated with Claude Code

Reading a solved symbol back from the model was written twice - once for a
scalar member, once per collection element - as two ~35-line switch statements
that were arm-for-arm identical: the same casts, the same checked conversions,
the same decimal-string handling, differing only in which Expr they read and
which "unsupported type" message they threw. One `ReadZ3Value` now owns the
reader, and a small `ParseZ3Decimal` owns the shared trailing-'?' decimal parse.
Net -64 lines, and a type that reads back wrong now has one place to fix rather
than two to keep in step.

The element path passes its element type so the array-specific diagnostic is
preserved; a null there selects the scalar message. The collection loop reads
its element type code once now, rather than on every element.

Behaviour-preserving:
- 322 tests unchanged.
- A mutation of the shared Int32 arm (+1) fails 111 tests, across both the
  scalar and the collection paths - the reader is exercised, and a regression
  in it is caught.
- Allocation unchanged (the per-arm boxing is the same), confirmed with the
  benchmark suite: every shape within run-to-run rounding of its prior figure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PipoHZJsgydrV3JC3fQN6Q
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Test Results

  1 files    1 suites   10s ⏱️
309 tests 309 ✅ 0 💤 0 ❌
322 runs  322 ✅ 0 💤 0 ❌

Results for commit 8f0659d.

jsboige added a commit to MyIntelligenceAgency/Z3.Linq that referenced this pull request Oct 19, 2026
Cadre G1-bis : verdict des 13 PRs endjin/Z3.Linq post-G1 (commits endjin#100-endjin#112). 3 DIVERGENT + 9 NOUVEAU + 1 REDONDANT. Recommandation G2 : port direct des 3 refactors dedup endjin#107 endjin#108 endjin#109.

Co-Authored-By: Claude Haiku 4.5 (1M context) <noreply@anthropic.com>
@HowardvanRooijen
HowardvanRooijen marked this pull request as ready for review October 27, 2026 07:53
Copilot AI balanced review requested due to automatic review settings October 27, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review supports behavior preservation across both conversion paths, with no unresolved findings; tests were not rerun.

No open issues 🎉

What changed in this PR

This PR consolidates Z3 model-value conversion into one reader shared by scalar symbols and collection elements, reducing duplication while preserving existing behavior and diagnostics.

Changes:

  • Replaces both conversion switches with ReadZ3Value.
  • Extracts shared decimal parsing into ParseZ3Decimal.
  • Computes the collection element type code once before the loop.
File Description
solutions/​Z3.Linq/​Theorem.cs Unifies scalar and element conversion while retaining checked casts, UTC date handling, decimal parsing, and error messages.

Review effort: Balanced

@HowardvanRooijen HowardvanRooijen added no_release Suppresses auto_release functionality and removed pending_release labels Oct 27, 2026
@HowardvanRooijen
HowardvanRooijen merged commit c2be553 into main Oct 28, 2026
12 checks passed
@HowardvanRooijen
HowardvanRooijen deleted the feature/marshalling-reader branch October 28, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no_release Suppresses auto_release functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants