Repository navigation
engine: make an MDL save keep the model it saves - #1076
Conversation
Codex Review SummaryThis 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 #1076 +/- ##
==========================================
+ Coverage 92.66% 92.70% +0.04%
==========================================
Files 308 311 +3
Lines 188506 190063 +1557
==========================================
+ Hits 174672 176194 +1522
- Misses 13834 13869 +35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Review of PR #1076Reviewed the full diff (~14k lines) with focus on correctness bugs in the MDL reader/writer, engine builtins (TRUNC/REM/QUANTUM), VM/WASM lowering, LTM polarity, XMILE panic fixes, and unit checking. Findings: none that meet the bar for flagging. Specific areas verified:
Caveats (surfaced by comments in the code, not bugs):
Overall correctness verdict: correct. The patch is internally consistent across VM/WASM/codegen/LTM/units, has extensive proptest and corpus-gate coverage, and the save-meaning table ratchets both ways so a regression on any corpus file fails CI. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47f6607237
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pub fn uid_span(&self) -> i32 { | ||
| self.elements | ||
| .last_key_value() | ||
| .map_or(0, |(uid, _)| uid.saturating_add(26)) |
There was a problem hiding this comment.
Avoid saturating composed view UIDs
When the first view in a multi-view MDL contains a UID at or above i32::MAX - 25—a case the new map representation explicitly permits—this clamps its span to i32::MAX. compose_views consequently assigns that offset to the next view, and convert_view saturating-adds every positive local UID there to the same i32::MAX value. Elements in subsequent views therefore receive duplicate UIDs, so links and aliases can attach to the wrong element; use checked wider arithmetic or reject/remap overflowing UIDs instead of saturating them.
Useful? React with 👍 / 👎.
| return Vec::new(); | ||
| }; | ||
| let held: HashSet<Vec<String>> = slots.iter().map(|slot| key_parts(&slot.0)).collect(); | ||
| product(axes) |
There was a problem hiding this comment.
Bound EXCEPT warning expansion
When an arrayed variable has an :EXCEPT: default the writer cannot represent—for example, an external-data default—this eagerly materializes the full Cartesian product solely to enumerate undefined elements in a warning. A compact sparse model with four 100-element dimensions therefore attempts to allocate 100 million key vectors and then an enormous message during save, which can hang or exhaust the process; cap/count/sample this diagnostic expansion behind the same kind of production threshold used by the importer, and exercise that threshold through a tiny test-only override.
AGENTS.md reference: AGENTS.md:L93-L95
Useful? React with 👍 / 👎.
| if is_mdl_quoted_ident(name) { | ||
| return name.to_owned(); |
There was a problem hiding this comment.
Escape newlines inside pre-quoted identifiers
When a project supplied by XMILE or the API contains an already-quoted identifier whose interior has a real newline, this early return emits that newline verbatim even though the new rustdoc promises the \n escape. Because format_sketch_name delegates here too, the newline splits the comma-delimited sketch record as well as the equation identifier, producing an MDL file that cannot reliably re-import; preserve underscores without bypassing newline and trailing-backslash escaping for the quoted interior.
AGENTS.md reference: AGENTS.md:L117-L120
Useful? React with 👍 / 👎.
The MDL reader and writer disagreed on arrayed dimensions, element spelling, PULSE, INTEGER/MODULO, names and groups, so a save could re-import as a different model, and the writer could write equations Vensim refuses. The reader settles each axis on a named dimension of exactly the elements defined, else the smallest, first declared (GH #1059). It keys elements canonically, spells a reference as its definition does, and reads a declared `dt` or `pi` as the variable. It imports INTEGER and MODULO as TRUNC and REM, and PULSE / PULSE TRAIN as the comparisons Vensim documents. It refuses a list of the wrong length and a range or product past a bound rather than guess or abort. The writer names dimensions through number lists, grouped left-hand sides and :EXCEPT: equations, never writing one that defines no element. It keeps subscript ranges on their left-hand side, writes a builtin as Vensim's keyword and a variable as its name, and warns where MDL cannot hold the model. save_roundtrip_tests, writer_proptest, import_determinism_tests, mdl_vensim_truth and save_meaning's table hold the reader and writer to this.
The writer's pass that spells a view element's name as its definition is written used SharedVec::edit_each, which main replaced with update: a pass that reads an element and returns its replacement, so it cannot change one and leave it out. The pass returns the renamed element.
47f6607 to
f6b852e
Compare
The warning for an :EXCEPT: default that cannot be written built the whole product of the variable's elements to name the ones only the default defines: four dimensions of 100 elements took 90 seconds and a 1.67 GB message on save. It names a dozen, walking the product lazily, and counts the rest by arithmetic. An already-quoted name was written as it stands, a real newline inside it included, which splits the equation and the sketch record that names it. A newline is written as the escape, and a final backslash is doubled so it cannot escape the closing quote.
|
Follow-up commit e975765 for the Codex review:
|
Why
A fresh-eyes review of the MDL (Vensim) reader and writer found that a save could re-import as a different model: arrayed variables changed dimensions, elements were respelled,
PULSEandINTEGER/MODULOhad the wrong meaning, and a variable nameddtwas writtendt = dt. Some saves were equations Vensim refuses, and some files aborted the reader.What
dtorpiis read as the variable;:EXCEPT:;INTEGER/MODULOas the engine'sTRUNC/REM, andQUANTUMfor a quantum at or below zero (Vensim'sfn_integer,fn_modulo,fn_quantumpages; theroundingandsubscripted_roundoutputs intest/);PULSE/PULSE TRAINperfn_pulse,fn_pulse_trainandpulsetrain.dat;:EXCEPT:over the variable's dimensions or a subrange its default names, else element equations with a warning;VMAX/VMIN/VECTOR RANK; bit-exact numbers;NaN, a nestedACTIVE INITIAL, functions Vensim lacks, and partial arrays.TRUNC/REMbuiltins;QUANTUM/REMarguments must share units;TRUNCpropagates link polarity; the LTM zero-slot classifier reads builtin signatures.Decisions worth a reviewer's eye
PULSEwidths of half a step or less,MODULOwith a negative divisor, an excepted element nothing defines (it stays undefined), a wrong-length number list (refused).truncandremare now reserved call names, andQUANTUM(x, q <= 0)returns its input for every format.Evidence
.mdlkeeps its datamodel through a save, with no exceptions listed, and every written equation obeys Vensim's subscript-range rule. On the save-meaning table, 64 MDL saves that used to change their model now keep it; 51 rows remain, each with a cause. The Vensim-truth gate pins each differing series by name (667 series) and fails both when a listed series starts matching and when an unlisted one differs.INTEGER/MODULO/QUANTUMaccount for 35 of the moved series, in 2 files, all closer to Vensim.:EXCEPT:equations that broke Vensim's rule; the second found two saves the fix round had regressed. All are fixed and pinned.subscripted_lookupsmoves from differing to matching Vensim, and the threeDELAY FIXEDmodels move from differing to refused.What this does not establish
PULSEwidths of half a step or less,PULSE TRAINintervals,MODULOwith a negative divisor.dt/pireading moves no corpus series, so it rests on the rule, not on Vensim output.ROUND,INT,MOD), conveyors and queues, an:EXCEPT:default naming a mapped range (written as element equations), variables over some elements of a dimension.PULSEsaved as MDL can still differ for intervals that are not binary fractions; the writer's expression should be rewritten against the engine's pulse rule as engine: count a run's steps and read its rows by time #1075 states it, which is a follow-up.Fixes #1059
🤖 Generated with Claude Code
https://claude.ai/code/session_01LYR7N9WZwQuFnZFW8JDUgx