Skip to content

Synchronization primitives, environments and region checks - #25

Open
Kristof Roomp (mcroomp) wants to merge 9 commits into
mainfrom
feature/synchronization-primitives
Open

Kristof Roomp (mcroomp) wants to merge 9 commits into
mainfrom
feature/synchronization-primitives

Conversation

@mcroomp

@mcroomp Kristof Roomp (mcroomp) commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Adds first-class synchronization primitives and environments so TlaLink can check deadlock and progress models of concurrent C# against the code they describe. Design: docs/proposals/synchronization-primitives.md. Developed against a real multiplexed RPC/bulk-transfer library as the first consumer; all examples and fixtures here are synthetic.

What changes

  • Kind library (src/tlalink/Tla/Primitives): register, latch, once, admission gate, counting resource, channel and cancellation source modules with a common interface. Every action A also has pure AEnabled/AApply operators, so a model can compose one atomic step that changes several instances of the same kind. Each kind ships with harnesses, reachability witnesses and named broken variants as negative controls.
  • Primitive manifests (one per C# type) replace reviewed method summaries:
    • declare the kind (or a custom module) and every member's role and kind actions;
    • guarantees (signals-async, non-blocking, ...) are statically checked where possible;
    • the verification scenarios and inspection obligation, dependencies, and an optional state_mapping.
    • Library primitives (BCL types) declare only the members a region uses.
  • Environment manifests for code outside the region (interfaces it calls, consumers that call it): operations, lock_safe, obligations and evidence. Obligations appear as assumptions in plans and reports.
  • Synchronization regions in the correspondence scope: explicit files, locks with their allowed nesting, spawn dispositions and non-primitive waits.
    • SR100-SR106 check raw synchronization, undeclared operations and waits, lock-region rules (no waits, no inline callbacks, declared nesting only), spawns, stale declarations and guarantee discharge.
    • They run without a model checker, as a synchronization stage, and in preflight for model stages.
  • Instances and sites: an instance annotation binds region fields to kind-module instances. Roslyn finds every site that applies a primitive operation to an instance field, and SANY reference extraction checks that the bound model action applies the corresponding kind actions.
    • SR107-SR111: undeclared instance, unbound site, contract mismatch, stale instance, unresolved receiver.
    • Coverage and contract checks are scoped to targets that declare the instance.
  • Assumptions and scale:
    • temporal stages must declare fairness (SR112-SR114);
    • symmetry with liveness is rejected (SR115);
    • state_mapping expressions are restricted and checked (SR116-SR117) and captured under the primitive's lock at bound sites, so trace validation checks primitive state.
  • Fixes:
    • stage child commands run on the current .NET host instead of the first dotnet on PATH, which could change the pinned reference set mid-run (WF900);
    • the cancellation source models Dispose;
    • stage and profile timeout_seconds may be up to 48 hours (check-stage already allowed this), and storing a TLC result retries the final directory move when a scanner briefly holds a file.
  • Admission-gate drain is signaled in the draining step: the Exit or Close that leaves the gate closed and empty sets signaled; there is no separate internal Signal action, so every kind now has Internal(i) == FALSE. Implementations complete the drain task on that caller's stack right after the state change, and completing it only enables waiters. Disposal paths close several gates at once, and the separate step interleaved every signal order: in the first consumer's two-lane model it produced 78% of distinct states and the check did not finish in 4 hours. It now completes in about 10 minutes (10.2M and 17.0M distinct states).
  • SR118 synchronous wait probe: a region read of an admission-gate wait's completion (IsCompleted, Status, ...) could observe the merged state and is rejected unless excluded. Other kinds complete their waits with their state change (a latch's state is its task), so their completion reads are not reported.

Not included

  • Per-component trace projection (documented as not implemented).
  • Declared symmetric instance sets; only the symmetry-with-liveness rejection is enforced.

Validation

All suites pass at the head commit: --core 485/485, --primitives 49/49, --links 49/49, --frontend 15/15, --trace 50/50, --workflow 55/55, --evidence 35/35 (Dafny via TLALINK_DAFNY). The examples/Primitives project runs end to end:

  • region check with negative controls;
  • caller model with instances, binds and fairness;
  • liveness stage;
  • trace stage with state capture and a double-credit negative control.

kristofr and others added 9 commits November 22, 2026 11:25
Replace reviewed method summaries with declared primitive kinds, per-primitive
manifests, environment manifests and region completeness checks, with the
Abacus multiplexer as the first consumer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Ship a kind library (register, latch, once, admission gate, counting
resource, channel, cancellation source) with harnesses, witnesses and
negative controls. Add per-primitive manifests resolved with Roslyn and
SANY, scope synchronization.primitives and stage primitive uses, with
support and staleness carried over from reviewed method summaries, which
are removed. Replace the method-summary example with a primitives example.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Declare a region of explicit C# sources with its lock objects, spawns and
non-primitive waits, plus environment manifests for code outside it and
library primitives. Region checks (SR100-SR106) flag raw synchronization,
undeclared operations and waits, lock-region violations, undeclared spawns
and stale declarations, and statically discharge signals-async and
non-blocking guarantees. Checks run as a synchronization stage and in
preflight for model stages over a region scope.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add the instance annotation, Roslyn site detection over region fields and
SANY reference extraction, with SR107-SR111 for undeclared instances,
unbound sites, contract mismatches, stale instances and unresolved
receivers. Also accept empty declaration lists, limit resume-under-lock to
primitives with waits, make inline callbacks a per-operation flag and allow
inherited members as environment and library operations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ent host

TlaLinkCancellationSource gains Dispose and CancelRejected (Cancel after
Dispose throws), with harness history checks. Stage child commands now run
on the muxer of the running runtime instead of the first dotnet on PATH,
which could change the pinned reference set mid-run (WF900 'Input changed
between parser invocations: tool:csharp-references').

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Model stages now carry their region's environment obligations, and
temporal stages must declare fairness (SR112-SR114); symmetry with liveness
is rejected (SR115). Primitive manifests may map kind View fields to
restricted C# expressions (SR116-SR117), captured under the primitive's lock
at bound sites and checked by trace validation. Site coverage and contract
checks are scoped to targets that declare the field's instance.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Long safety checks of multi-instance models need more than two hours, and
check-stage already accepted 48-hour deadlines. Stage, profile and editor
schema limits now share ProjectWorkflow.MaxStageTimeoutSeconds.

Storing a TLC result retries the directory move when a scanner briefly
holds a new file open, and temporary-directory cleanup is best-effort.
REFERENCE documents that deadlines do not count host sleep on Windows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The admission-gate kind signaled its drain in an internal step separate
from the Exit or Close that left the gate closed and empty. Disposal paths
that close several gates at once then interleave every signal order: in a
two-lane connection model this step produced 78% of distinct states and
the check did not finish. Implementations complete the drain task on the
draining caller's stack right after its state change, and completing it
only enables waiters, so the kind now sets signaled in that step. Every
kind now defines Internal(i) == FALSE.

A synchronous completion probe (IsCompleted, Status, ...) on a wait could
observe the merged state, so SR118 rejects such sites unless excluded.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only the admission-gate kind merges a signal that implementations complete
after the state change. A latch's state is its task, so reading its
completion is an exact state query; SR118 rejected such reads in the
multiplexer's hello handling. The wait-probe mutant now also probes a
latch, which is not reported.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mcroomp
Kristof Roomp (mcroomp) marked this pull request as ready for review November 23, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant