Repository navigation
engine: split into crates and drop simlin-serve - #1098
Merged
Merged
Conversation
The local HTTP viewer and editor was never released and nobody uses it. It accounted for 148 of the 487 packages in Cargo.lock, and every pull request paid for it with an SPA build, two release smoke legs and a Windows type-check, each compiling the engine again. Loro's dependency chain (loro-internal -> pest -> psm -> ar_archive_writer) also carries the Apache-2.0 WITH LLVM-exception license that cargo-deny rejects, which is what has the lint job red. deny.toml keeps only the license allowances and advisory exceptions the remaining dependency graph needs. simlin-mcp-core keeps the ProjectAccess trait and its version token as they are; only what serve alone reached is trimmed. The empty-project helper becomes one function with one definition of the default sim-specs, and helpers with no caller outside the crate lose their pub. Nothing in libsimlin's C API changes. The threat model described serve alone, so it goes, and the security contact it held moves to the README.
@simlin/mcp ships a win32-x64 binary, and the release workflow that cross-compiles it runs only on a tag. No pull request job compiled the engine or simlin-mcp on Windows, so a change that does not build there was found at release time.
Every crate the engine is split into would have had to declare and forward the feature that gated Debug, and it was already a trap: an unconditional derive on a type holding a gated one passed a default build and failed the wasm and pysimlin builds. The gate bought no size. The browser bundle (wasm-release, no default features, before wasm-opt) is 12,986,892 bytes with it and 12,985,372 without.
The MDL writer read the compiler's test for an equation that says nothing, which read the MDL reader's sentinel for one; the MDL reader built its equations with an edit operation's constructor; the compiler's sync asked the patch code for a variable's uid; and the importers joined names for a sentence with the diagnostics formatter's function. Each is a fact of the datamodel or a string helper that needs nothing above it, so it now lives where both of its callers can reach it: the sentinel and its test, `Equation::arrayed` and `Variable::get_uid` in the datamodel, and `join_quoted_names` in `common`. This is the first of the moves that leave the engine's modules in layers, so that each layer can become a crate.
A row of results begins with the clock's slots, and everything that reads a row by them (the VM, the wasm backend, the analyses, the agent tools) reads them from the results, yet `results` took the first of them from the VM and the wasm backend kept a second copy of the rest. They are one list in `results` now, beside the names of those slots: what the systems reader and a rename refuse a variable is the name of a results key, which is not a fact of the db.
The map from a lowered expression back to a parsed one is the ast's: it reads and builds nothing else, and none of its callers is a patch. The shape of a name an equation references is read by the ast's lowering scope and by the fragment compiler, and is made only of dimensions and identifiers, so it moves down to the ast too. The ast then uses nothing of the compiler, and LTM and the db use nothing of the patch code.
The JSON a host sends a patch in is read into, and written from, the patch's own types, and those were in the module that applies them: the format code depended on every edit the engine can make. `project_patch` holds the operations as data, made only of datamodel values, and `patch` is what they do.
`generate_relationships` joins the causal graph's polarities with the SD-AI format, and it was in the format, which made reading and writing a file depend on LTM. It is the analysis's: `model_links` beside it is the owner of a model's causal links. The alternative was to move LTM's `LinkPolarity` below the formats, for one match, beside the datamodel's own type of that name, the polarity a diagram draws. `SourceVariableKind` moves beside `VariableSource`, the parse input it is a field of, so `variable` no longer reads the db that is built on it.
The engine's modules form layers, which are to become crates, and nothing held them: one `crate::` path is all it takes to put a cycle back. The table says which layer each crate-root module is in and which layers each layer may use, and the check fails on a production reference to any other. It lists no exceptions. Run over the tree before the moves it reports 54 references, the ones the moves removed, and a copy of this tree with each layer in a crate of its own, its visibility widened and nothing else changed, compiles. It reads Rust by tokens, follows `mod` declarations to find the files, and skips what no build without tests compiles. A new crate-root module fails the check until the table places it.
The engine is about to become several crates, and its integration tests, benchmarks and instruments use all of it at once. They are simlin-tests, which nothing depends on and which depends on everything. The engine's dev-dependency on itself goes with them. It was there to turn `file_io` on for the corpus (GH #925); what the feature gates is now `cfg(any(test, feature = "file_io"))`, and the corpus asks for the feature in the one edge simlin-tests has onto the engine, which no flag turns off. The examples need the `instruments` feature, so `cargo test` links none of them and the hook's `--all-features` clippy still checks them all. `vm.rs` imported a constant only a test-support build uses, which the deny- warnings build CI does, of production code alone, refuses.
simlin-base is the engine's lowest layer as a crate: the data model and the patches to it, identifiers, errors, dimensions, the equation lexer, parser and AST, the builtins, the stdlib and the results of a run. Nothing re-exports it; whoever uses one of its items names it there. What is public is what another crate uses, and no more: an item that was pub in a module nothing outside the crate could reach is pub(crate) unless it crosses the boundary, so the dead-code lint still sees it. Eleven tests moved. Nine of `ast::ArrayView` were in the compiler's dimension tests and are beside it now. Two run a model on the VM to say something of a base type, which base cannot, and are the engine's: that a canonical equation computes what its original does, and the table a run prints.
simlin-diagram draws a model's diagram as SVG, PNG and a scene, on simlin-base alone; the resvg rasterizer and its `png_render` feature are its own. Nine tests draw a corpus model, which they have to open, and the readers are built on this crate: they are in simlin-tests. The oracle they check a scene by is in the crate behind `test-support`, so its own tests and theirs share one.
`analyze_model` returned a JSON snapshot of the model beside the loops, so it could not be built below the file formats; libsimlin paid for the snapshot and dropped it. The MCP tools are what report it, and they take it now (`types::model_snapshot`), beside the SD-AI relationships, which they alone write. What a variable reads (`model_reads`) is the agent tools' question and walks the text a rename walks, so it is theirs.
simlin-formats reads and writes what a model is kept in: XMILE, Vensim MDL and VDF, the systems format, JSON and the stored protobuf. It is built on the data model and the diagram geometry, not on the compiler, so a compiler edit leaves it alone and the reverse; its tests that run what they read use the engine as a dev-dependency. The tests that ask the save check, land a patch or lay out a diagram are in simlin-tests, since those are built on this crate; the generator and comparisons they share with the writer's own tests are behind `test-support`.
simlin-edit holds the patches a host or an agent lands, the plans of gestures on a diagram and a variable's equations as a host draws them. An edit is made to a project whether or not it compiles, so none of it uses the compiler. Two tests of what the edits by field store ask the save check and are in simlin-tests; the one of what a diagram sync shares is with the layout it tests.
simlin-wasmgen lowers the engine's compiled simulation to a wasm module. It reads the bytecode tables and a few VM helpers, which are what the engine makes public for it; everything else of both stays inside the crate, so the dead-code lint still says when an opcode has no reader. What its tests build bytecode with is behind the engine's `test-support`, and the test that the backend refuses a stray overflow marker is here.
simlin-tools is what libsimlin's `agent_tools` feature now depends on, so the engine carries no feature for it and a build without the feature compiles none of it. `schema` is the tools' and the formats' alone. It leaves before the layout, which it uses to draw what an edit adds: the engine cannot hold the tools and depend on a layout crate built on the engine.
The check saves and reads back with the formats and runs both sides with the engine, so it is above both. It is not part of the agent tools, which use it: the browser bundle has `simlin_project_check_save` and leaves the tools out.
simlin-layout places what the engine's dependencies and loops say and draws it with the editing core's routing, so it is above both. The engine is left with the compiler, the VM and the analysis of runs, on the data model alone; its unit tests read and edit models with simlin-formats and simlin-edit, which do not depend on it. Two tests that ask the layout and the compiler the same question are in simlin-tests.
The wasm backend's tests hold the code it emits to the VM's own arithmetic, so those functions were public and the compiler could no longer inline them into the one call the VM makes of each. They are `vm_oracle` now, which only `test-support` has. `to_runtime_view`, public on a type the backend reads, and `dense_linear_start` are `#[inline]`: both were calls in the profile of a build without LTO. The dispatch loop is one function big enough that its speed moves several percent with what else is in its codegen unit; with one codegen unit the crates execute the instructions the single crate did, to 0.3%.
The routing is generic over its obstacles, so the layout's calls compiled it a second time, 66 KB of the browser bundle. The layout asks it through functions that take the stocks' centers, and the obstacles and their bounds are the editing core's own again.
The layers it held inside one crate are crates, so cargo refuses a use that goes up and `scripts/check-deps.py` holds the edges between them.
The hook's clippy pass turns on every feature and every dev-dependency, so an item that only a test configuration uses looks used. CI's Build job compiles the default features with warnings denied and fails on it, which a local commit could not see. A second pass over the default features costs a few seconds after an engine edit.
The details panel re-sent the whole variable for every change, with the text
of its one equation field as a scalar equation. An apply-to-all variable's
field also held an "{apply-to-all:}" line, and a per-element variable's a TODO,
so editing either saved that text as a scalar and discarded the dimensions and
every element's equation. The panel now says what the user changed -- the
engine's setEquation, setUnits and setNotes operations, one per field -- and
the engine keeps the rest, modules' units and notes included. Scalars end up
as they did before, except that the engine trims the units it is given.
The equation field holds the equation alone, so what it shows is what a save
sends and the engine's error offsets index it directly; a line beside it names
the dimensions. A per-element variable has no equation field: setEquation there
would set the default its other elements follow, so its equations are listed
read-only, the EXCEPT default with them, until there is an editor for them.
Arrayed variables preview as text, since the engine's LaTeX for them is a
placeholder.
Saving any edit to a lookup dropped the table's x points, so a table given as (0,0), (1,5), (10,9) was saved as three points spread evenly over its x scale even when only the y axis maximum had changed. The handler re-sent the variable with a table it rebuilt by hand, without the x points. It now sends the engine's setLookup operation with the table serialized as everything else serializes one, which also leaves nothing about the variable to re-send. The lookup editor saves the x points it shows, and no longer moves them on its own. The x axis minimum and maximum of a table with x points of its own are the range it is drawn over -- the engine does not read them then -- so changing one leaves the points where they are; they were spread evenly over the new range. Changing the point count does resample, over the x the table covers rather than the range it is drawn over, and always from the table as it was before the count was touched: typing 12 passes through 1, and resampling that one point flattened every table, and putting the count back now puts the points back.
The C API's comments, the conveyor fixtures' README and the layout_eval instrument named modules at the paths they had in one crate. simlin.h changes in those comments alone. With them, three things found while checking the crates one by one. A full wasm build compiled the batch budget that only native builds use. The dependency policy allowed simlin-cli a dependency on libsimlin it is documented not to take. dense_linear_start does not need its inline attribute: its crate's only callers are beside it, and builds without it measure no slower.
cargo-deny reads a path dependency with no version as a wildcard, which the policy denies, and it is not one of the hook's checks.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1098 +/- ##
==========================================
+ Coverage 92.88% 93.01% +0.13%
==========================================
Files 318 300 -18
Lines 198542 192638 -5904
==========================================
- Hits 184408 179177 -5231
+ Misses 14134 13461 -673 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #1094
Fixes #1097
Fixes #473
Fixes #478
Fixes #828
Fixes #916
Fixes #918
Fixes #945
Fixes #1046
A one-line engine edit cost about 13.5 s before a unit test could run: rustc rebuilds a whole crate, and the engine was one crate of 606k lines.
This splits it into crates so an edit rebuilds only what depends on it, removes simlin-serve, and fixes two editor bugs that lost people's work on app.simlin.com.
The crates
There is no facade crate, and none of these re-exports another: callers name the crate an item is in.
db/analysis)Decisions worth a look:
simlin_project_check_saveand not the agent tools.CompiledSimulation,ByteCodeandByteCodeContext, so their fields are public. What only its tests call is behindtest-support.analyze_modelno longer returns a copy of the model. It made one through the JSON format, which is now above it; simlin-mcp-core makes it.debug-derivefeature is gone; every crate would have had to forward it.simlin-serve is removed
It was never released and nobody uses it.
Cargo.lockgoes from 487 packages to 339, and CI loses the embedded SPA build and two release smoke legs.Loro's chain carried the crate whose license has the lint job red on
main.@simlin/mcpships a Windows binary.docs/threat-model.mdgoes; it described simlin-serve alone. Its security contact moves to the README.ProjectAccessand its version token, though nothing constructsAccessError::VersionMismatchnow.Editor fixes
Editing the equation of an arrayed variable replaced the whole array with one scalar equation, and saving a lookup edit dropped the table's own x points, both without a message.
setEquation,setUnits,setNotes,setLookup) where it used to re-send the whole variable, so a field it does not know about can't be lost.Evidence
test-support, and thin non-generic entry points for flow routing.scripts/gates.sh.--no-default-featuresand--all-featureseach check with warnings denied, as do both wasm builds.simlin.hdiffers frommain's in comments only, and the wasm bundles export the same 119 (full) and 108 (browser) functions.editor-panel-edits-engine.test.tsruns the real editor and engine over 24 kinds of variable and 11 lookup edits; the arrayed rows fail without the fix.variable-details-arrayed.test.tsxcovers what the panel shows. An edit through the notebook widget in Chromium kept its dimensions.What it costs
cargo test --workspace: 15 to about 22 s on 32 cores, since cargo runs the crates' test binaries one after another; about 42 s either way on 4 cores.The VM's dispatch loop is one function whose speed moves several percent with what else lands in its codegen unit: the same code with one more
#[inline]measured +1.1% and +3.6% without LTO, and with one codegen unit the differences go.Not covered
TODO(array), so these variables preview as text.Dependency advisoriesworkflow still fails for rmcp (RUSTSEC-2026-0462).