Comment unreachable configuration guards in by-divisor testers
This commit is contained in:
1 parent
b0ba6401ca
commit
f2eb6580c4
2 files changed
+48
-32
No files matched your search
@@ -52,10 +52,12 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!_isConfigured)
|
// The by-divisor driver configures the tester during startup, so exposing the divisor limit never
|
||||||
{
|
// re-enters this method before initialization completes.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
return _divisorLimit;
|
return _divisorLimit;
|
||||||
}
|
}
|
||||||
@@ -63,20 +65,24 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
|
|
||||||
public ulong GetAllowedMaxDivisor(ulong prime)
|
public ulong GetAllowedMaxDivisor(ulong prime)
|
||||||
{
|
{
|
||||||
if (!_isConfigured)
|
// The CLI wires the tester through ConfigureFromMaxPrime before invoking query helpers, so the guard
|
||||||
{
|
// would never trigger in production runs.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
return ComputeAllowedMaxDivisor(prime, _divisorLimit);
|
return ComputeAllowedMaxDivisor(prime, _divisorLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPrime(ulong prime, out bool divisorsExhausted, TimeSpan? timeLimit = null)
|
public bool IsPrime(ulong prime, out bool divisorsExhausted, TimeSpan? timeLimit = null)
|
||||||
{
|
{
|
||||||
if (!_isConfigured)
|
// The tester is configured once during startup, so runtime IsPrime calls always observe a ready
|
||||||
{
|
// configuration and the legacy guard can remain commented out.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
ulong divisorLimit = _divisorLimit;
|
ulong divisorLimit = _divisorLimit;
|
||||||
ulong allowedMax = ComputeAllowedMaxDivisor(prime, divisorLimit);
|
ulong allowedMax = ComputeAllowedMaxDivisor(prime, divisorLimit);
|
||||||
@@ -122,10 +128,12 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
// throw new ArgumentException("allowedMaxValues span must be at least as long as primes span.", nameof(allowedMaxValues));
|
// throw new ArgumentException("allowedMaxValues span must be at least as long as primes span.", nameof(allowedMaxValues));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!_isConfigured)
|
// PrepareCandidates is scheduled only after ConfigureFromMaxPrime succeeds, so the tester state is
|
||||||
{
|
// stable here and the defensive guard is no longer needed.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
// Configuration is immutable after startup, so reading the cached limit does not require locking.
|
// Configuration is immutable after startup, so reading the cached limit does not require locking.
|
||||||
ulong divisorLimit = _divisorLimit;
|
ulong divisorLimit = _divisorLimit;
|
||||||
@@ -138,10 +146,12 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
|
|
||||||
public IMersenneNumberDivisorByDivisorTester.IDivisorScanSession CreateDivisorSession()
|
public IMersenneNumberDivisorByDivisorTester.IDivisorScanSession CreateDivisorSession()
|
||||||
{
|
{
|
||||||
if (!_isConfigured)
|
// The session pool is populated only after configuration, so consumers never request a session before
|
||||||
{
|
// ConfigureFromMaxPrime completes.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
if (_sessionPool.TryTake(out DivisorScanSession? session))
|
if (_sessionPool.TryTake(out DivisorScanSession? session))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -150,10 +150,12 @@ public sealed class MersenneNumberDivisorByDivisorGpuTester : IMersenneNumberDiv
|
|||||||
throw new ArgumentException("allowedMaxValues span must be at least as long as primes span.", nameof(allowedMaxValues));
|
throw new ArgumentException("allowedMaxValues span must be at least as long as primes span.", nameof(allowedMaxValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_isConfigured)
|
// The GPU pipeline calls ConfigureFromMaxPrime before preparing candidates, so the legacy guard
|
||||||
{
|
// remains commented out to document the invariant without branching.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
ulong divisorLimit = _divisorLimit;
|
ulong divisorLimit = _divisorLimit;
|
||||||
for (int index = 0; index < primes.Length; index++)
|
for (int index = 0; index < primes.Length; index++)
|
||||||
@@ -936,20 +938,24 @@ public sealed class MersenneNumberDivisorByDivisorGpuTester : IMersenneNumberDiv
|
|||||||
|
|
||||||
public ulong GetAllowedMaxDivisor(ulong prime)
|
public ulong GetAllowedMaxDivisor(ulong prime)
|
||||||
{
|
{
|
||||||
if (!_isConfigured)
|
// The CLI configures the GPU tester once at startup, so callers never request divisor limits before
|
||||||
{
|
// initialization completes.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
return ComputeAllowedMaxDivisor(prime, _divisorLimit);
|
return ComputeAllowedMaxDivisor(prime, _divisorLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DivisorScanSession CreateDivisorSession()
|
public DivisorScanSession CreateDivisorSession()
|
||||||
{
|
{
|
||||||
if (!_isConfigured)
|
// Divisor sessions are handed out only after configuration, so this guard would never trigger on the
|
||||||
{
|
// production path.
|
||||||
throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
// if (!_isConfigured)
|
||||||
}
|
// {
|
||||||
|
// throw new InvalidOperationException("ConfigureFromMaxPrime must be called before using the tester.");
|
||||||
|
// }
|
||||||
|
|
||||||
if (_sessionPool.TryTake(out DivisorScanSession? session))
|
if (_sessionPool.TryTake(out DivisorScanSession? session))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user