Skip to content

Ariadne: a load:ed module's on_tick: runs at its mount - #904

Merged
transfix merged 13 commits into
masterfrom
feat/ari-module-on-tick
Oct 31, 2026
Merged

transfix merged 13 commits into
masterfrom
feat/ari-module-on-tick

Conversation

@transfix

Copy link
Copy Markdown
Owner

A load:ed module's on_tick: now runs. Before this, a module's init: ran but its on_tick: was ignored with no warning, so a module could not own a loop (cy-pca/cypkg's request loop, for one) and so could not be tested on its own.

Stacked on #900 (functions for modules). Retarget to master once that merges.

  • Loader (expand_load): captures the fragment's on_tick: onto the mount wrapper as Widget::tick_script, the same way it captures init_script. A non-scalar one gets a warning.

  • Runtime: one tick resident per mount sub-prefix (MountTick). Each one:

    • is owner-tagged, so kill_owner reaps it with the Runtime;
    • is chrooted to the sub-prefix, with the mount's FunctionScope prelude defined once before its loop;
    • listens on its own channel, <owner>#tick@<sub-prefix>;
    • is woken each drain by post_tick, coalesced like the document's tick.

    ensure_resident now takes the chroot and the prelude; the 4-argument form keeps the document's behaviour.

  • Lifetime:

    • The resident starts the first frame the mount is drawn, right after its init: (and its holes), so the first tick sees what init: seeded.
    • A reconcile keeps it when the new tree has the same mount at the same sub-prefix with the same program (body plus functions), as a reload of an unchanged document does. Otherwise the reconcile stops it.
    • For a repeated mount, each instance stops when its outermost repeat: count drops below it. With a nested repeat, an instance whose inner count drops keeps running until the next reconcile.
  • Errors: a failing or killed module tick is reported once, as on_tick: of mount '<sub-prefix>' resident [...]. ari test fails the document on it.

  • Checks: the load-time free-head preflight and the channel lint now scan a mount's on_tick:.

  • Decision: on_key:, on_pointer: and on_signal: stay with the outermost document. A fragment that declares one now loads with a warning instead of having it silently ignored. Raw input and signals belong to the document:

    • a module that saw every key could read what is typed into the parent's fields;
    • two modules cannot both decide what Ctrl-C does.

    A module reacts to its own widgets. The parent passes on anything else through a link: hole, which the module's on_tick: can read. This is written up in docs/ARIADNE.md §6.3.

  • Docs: ARIADNE.md §2.3 (residents), §2.4 (the warning's lane name), §6.3 (a module's programs and the input-lane decision) and §7.4 (the order: holes, then init:, then the tick; reconcile and repeat lifetime).

Tests

  • ariadne_host_test AriadneModuleTick.*:
    • the tick runs at the mount, after init:, with the functions its mount granted, and cannot reach the parent's state; the document's own tick runs beside it;
    • a failure warning names the mount;
    • a reload of the same document keeps the tick running, and a reconcile that drops the mount stops it;
    • a repeated mount ticks once per instance, and an instance the count drops stops;
    • a module's on_key: and on_signal: load with warnings.
  • ari_test_command_test AriTest.AModulesOnTickRuns: a parent document's test waits for the module to tick 3 times, and a module whose tick asserts false fails ari test, with the mount named.

- (quit [code]): AppRuntime::register_quit() binds `on: quit` and the verb; the
  first close request's code is exit_code(). ari run/snapshot/check and arigl (window
  and --terminal) exit with it; snapshot stops on the frame the document quit.
- (assert cond [message [data]]): a builtin raising AssertionError (a new class under
  Exception), "assertion failed[: message]"; its traceback ends at the form.
- tests: block (name -> program) captured by the loader; Runtime::run_program runs a
  program on the action lane and reports how it ended to a callback.
- ari test [--tap] [--timeout S] [--frames N] doc.ari...: each document headless until
  it quits, its tests have run, N frames, or the timeout. Fails on a non-zero quit, an
  uncaught error, a failed or warning load, a failed test, or a timeout. One line per
  document with what failed and in which program; TAP with --tap; exit 1 on failure.
  Network flags and settling as snapshot's.
- Action failure warnings name their program; resident ones their lane.
- Docs: ARIADNE.md §13, the exceptions table, the developer guide.
…s modules (#894)

- functions: (top level): a program of (defun ...) forms that every program in the
  document's scope can call (init:, on:, residents, key bindings, tests:); anything
  else is skipped with a warning. import: merges a library's functions.
- load: functions: [names] | name | "*": grants the parent's functions to the module,
  each with the functions it calls; a module gets none otherwise, and its own
  functions: stay inside it. Code, not authority: a granted function runs chrooted to
  the module.
- Mechanism: Widget::functions (FunctionScope) on the root and every mount wrapper; the
  runtime keeps a function-scope stack beside the mount scopes and runs the scope's
  prelude ahead of each program (actions, residents, run_program, init:, mount init:).
- The free-head preflight is scope-aware and scans function bodies and mount init:.
- Docs: ARIADNE.md §6.6.
- Loader: expand_load captures the fragment's on_tick: onto the mount wrapper
  (Widget::tick_script), as it does init:. A fragment's on_key:, on_pointer: and
  on_signal: now load with a warning instead of being dropped silently: input and
  signals stay the outermost document's (docs/ARIADNE.md §6.3).
- Runtime: one tick resident per mount sub-prefix, owner-tagged, chrooted there with
  the mount's FunctionScope prelude, on <owner>#tick@<sub-prefix>, woken each drain by
  post_tick. Started on the mount's first frame, after its init:. A reconcile keeps it
  when the new tree has the same mount and program, and stops it otherwise. A repeated
  mount's instance stops when its outermost repeat: count drops below it.
- A failing module tick is reported as on_tick: of mount '<sub-prefix>'. The preflight
  and the channel lint scan a mount's on_tick:.
- Tests: AriadneModuleTick.* (ariadne_host_test), AriTest.AModulesOnTickRuns.
- Docs: ARIADNE.md §2.3, §2.4, §6.3, §7.4.
transfix added a commit to cy-pca/cypkg that referenced this pull request Oct 30, 2026
main.ari now only composes. It mounts search.ari and package.ari with
load: and grants each three holes: args (read-only), view and nav. Each
module owns its state, imports its view (views.ari) and logic (lib.ari),
and runs its own requests in its on_tick (transfix/libcvc#904). Its
views reach a parsed reply through holes that grant a subtree (#905).
A hidden mount doesn't start until shown, so Open sets view as well as
nav.open, and that starts the package module.

tests/modules/ mounts each module alone against the fixture through the
same holes (9 search, 8 package tests, from the old whole-document logic
tests), and tests/modules.sh runs them with ari test. tests/logic.sh,
which ran ari test on a copy of main.ari, goes. lib.ari gains int-or, so
a module loaded without its holes (ari check) doesn't fail its init.

Every snapshot frame and interactive step is unchanged.
transfix and others added 6 commits October 30, 2026 12:54
Conflicts with the locks spawn context (#865) and --credential-env (#895): the sweep keeps
run_program's report and the spawned children's reap; ari test settles with AppRuntime::settle,
which replaced settle_async_calls; --timeout joins --credential-env among the value flags.
…-tick

The locks spawn context (#865) makes resident contexts shared and built by
make_action_context: a mount's tick resident is made the same way, chrooted to its
sub-prefix.
…illing

stepped_solve::impl did f.assign(nv, f[0]): the value is a reference into f, and libc++'s
assign frees the old buffer before filling the new one, so on macOS every entry was read
from freed memory (Fem.SteppedPoissonMatchesTheOneShotSolve, rel diff 6.7e268 in the macOS
recipe lanes). libstdc++ and MSVC copy the value first, so Linux and Windows passed.
Takes #903's fix for the stepped Poisson solve in place of the same fix made here.
Base automatically changed from feat/ari-module-functions to master October 31, 2026 05:12
#900 landed on master squashed (b2e381a), so this branch's own change is 657290a's diff from
#900's last head b83e92d. It applies to master unchanged: the module on_tick work alone.
@transfix
transfix enabled auto-merge (squash) October 31, 2026 05:13
@transfix
transfix merged commit 810efb0 into master Oct 31, 2026
27 checks passed
@transfix
transfix deleted the feat/ari-module-on-tick branch October 31, 2026 07:35
transfix pushed a commit that referenced this pull request Oct 31, 2026
#904 landed on master squashed (810efb0), so this branch's own change is 8d9ae77's diff from
#904's last head 657290a. It applies to master unchanged: a module's own requires: alone.
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