Repository navigation
engine: refuse a systems stock named for the clock - #1088
Conversation
A systems-format stock named time (or dt, initial_time, final_time) takes the clock slot's key in the results, where every host reads the clock by name. The CLI printed the clock under "time" and silently dropped the stock's series. The importer now refuses such a stock with an error naming the stock and its line, the same rule a patch rename keeps; the check reuses db::is_implicit_global rather than a second list. Other builtin names (pi, time_step, starttime, stoptime) stay legal, since the translator quotes them and equations read the stock. The check sits in the lexer's stock-name validation, the one place every stock reference passes through with its line number. The CLI's skip of a stock whose canonical name is time is dead now and removed, as is the integration test that pinned the old collision.
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. |
|
Reviewed the diff. The lexer check correctly rejects clock-named stocks at every reference site (plain, parameterized, infinite Overall correctness: correct. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f98984801
ℹ️ 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".
| }); | ||
| } | ||
| } | ||
| if crate::db::is_implicit_global(&crate::canonicalize(name)) { |
There was a problem hiding this comment.
Reject clock-named stocks during systems export
When a valid non-systems project, such as one loaded from XMILE or JSON, contains a stock named time, dt, initial_time, or final_time, systems::writer::project_to_systems still formats it as an ordinary stock and returns Ok; simlin_project_serialize_systems therefore reports a successful export. The resulting text now deterministically fails in open_systems at this check, so the writer can emit an artifact its paired reader cannot consume. Add the same representability check to export and return an error, or otherwise ensure writer output remains parseable.
AGENTS.md reference: src/simlin-engine/AGENTS.md:L27-L29
Useful? React with 👍 / 👎.
A systems-format stock named
timesimulated, but its series took the clock's key in the results, so the CLI printed the clock undertimeand silently dropped the stock.The same holds for the other clock names (
dt,initial_time,final_time).The systems reader now refuses such a stock, as a returned error that names the stock as written and its line:
What counts as a clock name comes from
db::is_implicit_global, the rule a patch rename already uses, not a second list.The check is in the lexer's stock-name validation, which every stock reference passes through and which already knows the line.
Other builtin names (
pi,time_step,starttime,stoptime) stay legal: the translator quotes them, so equations read the stock.With these names refused, the CLI's skip of a stock named
timeinprint_filtered_tsvandprint_filtered_tsv_comparisoncould never fire, so it is removed.The integration test that pinned the old collision (
visible_stocks_includes_time_named_stock) goes with it.Nothing in
test/names a stock after the clock.Evidence
systems::parser::tests::a_stock_named_for_the_clock_is_refused: every name indb::IMPLICIT_GLOBALS, in lower, upper and title case, at each place a line names a stock (stock-only, with parameters, infinite, flow source, flow destination, flow with no rate), is refused withline 3:and the stock's name. Names that only contain a clock name (time2,time_spent) are accepted.systems::translate::tests::a_stock_named_like_a_builtin_is_read_as_the_stock: takes every zero-argument builtin name and alias and splits them withis_implicit_global. It checks that the clock names are exactlyIMPLICIT_GLOBALSand thatopen_systemsrefuses each one. Every other name must simulate the same as the model with the stock nameda.simlin simulateonA(5) > Time @ 1exits 1 with the message above.What this does not establish: the CLI has no test harness, so its column printing is covered only by reading the code and the manual run. Formula references to an undeclared
timeare unchanged: they are undeclared names like any other, as before.Fixes #440