Give cross()/above()/timer()/absdelta() real signatures (VAMS-2023 §5.10.3, Mantis 7810) - #31
Merged
Conversation
`collect_event_stmt` collected a bare-path event expression (the named-event case) but dropped every call-shaped one into `_ => Event::Cross` without collecting it, so the arguments of the four analog event functions were neither name-resolved nor type-checked. `@(cross(1.0,2,3,4,5,6,7,8))` and `@(timer(undeclared, bogus))` both compiled with zero diagnostics. Add the four as builtins with the LRM signatures from 5.10.3.1-5.10.3.4: cross ( expr [ , dir [ , time_tol [ , expr_tol [ , enable ] ] ] ] ) above ( expr [ , time_tol [ , expr_tol [ , enable ] ] ] ) timer ( start_time [ , period [ , time_tol [ , enable ] ] ] ) absdelta ( expr , delta [ , time_tol [ , expr_tol [ , enable ] ] ] ) `dir` and `enable` are integers, the rest are reals. Every argument is an `analog_expression`, so the tolerances are dynamic -- the LRM explicitly permits `time_tol` and `expr_tol` to change during the simulation -- which matches the rule applied to `transition()` for Mantis 7810. `Event::Cross` now carries the call so it is inferred and validated. The event expression is validated in the event context, so it may read natures but not use analog operators, and an event function used anywhere other than as the event expression of an event control is rejected (5.10.3), including when nested inside another event function. The call is never lowered: the event condition still takes no part in scheduling and the guarded body is always evaluated, so this is a front-end only change. `named_events.mir` moves only in its source-reference tags. Also deduplicate the candidate list in the type-mismatch diagnostic; with five `cross` signatures sharing a real first argument it printed "expected real value, real value, real value or real value". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Part of #19 (VAMS-2023 alignment). This is the remaining half of Mantis 7810 — #30 fixed
transition()'s tolerances, this one gives the four analog event functions real signatures.The gap
collect_event_stmtcollects a bare path event expression (the named-event case added in #29) but drops every call-shaped one into_ => Event::Crosswithout collecting it. The arguments ofcross/above/timer/absdeltawere therefore never name-resolved and never type-checked — the four names were not in scope at all, and the expressions inside@(...)reached no analysis. On currentmobboth of these compile with zero diagnostics:What this changes
The four functions become real builtins with the VAMS-2023 §5.10.3.1–5.10.3.4 signatures:
dirandenableare integers, everything else is real. Every argument is ananalog_expression, so none of the tolerances has to be a constant — the LRM explicitly permitstime_tolandexpr_tolto change during the simulation (§5.10.3.3, §5.10.3.4). This matches the dynamic-tolerance rule #30 applied totransition().hir_def:Event::Crosscarriescall: Option<ExprId>, andcollect_event_stmtcollects a call-shaped event expression (the shape Add analog named events (VAMS-2023 §5.10.4, Mantis 7809) #29 established for named events).hir_ty: the call is inferred, so arity, argument types and name resolution are all checked. The event expression is validated in theEventControlcontext, so it may read natures (@(cross(V(a)))) but not use analog operators.The call is deliberately never lowered. The event condition still takes no part in scheduling — the guarded body is always evaluated, exactly as before — so this is a front-end-only change. The one snapshot that moved (
named_events.mir) moved only in its@XXXXsource-reference tags, by exactly the number of newly collected expressions; the instruction stream is byte-identical.Also deduplicates the candidate list in the "type mismatch" diagnostic. With five
crosssignatures that all take a real first argument, the old code printedexpected real value, real value, real value or real value; it now prints each distinct requirement once.Not in scope
Two pre-existing parser gaps are unchanged and still rejected, both of which predate this PR:
analog_expression_or_null— the null-argument form,cross(expr, dir, , , enable).analog_event_expression or analog_event_expression—@(cross(...) or timer(...)).Test plan
ui/event_functions.va— every arity of all four functions, with tolerances that are variables rather than constants, plus integer/real conversion cases. Compiles clean.ui/event_functions_err.va+.log— too many arguments, too few arguments, unresolved names, wrong argument type, an event function used as an expression, and one nested inside another.integration_tests/VAMS2023_EVENT_FUNS— all four functions, all arities, run-time tolerances, compiled end to end through OSDI.cargo test -p hir -p hir_ty -p hir_def -p hir_lower -p basedb -p sourcegen -p preprocessor -p syntax -p parser -p tokens -p mir -p mir_autodiff -p mir_build -p mir_interpret -p mir_opt -p sim_back— green.cargo test --release -p openvaf-driver -p openvaf -p osdi -p mir_llvm --features llvm18— green, including the behaviouraladc,cross_latch,cross_arrayandqam16tests, whose.snapdescriptors are unchanged.RUN_DEV_TESTS=1over the full integration suite — all 33 models (BSIM3/4/6, BSIMBULK/CMG/IMG/SOI, PSP102/103, HICUML2, HiSIM2/HV/SOTB, MEXTRAM, EKV, MVSG_CMC, DIODE_CMC, …) produce identical frontend diagnostics. This change can newly reject models that were passing garbage, so that sweep was the point; nothing regressed.cargo fmt --all -- --check— clean.