Skip to content

0.44: allow agent state - #85

Merged
MathisWellmann merged 5 commits into
mainfrom
state
Oct 13, 2026
Merged

MathisWellmann merged 5 commits into
mainfrom
state

Conversation

@MathisWellmann

@MathisWellmann MathisWellmann commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

• Declared functions can now take &mut State or &State. You declare it with evolvable! { type State: Default + Send + 'static; .. }, and the agent defines the type.
• The host holds an opaque symbiont::State for each run, created with Runtime::new_state or the generated new_state(revision). The dylib allocates, borrows and drops the value itself, because only the code that knows the layout should touch it.
• Each State is tied to the revision that created it, and every call checks this. A mismatch aborts, because two revisions can share a TypeId but have different layouts.
• A State pins its revision. The value is dropped before the pin is released, so unload_revision cannot unmap code that a live state still needs.
• If State::default() panics, you get an error. A panic in Drop stays inside the dylib. Miri tests cover the handle layout, borrows and drop order.

`evolvable! { type State: Default + Send + 'static; .. }` lets declared
functions take `&mut State` / `&State`. The agent defines `State`; the host
holds an opaque `symbiont::State` per run (`Runtime::new_state`, generated
`new_state(revision)`). The dylib allocates, borrows and drops the value
through exported glue, so only the code that knows the layout touches it.

- Bound to its revision by a tag (address of a static in the creating dylib),
  checked by every export wrapper; a mismatch aborts, because equal crate
  names make equal TypeIds with different layouts.
- Pins its revision like RevisionFn, value dropped before the pin, so
  unload_revision cannot unmap the drop code under a live state.
- Panicking State::default() is an error, panicking Drop stays in the dylib.
- Miri covers the handle layout, borrows and drop order via state_preamble.rs.

One revision (~1.5k lines, half of it tests): the handle, the glue and the
macro only make sense together; split, the first half is dead code under
-D warnings.
…ble code, so long-lived state iterates reproducibly
@MathisWellmann
MathisWellmann merged commit 28e3b29 into main Oct 13, 2026
4 of 6 checks passed
@MathisWellmann
MathisWellmann deleted the state branch October 13, 2026 18:52
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