Repository navigation
Generate and validate the XML documentation - #94
Merged
Merged
Conversation
No project set GenerateDocumentationFile, so the compiler never parsed a doc comment and the package shipped no documentation file. A malformed comment reached #81 and was caught by a reviewer rather than the build, despite TreatWarningsAsErrors. The setting now goes on in Directory.Build.props for every project. Malformed XML and unresolvable crefs are build errors from here, and the packable projects ship their documentation. CS1591 - a public member with no comment - is enforced for Z3.Linq only; the test, examples and demo projects suppress it, each saying why in its project file. Turning it on found three defects this stack had already introduced: the documentation for GetSolution<T> had come loose from its method when two helpers were inserted between them, and was reporting a typeparam and three params that its new host does not have. It is back on the method, with the template parameter it gained in #78. The 21 public members that had no comment - Environment and its members, ExpressionVisitor, the two rewriter interfaces and the three attributes, and Optimization - are documented. Two negative controls confirm the guard has teeth: a broken cref is error CS1574, and a duplicated closing tag in a test remark is error CS1570. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The documentation and build-setting changes have no identified blockers; only an optional wording correction remains.
1 open issue
What changed in this PR
Enables XML documentation generation and validation across the solution, addressing #82 and ensuring packable projects include documentation for consumer IntelliSense. Runtime behavior is unchanged.
Changes:
- Enables documentation generation globally, with CS1591 suppressed only in tests, examples, and the demo.
- Documents previously undocumented public library members.
- Moves the misplaced documentation onto
GetSolution<T>and documents its template parameter.
| File | Description |
|---|---|
| solutions/Z3.Linq/TheoremVariableTypeMappingAttribute.cs | Documents type mapping and constructor requirements. |
| solutions/Z3.Linq/TheoremPredicateRewriterAttribute.cs | Documents predicate rewriter registration. |
| solutions/Z3.Linq/TheoremGlobalRewriterAttribute.cs | Documents global rewriter registration. |
| solutions/Z3.Linq/Theorem.cs | Restores documentation to GetSolution<T>. |
| solutions/Z3.Linq/Optimization.cs | Documents optimization directions. |
| solutions/Z3.Linq/ITheoremPredicateRewriter.cs | Documents the predicate rewriting contract. |
| solutions/Z3.Linq/ITheoremGlobalRewriter.cs | Documents the global rewriting contract. |
| solutions/Z3.Linq/ExpressionVisitor.cs | Describes the translator’s purpose and intended usage. |
| solutions/Z3.Linq/Environment.cs | Documents symbol bindings and object-collection limitations. |
| solutions/Z3.Linq.Tests/Z3.Linq.Tests.csproj | Suppresses missing-documentation warnings for tests. |
| solutions/Z3.Linq.Examples/Z3.Linq.Examples.csproj | Suppresses missing-documentation warnings for samples. |
| solutions/Z3.Linq.Demo/Z3.Linq.Demo.csproj | Suppresses missing-documentation warnings for the demo. |
| solutions/Directory.Build.props | Enables XML documentation generation for all projects. |
Review effort: Balanced
| /// <param name="context">Z3 context.</param> | ||
| /// <param name="model">Z3 model to evaluate theorem parameters under.</param> | ||
| /// <param name="environment">Environment with bindings of theorem variables to Z3 handles.</param> | ||
| /// <param name="template">An instance of <typeparamref name="T"/> whose collections give the solution's their length, or null.</param> |
Member
Author
MikeEvansLarah
approved these changes
Oct 27, 2026
HowardvanRooijen
added a commit
that referenced
this pull request
Oct 28, 2026
* Pin the true arm in the false-branch ternary test The test pinned X1 to -1 and asserted `(X1 > 0 ? X2 : 9) == 9`, leaving X2 free. A translation that always took the true arm would still find a model - X2 = 9 - so the test could not tell the two arms apart, and it was the only ternary test exercising the false arm. X2 is now pinned to 0, which makes the true arm unsatisfiable. Checked by mutation: with the ternary translated as its true arm alone, this test now fails and the other three ternary tests still pass. Found by Copilot review on #99. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Build the Optimize benchmark's objective once Optimize takes an expression tree, so the inline `t => t.X1` built a new tree on every measured invocation and charged its construction and allocation to the solve. Every other benchmark builds its expressions in Setup; the objective is now a field built once, so the Optimize figures measure the same thing as the rest. Found by Copilot review on #104. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Say what the template's collections are for "whose collections give the solution's their length" lost its noun. The template's collections set the lengths of the solution's collections; both GetSolution overloads now say so. Found by Copilot review on #94. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Tell the demos README to populate the Z3 feed first The Microsoft.Z3 version the library needs is not on nuget.org, so restore finds it only in the local _z3-feed folder, which the build script fills. `dotnet run demos/<file>.cs` does not run the build script, so on a clean clone the first demo run fails with NU1102. The README now says to run scripts/Install-Z3Package.ps1 first. Reproduced with an empty _z3-feed and an empty NUGET_PACKAGES folder: restoring demos/sudoku.cs fails with "NU1102: Unable to find package Microsoft.Z3 with version (>= 5.3.2)". Found by Copilot review on #110. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Read a template member only where its value is used The marshaller read every member of the template passed to NewTheorem, scalars included, and handed the value down - but only a collection (for its length) and a nested environment (for its own collections) use it. A scalar getter that threw failed a solve that only needed the setter, and a getter with side effects ran for nothing. ConvertZ3Expression now takes the template instance and reads the member from it in the collection and nested-object branches only. The type is normalised through its TheoremVariableTypeMapping before the branch is chosen, so a mapped scalar is skipped too. The new test counts reads of a scalar getter on the template: one before the change, none after. Found by Copilot review on #93. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fix three bit-vector translations that disagreed with C# All three were introduced with the uint/ulong bit-vector symbols. Shift counts were not masked. C# uses only the low five bits of the count for a uint and the low six for a ulong, so `1u << 32` is 1; Z3 shifts by the whole count and gives 0. The count is now ANDed with the width minus one before the shift. A negative count reaches the mask in two's complement, since the int-to-bit-vector conversion is modulo 2^width, so it matches C# too. A uint beside a ulong threw NotImplementedException. C# widens the uint implicitly, so `t.X1 == t.X2` over Symbols<uint, ulong> was unusable. VisitConvert now zero-extends from 32 to 64 bits, and an explicit `(uint)` cast on a ulong keeps the low 32 bits, as an unchecked cast does. Checked arithmetic wrapped. AddChecked, SubtractChecked and MultiplyChecked shared the wrapping bit-vector form, so `checked(t.X1 + 1u) == 0u` returned uint.MaxValue, a value for which the C# predicate throws OverflowException. These are now refused with a NotSupportedException that says so; overflow checking is not translated. Checked arithmetic on int and real symbols is unchanged. The shift tests take the count as a symbol, so the solver cannot fold it, and compute the expected value with C# from the returned symbols. Found by Copilot review on #101. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Wrap narrowing integer casts, and refuse conversion operators Two ways VisitConvert returned a model the C# predicate rejects, both because it chose the translation from the sorts alone. A narrowing cast between integer types was a no-op. Every integer type but uint and ulong is an unbounded integer in Z3, so `(int)t.X1` on a long symbol kept the long value: `(int)4294967295L` came out as 4294967295 where C# gives -1, and against a bounded int symbol the theorem was reported unsatisfiable. The cast now wraps into the target range, ((x - low) mod n) + low, which is the unchecked C# result for signed and unsigned targets and negative operands alike. A widening cast, and any cast to long, is still a no-op. A checked cast is a ConvertChecked node, which is not translated. A user-defined conversion operator was dropped. For a type mapped to float whose explicit operator to float doubles its value, `(float)t.X1 == 6f` returned a symbol holding 6, which the operator turns into 12. A conversion that calls an operator method is now refused with a NotSupportedException naming the operator, except decimal's built-in conversions, which are operator methods on decimal. A cast to a type with no sort still throws NotImplementedException, as before. The wrap reuses Theorem.GetBounds, which becomes internal, so a conversion and a symbol agree about a type's range. Found by Copilot review on #88 (narrowing) and #92 (operators). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Let a collectible environment type unload The per-type reflection caches - type mappings, public properties and public fields - were static ConcurrentDictionary instances keyed on Type, so they held every environment type they had seen for the life of the library. A host loading environments from a collectible assembly (a plugin it reloads, a script it compiles) could never unload one. They are now ConditionalWeakTable instances, which drop an entry when nothing else holds the type. A cached PropertyInfo or FieldInfo refers back to its declaring type, which a weak table tolerates without keeping the key alive. A weak table's value cannot be null, so an absent mapping is cached as an entry holding null. The new test emits an environment type into a RunAndCollect assembly, solves with it, drops its references and checks that the type is collected. It fails with the dictionaries and passes with the weak tables, so nothing else in the solve path keeps the type alive. Measured with the benchmark suite (--job short), before and after: allocations are identical in every shape (3.3 KB to 6.2 KB per solve), and the differences in mean time are inside the run-to-run noise of a roughly 15 ms solve that Z3 dominates. Found by Copilot review on #105. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 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.

Fixes #82.
The defect
No project set
GenerateDocumentationFile, so the compiler never parsed a doc comment. Twoconsequences: the test suite's documentation - which carries most of the reasoning behind this
stack - was unvalidated, and a malformed comment reached #81 and was caught by a reviewer rather
than the build, despite
TreatWarningsAsErrors; and the package shipped no documentation file,so consumers got no IntelliSense for anything.
What turning it on found first
Measured before any other change, with
-p:GenerateDocumentationFile=trueon the command line:Z3.Linq<param>tags forcontext,modelandenvironmenton a method with no such parametersmemberandinstancewith no tag on the same method<typeparam name="T">on a method with noTThe last three rows are one defect this stack introduced: the documentation for
GetSolution<T>came loose from its method when #75 insertedIsCollectionbetween them, and#78 then inserted
GetMemberValuebefore that - so the block attached toGetMemberValue,describing a
T, acontext, amodeland anenvironmentit does not have. Neither PR couldhave noticed, because nothing parsed the comment. It is back on
GetSolution<T>, with thetemplateparameter it gained in #78. That is the guard proving its worth before it exists.The change
GenerateDocumentationFile=trueinDirectory.Build.props, for every project. Malformed XMLand unresolvable crefs are build errors from here, and the packable projects ship their
documentation. CS1591 is enforced for
Z3.Linqonly; the test, examples and demo projectssuppress it, each with a comment in its own project file saying why - a test's name is its
documentation, sample types are illustrations rather than an API, and the demo is a console
program. That answers the issue's open question about where the settings belong: the setting is
global, the suppression is per project, next to the reason.
The 21 public members are documented.
Environmentand its three members,ExpressionVisitor,ITheoremGlobalRewriterandITheoremPredicateRewriterand their methods,the three attributes with their constructors and properties, and
Optimizationwith both values.Each comment says what the thing is for and, where it matters, when a wrong use fails - a
rewriter type that does not implement the interface is rejected at solve time, not when the
attribute is applied; a predicate rewriter that returns its input is refused; a mapped type
without the right constructor fails when the solution is read.
Environment.IsArraysays plainlythat nothing reads it, and points at #89.
Verification
dotnet build solutions/Z3.Linq.slnx -c Release- clean: 0 warnings, 0 errors, withTreatWarningsAsErrorson and documentation generation on for all four projects./build.ps1 -Configuration Release- 46 tasks, 0 errors, 0 warningslib/net10.0held only the assembly;after,
lib/net10.0holdsZ3.Linq.dlland a 47,833-byteZ3.Linq.xml. Straight from the ZeroFailed pipeline: every earlier package in_packageslists the dll alone, andZ3.Linq.2.0.2-xml-docs.47.nupkglists both.Z3.Linq.Examplesships its 4 KB file tooZ3.Linq.xmldocuments 93 membersNegative controls
Both run against the final code and restored byte-identical afterwards, because a clean build
proves nothing until the check has been seen to fail:
Environmentchanged toExpressionVisitor.NoSuchMembererror CS1574: XML comment has cref attribute 'NoSuchMember' that could not be resolved</remarks>in a test class - the exact defect from #81error CS1570: XML comment has badly formed XML -- 'End tag was not expected at this location.'What this does not catch
Recorded on the issue and worth repeating here: the defect Copilot found on #86 was an inaccurate
<returns>- well-formed XML, resolving crefs, wrong sentence. This setting would not have caughtit and nothing mechanical will. It catches the malformed-XML and broken-reference classes, which
is what it found on #81 and what it found in this stack.
Coverage unchanged at 88.1% line (693 of 786) and 77.5% branch (459 of 592), as it should be for a change that touches no behaviour.
Release note
Releases remain on hold under #60 until Microsoft.Z3 5.x reaches nuget.org. This is the change
the issue asked to have in place before that hold lifts, so the first published 2.x carries its
documentation.