Repository navigation
Make the expression visitor an internal instance class - #100
Merged
HowardvanRooijen merged 1 commit intoOct 28, 2026
Merged
HowardvanRooijen merged 1 commit into
HowardvanRooijen merged 1 commit into
Conversation
ExpressionVisitor was a public static class that threaded the Z3 context, the environment, and the constraint lambda's parameter through every method - four arguments on each, of which three are invariant for the whole translation. It is now an internal sealed class that holds those three as readonly fields, set once by a static Translate entry point, so the Visit* methods take only the node they translate. The dispatch lambdas still take the context, so they stay non-capturing and compiler-cached rather than allocating per node. Behaviour is unchanged - the 290 tests pass as before; this is a shape and visibility change, the visibility being the point: the class was public "for historical reasons" with no supported reason to call it, and the .NET 10 major version is the moment to stop shipping it as API. Nothing outside the assembly referenced it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
marked this pull request as ready for review
October 27, 2026 07:53
There was a problem hiding this comment.
🟢 Approval recommended
The mechanical refactor preserves translation logic, updates both call sites, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Refactors constraint translation into an internal instance-based visitor, completing the structural follow-up to #99 while preserving translation behavior. The visibility change intentionally removes an unsupported public type for the major release.
Changes:
- Stores translation context in readonly instance fields behind a static
Translateentry point. - Updates both
Theoremcall sites while retaining non-capturing dispatch lambdas and staticToUtcTicks. - Revises documentation to reflect the visitor’s new structure.
| File | Description |
|---|---|
| solutions/Z3.Linq/Theorem.cs | Routes constraint and optimization translation through Translate. |
| solutions/Z3.Linq/ExpressionVisitor.cs | Converts the static visitor into an internal sealed instance class. |
| solutions/Z3.Linq/Environment.cs | Removes the obsolete ExpressionVisitor.Visit documentation reference. |
Review effort: Balanced
MikeEvansLarah
approved these changes
Oct 27, 2026
jsboige
pushed a commit
to MyIntelligenceAgency/Z3.Linq
that referenced
this pull request
Nov 4, 2026
Build green (0 warnings under TreatWarningsAsErrors), 371/372 tests passing. Aligns the rebased partial-eval branch with the newer upstream base: GetEnvironment/GetSolution call sites after the expression-visitor rewrite (endjin#100); ExtractCollection now uses upstream template-length sizing, the complete ReadZ3Value scalar conversion, EvaluateWithCompletion for free elements, and the no-length NotSupportedException parity. Keystone CollectionHandling tests moved to MSTest.Sdk/Shouldly. One expected failure remains: Solve_MemberChainThroughANull_ThrowsNamingTheExpression (endjin#118) - the global PartialEval fold preempts the null member-chain path. Co-Authored-By: Claude-Code <noreply@anthropic.com>
jsboige
added a commit
to MyIntelligenceAgency/Z3.Linq
that referenced
this pull request
Nov 5, 2026
Rebase onto current main (964f177, including the endjin#100 expression-visitor rewrite and endjin#118) and port the xUnit smoke suite to MSTest/MTP + Shouldly, aligned with the rest of the solution, as requested in review. The ten facts keep their semantics: integer and boolean symbols over anonymous-type environments, chained Where constraints, tuple readback, contradiction-to-null, Distinct, and Optimize in both directions. The xUnit project is gone - the tests now live in the existing MTP test project as a single file, so the PR adds coverage without a second harness. Measured: full suite 378/378 passing (368 on main + these 10), 4.9s; BasicTheoremTests alone 10/10, 328ms. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
The first of the two follow-ups #99 listed: turn
ExpressionVisitorinto an internal instanceclass. Behaviour-preserving; the visibility change is a deliberate break for the major version.
The change
ExpressionVisitorwas apublic static classwhose every method threaded four arguments -(Context context, Environment environment, …, ParameterExpression param)- of which three areinvariant for the whole translation of one constraint. It is now an
internal sealed classthatholds those three as
readonlyfields, constructed once by a staticTranslateentry point:so the
Visit*methods take only the node they translate.TheoremcallsTranslateat its twosites; nothing else changes.
Two details kept deliberately:
Context(static (ctx, a, b) => ctx.MkAdd(…)), so theyremain non-capturing and are cached by the compiler in a static field rather than allocated per
node. Making
contexta field did not tempt them into closures.ToUtcTicksstaysinternal static- it depends on nothing instance-level andTheorem'sread path refers to it by name.
Why
internalThe class was
public"for historical reasons," and its own doc said there was no supportedreason to call it. Since #82 the package ships its types and their IntelliSense, so that
non-API was visible to consumers. The .NET 10 major version is the window to stop exposing it.
Confirmed nothing outside the assembly referenced it - the only mentions in tests are line-number
comments, not calls - so this breaks no caller in the repository, and
Theorem(same assembly)is unaffected.
Verification
dotnet build solutions/Z3.Linq.slnx -c Release- clean,TreatWarningsAsErrorsanddocumentation generation on;
ExpressionVisitoris nowinternal sealedrefactor: same tests, same results, only the shape and visibility moved
./build.ps1 -Configuration Release- 46 tasks, 0 errors, 0 warningsNo new tests: there is no new behaviour to pin, and the existing suite already exercises every
Visit*path. A reflection test asserting the type isinternalwould only restate the compiler'sown enforcement.
The other follow-up, still open
Bit-vector symbols - what would make integer bitwise (
&/|/^) and shifts actually workrather than be refused, as #99 diagnosed them. That is a feature in its own right, with a design
decision to make first (how a caller opts a symbol into a fixed-width bit-vector, and its width),
so it is not folded in here.
Release note
Releases remain on hold under #60 until Microsoft.Z3 5.x reaches nuget.org, so this reaches
mainbut not consumers. The public-API surface shrinks by one type (
ExpressionVisitor), which themajor version accommodates.