Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
952692a
Migrate build from Endjin.RecommendedPractices.Build to ZeroFailed (#44)
HowardvanRooijen Oct 28, 2026
79d30a7
Modernise solution: .NET 10, Central Package Management, .slnx (#45)
HowardvanRooijen Oct 28, 2026
ee509f8
Update MiaPlaza.ExpressionUtils to 1.3.1 and adapt to its breaking ch…
HowardvanRooijen Oct 28, 2026
363260f
Update Microsoft.Z3 to 5.1.0 for Linux and arm64 native binaries (#61)
HowardvanRooijen Oct 28, 2026
5c4137d
Add Z3.Linq.Tests covering the Distinct partial-evaluation path (#48)
HowardvanRooijen Oct 28, 2026
205c3c2
Add core solve and composition tests (test suite phase A) (#59)
HowardvanRooijen Oct 28, 2026
bf752b0
Add type marshalling tests for symbols, collections and environment s…
HowardvanRooijen Oct 28, 2026
055a209
Add optimisation tests for Optimize, OrderBy and OrderByDescending (#67)
HowardvanRooijen Oct 28, 2026
d432370
Add failure mode and rewriter tests (#69)
HowardvanRooijen Oct 28, 2026
7fff5d3
Add acceptance tests for the Sudoku and river crossing samples (#71)
HowardvanRooijen Oct 28, 2026
595b394
Populate symbols the solver leaves uninterpreted (#73)
HowardvanRooijen Oct 28, 2026
63e044a
Drop the constraints that only existed to dodge #51 (#74)
HowardvanRooijen Oct 28, 2026
72ae9ca
Render real constants invariantly (#77)
HowardvanRooijen Oct 28, 2026
45425b9
Read the value a collection field holds (#79)
HowardvanRooijen Oct 28, 2026
de71f72
Read a float symbol back as a float (#80)
HowardvanRooijen Oct 28, 2026
67fe574
Read the decimal element the loop selected (#81)
HowardvanRooijen Oct 28, 2026
aa95063
Read a DateTime back as UTC (#84)
HowardvanRooijen Oct 28, 2026
e28eeb3
Report satisfiability separately from the solution (#86)
HowardvanRooijen Oct 28, 2026
ed8eb9b
Make short and enum symbols work (#88)
HowardvanRooijen Oct 28, 2026
ee3348d
Give collections the same sorts as scalars (#90)
HowardvanRooijen Oct 28, 2026
4b91def
Marshal anonymous environments like every other shape (#91)
HowardvanRooijen Oct 28, 2026
a328370
Choose numeric conversions by sort, not by target type (#92)
HowardvanRooijen Oct 28, 2026
af96b87
Size collections from the instance passed to NewTheorem (#93)
HowardvanRooijen Oct 28, 2026
16ce65d
Generate and validate the XML documentation (#94)
HowardvanRooijen Oct 28, 2026
cd4b2b5
Encode a DateTime as ticks rather than a file time (#95)
HowardvanRooijen Oct 28, 2026
b043c53
Let a solve be bounded, and say when Z3 could not decide (#96)
HowardvanRooijen Oct 28, 2026
c09327d
Bound each integer symbol to the range of its type (#98)
HowardvanRooijen Oct 28, 2026
f3ac450
Translate ternaries, and stop crashing on bitwise and real modulo (#99)
HowardvanRooijen Oct 28, 2026
cc89278
Make the expression visitor an internal instance class (#100)
HowardvanRooijen Oct 28, 2026
2ed9e9e
Support uint and ulong as bit-vector symbols (#101)
HowardvanRooijen Oct 28, 2026
0245182
Support byte, sbyte and ushort as bounded integer symbols (#102)
HowardvanRooijen Oct 28, 2026
4d02e08
Fix two defects in the solve-limits code found by review (#103)
HowardvanRooijen Oct 28, 2026
6b31b95
Add a BenchmarkDotNet suite for solve hot paths (#104)
HowardvanRooijen Oct 28, 2026
a3d060f
Cut per-solve managed allocations by caching per-type reflection (#105)
HowardvanRooijen Oct 28, 2026
5d9f02c
Modernise the solve path with C# 14 idioms (#106)
HowardvanRooijen Oct 28, 2026
25e202b
Extract MemberClrType for the property/field type switch (#107)
HowardvanRooijen Oct 28, 2026
a49ab51
Extract Assert for the Solver/Optimize dispatch (#108)
HowardvanRooijen Oct 28, 2026
c2be553
Merge the scalar and element marshallers into ReadZ3Value (#109)
HowardvanRooijen Oct 28, 2026
27b8c45
Convert the demos to single-file Spectre.Console apps (#110)
HowardvanRooijen Oct 28, 2026
7dbf6a7
Update Microsoft.Z3 to 5.3.2, and MSTest.Sdk and code coverage to the…
HowardvanRooijen Oct 28, 2026
8483d3d
Address the Copilot review findings on #88-#110 (#116)
HowardvanRooijen Oct 28, 2026
ea3f09f
Truncate a real-to-integer cast toward zero (#117)
HowardvanRooijen Oct 28, 2026
964f177
Read static members and captured member chains as constants (#118)
HowardvanRooijen Oct 28, 2026
92f8ff1
Merge endjin/main into resync/endjin-main-964f177
jsboige Nov 24, 2026
5071d6f
Docs: record consumer validation and mapped-conversion PR
jsboige Nov 24, 2026
87dbb66
Merge branch 'main' into resync/endjin-main-964f177
jsboige Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .deploy/Microsoft.Z3.dll
Binary file not shown.
Binary file modified .deploy/Z3.Linq.dll
Binary file not shown.
Binary file modified .deploy/libz3.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion .zf/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $SkipTestReport = $false
$SkipAnalysis = $false
$SkipPackage = $false

# Releases are ON HOLD. The build uses Microsoft.Z3 5.1.0 for its Linux and arm64 native
# Releases are ON HOLD. The build uses Microsoft.Z3 5.3.2 for its Linux and arm64 native
# binaries, but that version is not on nuget.org, so a published Z3.Linq would declare a
# dependency no consumer can restore (NU1102). Lift this once Microsoft.Z3 5.x is published -
# see https://github.com/endjin/Z3.Linq/issues/60 and https://github.com/Z3Prover/z3/issues/10711
Expand Down
242 changes: 114 additions & 128 deletions DIVERGENCE_STATUS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"runner": "Microsoft.Testing.Platform"
},
"msbuild-sdks": {
"MSTest.Sdk": "4.3.3"
"MSTest.Sdk": "4.5.1"
}
}
4 changes: 2 additions & 2 deletions scripts/Install-Z3Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
[CmdletBinding()]
param (
[Parameter()]
[string] $Version = '5.1.0',
[string] $Version = '5.3.2',

[Parameter()]
[string] $ExpectedHash = 'D808E6BD31D96895ECA446ECEB37E90DD24480B0D9B5F513113F3E2FD312ABF2',
[string] $ExpectedHash = '7DDF59F33CB6785C439186638450670AF450131B603CD07ABE116A75E4EC75F0',

[Parameter()]
[string] $FeedPath = (Join-Path $PSScriptRoot '..' '_z3-feed')
Expand Down
4 changes: 2 additions & 2 deletions solutions/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- Deliberately no PlatformTarget. Microsoft.Z3 5.1.0 ships native binaries for x64
<!-- Deliberately no PlatformTarget. Microsoft.Z3 5.3.2 ships native binaries for x64
and arm64 on all three platforms, so AnyCPU lets each machine resolve the one it
needs; pinning x64 here would shut arm64 out. -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down Expand Up @@ -53,6 +53,6 @@
NU1506 on restore.
-->
<PropertyGroup>
<MicrosoftTestingExtensionsCodeCoverageVersion>18.10.0</MicrosoftTestingExtensionsCodeCoverageVersion>
<MicrosoftTestingExtensionsCodeCoverageVersion>18.12.0</MicrosoftTestingExtensionsCodeCoverageVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion solutions/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
osx-arm64, win-x64 and win-arm64. It is downloaded into the local folder feed by
scripts/Install-Z3Package.ps1, which pins the version and its SHA-256 hash -
change both together with this one. -->
<PackageVersion Include="Microsoft.Z3" Version="5.1.0" />
<PackageVersion Include="Microsoft.Z3" Version="5.3.2" />
</ItemGroup>

<ItemGroup Label="Testing">
Expand Down
9 changes: 8 additions & 1 deletion solutions/Z3.Linq.Benchmarks/SolveBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Z3.Linq.Benchmarks;

using System.Linq.Expressions;

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
Expand Down Expand Up @@ -63,6 +65,11 @@ public InProcessShortConfig()
private Theorem<Symbols<int, int, int, int, int>> wide = null!;
private Theorem<Symbols<int, int>> optimizeSource = null!;

// Optimize takes an expression tree, so a lambda written inline in the benchmark would build a
// new tree on every invocation and count that construction against the solve. Built once here,
// like the constraints in Setup.
private readonly Expression<Func<Symbols<int, int>, int>> optimizeObjective = t => t.X1;

[GlobalSetup]
public void Setup()
{
Expand Down Expand Up @@ -142,7 +149,7 @@ public void Cleanup()
[Benchmark]
public Symbols<int, int>? Optimize()
{
return this.optimizeSource.Optimize(Optimization.Maximize, t => t.X1);
return this.optimizeSource.Optimize(Optimization.Maximize, this.optimizeObjective);
}

private sealed class NestedEnvironment
Expand Down
87 changes: 87 additions & 0 deletions solutions/Z3.Linq.Tests/CollectibleTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace Z3.Linq.Tests;

using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

/// <summary>
/// Solving with an environment type from a collectible assembly does not keep that assembly
/// alive.
/// </summary>
/// <remarks>
/// The library caches per-type reflection - mapping attributes, public properties and fields - for
/// the life of the process. A cache keyed strongly on <see cref="Type"/> holds every environment
/// type it has seen, so a host that loads environments from a collectible assembly (a plugin it
/// reloads, a script it compiles) could never unload one. The environment type here is emitted into
/// a <see cref="AssemblyBuilderAccess.RunAndCollect"/> assembly, solved once, and then every
/// reference the test holds is dropped; the assembly must then be collectable.
/// </remarks>
[TestClass]
public class CollectibleTypeTests
{
[TestMethod]
public void Solve_EnvironmentFromACollectibleAssembly_LetsTheAssemblyBeCollected()
{
// Arrange & Act
WeakReference environment = SolveWithACollectibleEnvironment();

for (int i = 0; i < 10 && environment.IsAlive; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

// Assert
environment.IsAlive.ShouldBeFalse();
}

// Not inlined, so no reference to the emitted type or its assembly survives on this frame.
[MethodImpl(MethodImplOptions.NoInlining)]
private static WeakReference SolveWithACollectibleEnvironment()
{
AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(
new AssemblyName($"CollectibleEnvironment{Guid.NewGuid():N}"),
AssemblyBuilderAccess.RunAndCollect);

TypeBuilder builder = assembly.DefineDynamicModule("Module").DefineType("Environment", TypeAttributes.Public | TypeAttributes.Class);
builder.DefineField("X", typeof(int), FieldAttributes.Public);
builder.DefineDefaultConstructor(MethodAttributes.Public);
Type environment = builder.CreateType();

object solution = Solve(environment);

// The solve really ran against the emitted type, so its members went through the caches.
environment.GetField("X")!.GetValue(solution).ShouldBe(42);

// The type, not the AssemblyBuilder: the builder is a wrapper that can be collected while
// the runtime assembly behind it stays loaded.
return new WeakReference(environment);
}

private static object Solve(Type environment)
{
using var context = new Z3Context();

// t => t.X == 42, built by hand because the type does not exist at compile time.
ParameterExpression t = Expression.Parameter(environment, "t");
LambdaExpression constraint = Expression.Lambda(
typeof(Func<,>).MakeGenericType(environment, typeof(bool)),
Expression.Equal(Expression.Field(t, "X"), Expression.Constant(42)),
t);

object theorem = typeof(Z3Context)
.GetMethod(nameof(Z3Context.NewTheorem), Type.EmptyTypes)!
.MakeGenericMethod(environment)
.Invoke(context, null)!;

object constrained = theorem.GetType().GetMethod("Where")!.Invoke(theorem, [constraint])!;

// The fork adds a second Solve overload that inspects the model (Solve with an
// Action<ModelWitness<T>>), so a name-only lookup is ambiguous here. The parameterless
// solve the test means is the one taking only a CancellationToken: select it by signature.
return constrained.GetType()
.GetMethod("Solve", [typeof(CancellationToken)])!
.Invoke(constrained, [default(CancellationToken)])!;
}
}
51 changes: 51 additions & 0 deletions solutions/Z3.Linq.Tests/CollectionSymbolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,36 @@ public void Solve_TemplateElementValues_DoNotReachTheSolution()
template.Values.ShouldBe([99, 99]);
}

/// <summary>
/// A scalar member's getter on the template is never called.
/// </summary>
/// <remarks>
/// The template supplies only lengths, for collections and the collections of nested
/// environments, so a scalar member's value on it is of no use. Reading it anyway runs a getter
/// that may throw or have side effects, and makes such a getter fail a solve that only needs
/// its setter.
/// </remarks>
[TestMethod]
public void Solve_TemplateWithAScalarMember_DoesNotReadTheScalarGetter()
{
// Arrange
using var context = new Z3Context();
var template = new WatchedScalarEnvironment { Values = new int[2] };

// Act
var result = context.NewTheorem(template)
.Where(t => t.Values[1] == 3)
.Where(t => t.Watched == 7)
.Solve();

// Assert
result.ShouldNotBeNull();
result.Values.Length.ShouldBe(2);
result.Values[1].ShouldBe(3);
result.Watched.ShouldBe(7);
template.WatchedReads.ShouldBe(0);
}

/// <summary>
/// The template survives <c>Where</c> and <c>OrderBy</c>.
/// </summary>
Expand Down Expand Up @@ -1217,6 +1247,27 @@ private sealed class IntArrayEnvironment
public int Length { get; set; }
}

private sealed class WatchedScalarEnvironment
{
private int watched;

public int[] Values { get; set; } = [];

public int Watched
{
get
{
this.WatchedReads++;
return this.watched;
}

set => this.watched = value;
}

// Not public, so not a symbol: the library walks public instance members only.
internal int WatchedReads { get; private set; }
}

private sealed class IntListEnvironment
{
public List<int> Values { get; set; } = [0, 0];
Expand Down
Loading
Loading