Table of Contents

Class CheckConfig

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

Runtime gate for Typhon's user-facing correctness checks — the "strict mode" (issue #422).

The Release NuGet strips every Debug.Assert / #if DEBUG check, so users get no diagnostics when they misuse the API. The valuable, user-facing checks are converted to run behind this gate: CheckConfig.Require(Enabled, …). Mirroring TelemetryConfig, the gate is a static readonly bool so the JIT dead-code-eliminates the check path entirely when strict mode is off (the Release default) — zero cost on the hot path.

Off by default, everywhere. Enable deliberately when diagnosing, via Typhon:Checks:Enabled in typhon.telemetry.json or the TYPHON__CHECKS__ENABLED environment variable. There is no build-config auto-detection and no runtime setter (a mutable field would defeat the JIT fold — restart to reconfigure).

Startup: call EnsureInitialized() once before hot paths JIT (wired in the engine's module initializer, next to EnsureInitialized()). Configuration is read once from the same merged source as TelemetryConfig (typhon.telemetry.json in cwd, then next to the assembly, then env vars).

public static class CheckConfig
Inheritance
CheckConfig
Inherited Members

Fields

DeclaredAccessActive

Separate opt-in (default false) for the one costly check — SystemAccessValidator.AssertWrite<T> and its Enter/LeaveSystem descriptor-stack infrastructure — so enabling strict mode does not force a HashSet lookup on every Write<T>(). Effective value is Enabled AND Typhon:Checks:DeclaredAccess.

public static readonly bool DeclaredAccessActive

Field Value

bool

Enabled

Master strict-mode switch (default false). When true, all the cheap user-facing misuse checks run. Reads Typhon:Checks:Enabled / TYPHON__CHECKS__ENABLED.

public static readonly bool Enabled

Field Value

bool

Methods

EnsureInitialized()

Forces early initialization so the JIT sees the final static readonly gate values before compiling hot paths. Call once at startup. NoInlining guarantees the call (and thus the static ctor) runs.

public static void EnsureInitialized()

Record(bool, bool, ref CheckMessageHandler)

Latch-safe strict-mode check: like Require(bool, bool, ref CheckMessageHandler) but never throws — on failure it increments Typhon.Engine.CheckConfig.RecordedViolationCount. Use where a throw is unsafe (e.g. reachable while holding an OLC latch, where an exception would leak the latch and deadlock). The message is built only on failure.

public static void Record(bool enabled, bool condition, ref CheckMessageHandler message)

Parameters

enabled bool
condition bool
message CheckMessageHandler

Require(bool, bool, ref CheckMessageHandler)

Strict-mode assertion: when enabled is set and condition is false, throw an InvalidOperationException (via ThrowHelper). The message is built only on failure — the interpolated-string handler skips all formatting when the check passes or strict mode is off, so a passing call in strict mode allocates nothing. Pass Enabled (or a sub-gate) as enabled so the JIT folds the whole call to a no-op when the gate is off.

public static void Require(bool enabled, bool condition, ref CheckMessageHandler message)

Parameters

enabled bool
condition bool
message CheckMessageHandler