Skip to content

Commit 25837d5

Browse files
committed
ConformExhaustive more parallel
1 parent 0897ba2 commit 25837d5

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎CsCheck/Spec.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,19 +2000,19 @@ static string SutClause<TSut>()
20002000
/// <param name="writeLine">WriteLine function for the report.</param>
20012001
/// <param name="maxStates">Give up after this many distinct states (default 10,000,000). The states reached before then are still conformed, but the report is not closed.</param>
20022002
/// <param name="maxDepth">Stop after this many steps from the initial state. The states short of it are still conformed, but the report is not closed.</param>
2003-
/// <param name="threads">The number of threads to drive the implementation on (default number logical CPUs), so <paramref name="create"/>, <paramref name="apply"/> and <paramref name="clone"/> must be safe to call on different instances at once, as for Conform. The model is explored on one thread first. Results do not depend on it.</param>
2003+
/// <param name="threads">The number of threads to explore the model and drive the implementation on (default number logical CPUs), so the specification's delegates and the state's Equals and GetHashCode must be thread safe, and <paramref name="create"/>, <paramref name="apply"/> and <paramref name="clone"/> safe to call on different instances at once, as for Conform. Results do not depend on it.</param>
20042004
/// <param name="clone">Copies an implementation. Each state then keeps the implementation that took the transition into it, and each transition out of it is one step on a copy, so a path is only replayed to confirm a divergence: one seen on a copy is replayed on a fresh instance before it is reported, and put down to the copy if it does not recur. A copy must share nothing a step changes. An implementation is held for every state of the next breadth first level.</param>
20052005
public static SpecReport<S> ConformExhaustive<S, TSut>(this Spec<S> spec, Func<TSut> create, Func<TSut, Transition<S>, string?> apply,
20062006
Action<string>? writeLine = null, int maxStates = 10_000_000, int maxDepth = int.MaxValue, int threads = -1, Func<TSut, TSut>? clone = null)
20072007
{
2008+
if (threads < 1) threads = Threads;
20082009
var report = Explore(spec, null, $"Spec.ConformExhaustive{SutClause<TSut>()} to {Plural(spec.Requirements.Count, "requirement")}",
2009-
maxStates, maxDepth, 1, out var violation, out var frontier);
2010+
maxStates, maxDepth, threads, out var violation, out var frontier);
20102011
if (violation is not null)
20112012
{
20122013
Reporter.Write(writeLine, report);
20132014
ThrowHelper.Throw(violation.ToString(spec.Printer));
20142015
}
2015-
if (threads < 1) threads = Threads;
20162016
var divergence = clone is null ? frontier!.Conform(create, apply, threads, out Exception? error)
20172017
: frontier!.Conform(create, apply, clone, threads, out error);
20182018
Reporter.Write(writeLine, report);
@@ -2028,7 +2028,7 @@ public static SpecReport<S> ConformExhaustive<S, TSut>(this Spec<S> spec, Func<T
20282028
/// <param name="writeLine">WriteLine function for the report.</param>
20292029
/// <param name="maxStates">Give up after this many distinct states (default 10,000,000). The states reached before then are still conformed, but the report is not closed.</param>
20302030
/// <param name="maxDepth">Stop after this many steps from the initial state. The states short of it are still conformed, but the report is not closed.</param>
2031-
/// <param name="threads">The number of threads to drive the implementation on (default number logical CPUs), so <paramref name="create"/>, <paramref name="apply"/> and <paramref name="clone"/> must be safe to call on different instances at once, as for Conform. The model is explored on one thread first. Results do not depend on it.</param>
2031+
/// <param name="threads">The number of threads to explore the model and drive the implementation on (default number logical CPUs), so the specification's delegates and the state's Equals and GetHashCode must be thread safe, and <paramref name="create"/>, <paramref name="apply"/> and <paramref name="clone"/> safe to call on different instances at once, as for Conform. Results do not depend on it.</param>
20322032
/// <param name="clone">Copies an implementation. Each state then keeps the implementation that took the transition into it, and each transition out of it is one step on a copy, so a path is only replayed to confirm a divergence: one seen on a copy is replayed on a fresh instance before it is reported, and put down to the copy if it does not recur. A copy must share nothing a step changes. An implementation is held for every state of the next breadth first level.</param>
20332033
public static SpecReport<S> ConformExhaustive<S, TSut>(this Spec<S> spec, Func<TSut> create, Func<TSut, Transition<S>, bool> apply,
20342034
Action<string>? writeLine = null, int maxStates = 10_000_000, int maxDepth = int.MaxValue, int threads = -1, Func<TSut, TSut>? clone = null)

‎docs/Spec.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,10 @@ Three things to know:
685685
nondeterminism (or state shared between instances) rather than as a defect in that step. Nondeterminism the
686686
abstraction never reads, such as a fresh `Guid` only compared for equality, is fine.
687687
- **The cost is the depth.** Each transition costs one implementation step more than the depth of the state it
688-
leaves, and the third number in the line is their total. The model is explored on one thread and the implementation is
689-
driven on all of them by default, so `create` and `apply` must be safe to call on different instances at once,
690-
as for `Conform`; the result does not depend on the thread count.
688+
leaves, and the third number in the line is their total. The model is explored and the implementation driven on
689+
all threads by default, so the specification's delegates and the state's `Equals` and `GetHashCode` must be thread
690+
safe, and `create` and `apply` safe to call on different instances at once, as for `Conform`; the result does not
691+
depend on the thread count.
691692

692693
A model that does not close can still be conformed as far as the search went: every state short of `maxDepth`, or
693694
before the state where it gave up at `maxStates`, has all its transitions driven, and the report says it is not

0 commit comments

Comments
 (0)