Make the expression visitor an internal instance class - #100
Draft
HowardvanRooijen wants to merge 1 commit into
Draft
HowardvanRooijen wants to merge 1 commit into
HowardvanRooijen wants to merge 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>
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.