Skip to content

Commit 2fb00d1

Browse files
alcidesclaude
andcommitted
perf(verification): shrink and speed up SMT verification conditions
Three improvements to the liquid-type verification path, all behaviour-preserving on the standard (GIL) build (200+ SMT/typechecking tests pass): 1. flatten: O(depth^2) -> O(depth) binder alpha-renaming. The eager per-binder rename rebuilt the whole remaining constraint at every forall, making substitution_in_liquid the hottest function in the system. Renamings are now deferred and applied in one pass per premise/conclusion. ~2.2x faster flatten on deep constraints; verified structurally identical to the old output over 300+ real obligations (tests/flatten_rename_test.py). 2. VC simplification before Z3 (smt._simplify_vc): equality elimination + relevance slicing. Equality elimination (exact) substitutes x:=Y for premises x==Y and drops the binder, collapsing ANF h_i==e_i chains. Relevance slicing keeps only premises/functions/variables transitively connected to the goal, removing irrelevant `open`-library declarations. 3.48x faster validation on deep-constraint programs (supermario's 3.5M-char obligation 3.6s -> 1.1s); 0 verdict changes over 4,460 obligations across 44 programs. Slicing is always sound; see the docstring for the narrow disconnected-inconsistent-premise completeness caveat. 3. Thread-local Z3 context (smt._WS) + lock-atomic fresh_counter: makes the SMT layer safe for parallel candidate validation under free-threaded CPython (python3.14t). The main thread keeps the default Z3 context, so external importers and GIL-build behaviour are unchanged. Enables ~1.4-2x parallel validation of synthesis populations on 3.14t (the parallel driver itself is not yet wired in). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 34d8af9 commit 2fb00d1

4 files changed

Lines changed: 615 additions & 132 deletions

File tree

aeon/utils/name.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import threading
12
from dataclasses import dataclass, field
23

34
from aeon.utils.superscripts import superscript
@@ -8,10 +9,16 @@ class FreshCounter:
89

910
def __init__(self):
1011
self.counter = 0
12+
# ``fresh`` runs on worker threads under free-threaded CPython (parallel
13+
# SMT validation), where ``self.counter += 1`` is a non-atomic
14+
# read-modify-write that can hand out duplicate ids -- which would make
15+
# the alpha-renaming in ``flatten`` unsound. Guard with a lock.
16+
self._lock = threading.Lock()
1117

1218
def fresh(self) -> int:
13-
self.counter += 1
14-
return self.counter
19+
with self._lock:
20+
self.counter += 1
21+
return self.counter
1522

1623

1724
fresh_counter = FreshCounter()

0 commit comments

Comments
 (0)