Repository navigation
Conversation
…object or gone libcvc keeps no process-wide state in code we control (P0a). This moves the state_exec objects that collide between apps onto the app or into the object that owns them, and removes 77 lines from tools/singleton_scan/allowlist.txt. Header statics (every target that includes types.h or task.h): - nil_value, true_value and false_value were inline const value_t objects, one per process: they are functions now, nil_value() etc., returning a new value_t (value_t is not a literal type, so it can't be constexpr). Every use in the tree is updated; the two sites that took &nil_value use a local. - task.h's thread_local trampoline slot (trampoline_next()::h) is gone: sync_wait() owns its slot (a local) and every promise of the chain it drives points at it (promise_type::trampoline_, passed on as a task is awaited). A nested sync_wait has a slot of its own; a coroutine with no slot transfers symmetrically, as MSVC always did. Per app (app.slot<T>()): - frozen_builtins() is frozen_builtins(cvc::app &): the frozen default environment an app's exec_groups and pooled pycvc Execs extend, built once per app. A group with no app freezes a default environment of its own. - exec_group's creation count (pool_link().seq), its live-group map and its single-manager note were process-wide maps keyed by app address (an app at a reused address could inherit another's count or miss its note): each app keeps its own. live_groups() takes cvc::app &. A group with no app has seq 0. - The threaded-host flag (g_threaded_host) is the app's: detail::note_threaded_host(cvc::app &) / threaded_host_noted(cvc::app &). pycvc no longer sets a process-wide flag at import; it notes each app it makes (make_app) or runs an Exec on, before that app's lock manager is made. So importing pycvc no longer turns every later app's lock manager shared. Per object: - A scheduler's serial (the foreign-future check) and a cycle registry's id are 64 random bits each (never 0), not drawn from a library-wide counter. - An async_host's reply channels are "<name>.async#<host tag>-<n>": the host's random tag and its own count, not a process-wide sequence. - CVC_EXEC_VERIFY is read as each scheduler is made (scheduler_base::verifies_pump_owner()); no_process() is a member. - The closure-body cache (t_shared_bodies) lives in the cycle registry its closures are tracked in (a group's, or the thread's own), so two groups never share a body list, and the registry id that keyed it is not needed. - The intrinsics' chain-pin scratch stack is the intrinsics_context's (pin_scratch), not a thread_local; a data job's deferred write uses a local. - The lock manager owns the CVC_EXEC_FUZZ state (seed, hits, the yield stream: lock_manager::set_fuzz_seed / fuzz_seed / fuzz_hits, read from the environment as each manager is made) and the test hooks (lock_manager::set_test_hooks / test_hooks). The process-wide seed, hit and thread counters, the thread_local PRNG and the global hook pointer are gone. - math.random with no group stream bound draws from its stdlib_registry's own stream (under a mutex), not a thread_local engine. Gone or made constant: - stdlib_registry::standard() (a process-wide registry) and shared_scope() (a process-wide frozen scope) are removed; stdlib_registry::make_scope() builds a new frozen scope, and make_default_environment() links one of its own. - print takes stdout's own C library lock (flockfile / _lock_file) around its one write, instead of a leaked process-wide mutex. - stackless_evaluator::all_special_forms() returns a new std::set from a constexpr table; is_special_form(name) answers without building it (Ariadne's two callers use it). - kSso, kFreshBuckets, kBucketFormulaHolds, has_cpu_clock and the env flag CVC_STATE_EXEC_CHECK are computed where used, kept in their owner (the scope pool), or constexpr; detail::bucket_formula_holds() is checked by a test. API changes (4.0): nil_value() / true_value() / false_value(); frozen_builtins(cvc::app &); stdlib_registry::make_scope() replaces shared_scope(), standard() is gone (pycvc too); all_special_forms() returns by value, is_special_form() added; detail::live_groups(cvc::app &); detail::note_threaded_host(cvc::app &), threaded_host_noted(cvc::app &); detail::new_scheduler_serial(), pump_owner_verification(), scheduler_base::verifies_pump_owner(); lock_manager::set_fuzz_seed, fuzz_seed, fuzz_hits, fuzz(), set_test_hooks, test_hooks; lock_port takes the fuzz state; detail::lock_fuzz_point(lock_fuzz *, where), lock_fuzz_seed_from_environment(); the process-wide set_lock_fuzz_seed, lock_fuzz_seed, lock_fuzz_hits, set_lock_test_hooks and lock_test_hooks_get are gone; intrinsics_context::pin_scratch; detail::bucket_formula_holds(). Tests: multi_app_integration_test's workload gains state_exec(): each app runs a DSL program on its exec scheduler that defines a function and an exception class of its own, raises through a call and catches it, then runs a group of the app (its seq, its pid, the app's frozen builtins, the app's threaded-host note); the transcripts match alone, at once on threads and in reverse order. New: ExecGroup.CreationOrderAndLiveCountArePerApp (two apps in both orders, apps on threads, a later app counts from 1), SchedulerSerialTest .EachSchedulerDrawsItsOwn, StdlibSharedScopeTest.EachAppHasItsOwnFrozenBuiltins and EachDefaultEnvironmentLinksItsOwnScope, LockFuzz.TheSeedIsTheManagers, StateExecTypesTest.ConstantsAreNewValues and LookupBucketFormulaHolds; AppLockManager.AutoIsSharedForAThreadedHost runs in process now (two apps, both orders, a later app) instead of in a death-test child; the frozen-builtins tests check one scope per app and another app's differs. The lock suites install fuzz seeds and hooks on their managers. Allowlist lines removed (77): cvc 53 (state_exec sources 45, <header> 8), cvc-cli 6, cvcGL 6, pycvc 6, pycvc_gl 6.
…ument The evaluator hands detail::lock_wait_call the lock-enter token of the one %lock-wait call it applies (the wait native it builds captures it), instead of arming it in a thread_local (t_lock_enter): a program's own %lock-wait call has none, as before (LW-2). lock_enter_scope and lock_enter_token_get() are gone. One more allowlist line removed (cvc: t_lock_enter). Also: an exec_group keeps a pointer to its app's counts, so its destructor looks nothing up; the integration workload's error message is built with str-concat (str takes one argument).
…ine's include pycvc declares stackless_evaluator::all_special_forms() as it now is, returning a new set by value (its set out-typemap takes the value). python_engine.cpp includes lock_manager.h outside the server-only block, where attach() notes the threaded host on the app it is given.
exec_pool's process-wide g_membership mutex guarded every group's pool_link().call. Each group_pool_link now has its own membership mutex: pump_all takes it per group while it claims and releases the group, and a group's purge_host_calls holds its own across the wait, so the call still cannot end while the purge waits on it. Pools of different apps no longer share a lock. Allowlist: -1.
transfix
added a commit
that referenced
this pull request
Nov 12, 2026
The trampoline's await_suspend is a member template (it reads the caller's promise for its trampoline slot), and GCC and Clang reject a member template in a local class. CVC_COROUTINE_TRAMPOLINE is 1 only off MSVC, so Windows built and every Linux, macOS and wasm build failed in task.h (#1189's run: package-linux debug, CGAL A/B, both wasm-mt lanes). task<T>::awaiter and task<void>::awaiter are now members; operator co_await returns one.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No singletons, state_exec: the DSL's process-wide state per app, per object or gone. Stacked on #1176 (Ariadne part 3); a sibling of #1182, #1183, #1184 and #1187. Breaking (4.0).
What moved
nil_value,true_valueandfalse_valueare functions returning a freshvalue_t(value_tcannot beconstexpr). All 233 uses across the tree are updated.trampoline_next()::his gone: eachsync_wait()owns a local slot, and every promise in the chain it drives points at it throughpromise_type::trampoline_.app.slot):frozen_builtins(cvc::app&). A group with no app freezes a default environment of its own.exec_group's creation count, live-group count and the "manager is single" note. These were process-wide maps keyed by app address.make_app,app_from_capsule, atExecconstruction and inset_lock_manager, and the embedded Python engine notes the host's app inattach().async_hostbuilds its reply channels from its own random tag plus a count.CVC_EXEC_VERIFYis read when each scheduler is made.t_shared_bodiesand the registry-id counter.intrinsics_context::pin_scratch.CVC_EXEC_FUZZstate and the lock test hooks; the with-lock token is captured by the wait call the evaluator builds.math.randomwith no group stream draws from its registry's own stream, under a mutex.g_membershipmutex is each group's own (group_pool_link::membership). pump_all takes it per group while it claims and releases the group, andpurge_host_callsholds the group's own across its wait, so the call still cannot end while the purge waits on it. Pools of different apps no longer share a lock.stdlib_registry::standard()andshared_scope()are gone.make_scope()builds a new scope, andmake_default_environment()links one of its own.printtakes stdout's own C library lock instead of a leaked process-wide mutex.constexprtable, with a newis_special_form().kSso,kFreshBuckets,kBucketFormulaHolds,has_cpu_clockand theCVC_STATE_EXEC_CHECKcache are computed where used, kept in the scope pool, orconstexpr.Cost: groups with no app, and every
make_default_environment()call, now build their own stdlib scope instead of sharing one: a few hundred more allocations per default environment. Onlystate_exec_bench_smokewas run against it.Public API changes
nil_value(),true_value(),false_value();frozen_builtins(cvc::app&).stdlib_registry::make_scope()replacesshared_scope();standard()is removed, in pycvc too.all_special_forms()returns by value;is_special_form()is new.detail::live_groups(cvc::app&),detail::note_threaded_host(cvc::app&),threaded_host_noted(cvc::app&).scheduler_base::verifies_pump_owner(),detail::new_scheduler_serial(),detail::pump_owner_verification().lock_manager:set_fuzz_seed,fuzz_seed,fuzz_hits,fuzz(),set_test_hooks,test_hooks. Removed: the process-wideset_lock_fuzz_seed,lock_fuzz_seed,lock_fuzz_hits,set_lock_test_hooks,lock_test_hooks_get,lock_enter_scopeandlock_enter_token_get.lock_porttakes the fuzz state;lock_wait_call(ops, args, token)takes the token.Allowlist: -79 lines (cvc 55, cvc-cli 6, cvcGL 6, pycvc 6, pycvc_gl 6)
The cvc-cli, cvcGL and pycvc lines are the header statics (
nil_valueand the rest) that every target compiled in.Not removed: 31 lines (please review)
Apart from the exception classes and the scope-serial counter, these are per-thread, not process-wide: each is set and restored in scope by the thread doing the work, so no two apps share one. They stay because the code that reads them has no context to get one from:
~value_tag, shared_ptr deallocators, and native functions, whose typestd::function<value_t(span<const value_t>)>takes no context argument (about 590 of them in 69 files).t_in_async_kernel, the iterative value-release queue (used from~value_tag), and the scope pool (used from control-block deallocation).g_next_serial_runplus two thread-locals.g_next_serial_runis the one process-wide counter left; it keeps scope serials unique across threads, andenvironment::extendhas no app to hold it.t_await,t_park_forbidden,t_step_depth(natives read them throughcan_awaitandrequest_await) and the per-frame vector recycling.t_scope,t_native_depth; stdlib.cppt_stream; exec_group.cppt_current(behind the publicexec_group::current()); native_stack.cpp the thread's stack bound.classes()::built: the 19 built-in exception classes. They are immutable and identified by address, so C++ errors raised anywhere map to the classes a program catches. Making them per app needs a design decision: the C++-to-DSL exception mapping, the read-only check and snapshot relinking would all have to take an app or environment.types.cpp's measured TSC rate, cached once per process because measuring it takes a 5 ms sleep.Removing the rest needs a context argument on native functions or a redesign of how values are released: a follow-up.
Tests
multi_app_integration_testgains astate_execpart. Each app defines a function and an exception class, raises it through a call and catches it, runs a group of its own, and records the group's sequence and pid, whether its frozen builtins survived, and its threaded-host note.ExecGroup.CreationOrderAndLiveCountArePerApp(both orders, apps on threads, a later app counts from 1).SchedulerSerialTest.EachSchedulerDrawsItsOwn.StdlibSharedScopeTest.EachAppHasItsOwnFrozenBuiltinsandEachDefaultEnvironmentLinksItsOwnScope.LockFuzz.TheSeedIsTheManagers.StateExecTypesTest.ConstantsAreNewValuesandLookupBucketFormulaHolds.AppLockManager.AutoIsSharedForAThreadedHostruns in-process with two apps in both orders, instead of in a death-test child.Locally (Windows, MSVC Release; the full tree builds, including cvcGL, pycvc, pycvc_gl and the examples):
state_exec_*test executables, includingstate_exec_locks_test(215) andstate_exec_locks_model_test(201);ariadne_runtime_test(262),ariadne_registries_test,app_test(121),multi_app_integration_test,exec_pool_test(33);exec*andpycvc_state_exec*tests, both ariadne tests,pycvc_gl_ariadne_host,pycvc_gl_ariadne_gil);state_exec_bench_smoke.AsyncCalls.AS19andAS24failed once on wall-clock limits with the machine at 100% CPU, then passed three times on rerun. After the membership change:exec_pool_test,multi_app_integration_test,state_exec_groups_test,state_exec_async_calls_testandapp_testpass.CI
Full run: the push to
ci/full/no-singletons-state-exec, https://github.com/transfix/libcvc/actions/runs/43214724015.