Repository navigation
Conversation
Thirteen optional lists lacked a default and were read through
env_var_or_empty or env_var_exists_and_non_empty: VERILOG_DEFINES,
SYNTH_BLACKBOXES, SYNTH_KEEP_MODULES, SYNTH_RETIME_MODULES,
INFER_CLKGATES_EXCLUDE, POS_CLKGATE_AND_PORTS, NEG_CLKGATE_AND_PORTS,
BLOCKS, DONT_USE_CELLS, REMOVE_CELLS_FOR_LEC, PWR_NETS_VOLTAGES,
GND_NETS_VOLTAGES and FILL_CELLS. Give each `default: ""` and read it
as $::env(X). A list that is iterated with foreach or spliced with {*}
needs no test: an empty list does nothing. A list whose emptiness
selects a step, or that a flag precedes, is tested with
`$::env(X) ne ""`, which keeps today's behavior, including the configs
that set FILL_CELLS or PWR/GND_NETS_VOLTAGES empty to turn the step off.
Every stage that reads each of them is in its stages: list, or the
variable has no stages: list and is never erased.
Two reads in synth.tcl keep their helper for now, as rewriting them
touches lines that open pull requests change: the SYNTH_KEEP_MODULES
loop's guard and `set synth_blackboxes [env_var_or_empty
SYNTH_BLACKBOXES]`. Both are correct as they are, since the variable
is now always set.
TclContract.md gets the rule.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Øyvind Harboe <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates several Tcl scripts and the variables configuration to align with a new contract rule in TclContract.md. Optional list variables are now defined with a default empty string ("") in variables.yaml, allowing them to be directly iterated or spliced without safety guards like env_var_exists_and_non_empty. Where explicit emptiness checks are still required, they have been simplified to $::env(VAR) ne "". I have no additional feedback to provide as the changes are clean and adhere to the repository's style guidelines.
🔍 QoR checkMetrics reflect the PR merge build — i.e. what will land on the target branch. Commit 62 design(s) checked — 0 with regression(s), 0 without a comparable baseline. ✅ QoR is compared against the master build at this PR's merge base |
Thirteen optional lists have no default in
variables.yaml, so every script that reads one guards it withenv_var_or_emptyorenv_var_exists_and_non_empty. This gives each onedefault: ""and reads it plainly. A list that is iterated withforeachor spliced with{*}needs no test at all: an empty list does nothing. A list whose emptiness selects a step, or that a flag precedes, keeps an explicit$::env(X) ne "", which is exactly what the helper tested.VERILOG_DEFINESsynth_preamble.tcl(slang),synth_syn.tcl{*}$::env(X)synth_preamble.tcl(verific-vlog-define, yosysverilog_defaults -add)ne ""SYNTH_BLACKBOXESsynth_preamble.tcl(slang),synth_syn.tclforeachsynth_preamble.tcl(verific error, yosyshierarchy -check+blackbox)ne ""SYNTH_RETIME_MODULESsynth.tclne ""(the block lists the modules first)POS_CLKGATE_AND_PORTS,NEG_CLKGATE_AND_PORTSsynth.tclne ""(-pos/-neg, else the liberty files)INFER_CLKGATES_EXCLUDEsynth.tclne ""(*precedes the list)BLOCKSsynth_preamble.tclforeachDONT_USE_CELLSsynth_preamble.tcl/synth_syn.tcl,global_route.tclforeach/set_dont_use $::env(X), asfloorplan.tcl,global_place.tcl,resize.tclandcts.tclalready read itREMOVE_CELLS_FOR_LECformal_check.tcllappend ... {*}$::env(X)PWR_NETS_VOLTAGES,GND_NETS_VOLTAGESfinal_outputs.tcl,save_images.tclne ""(else: the "skipped" message)FILL_CELLSfillcell.tclne ""(else: copy the routed result)SYNTH_KEEP_MODULESsynth.tclEmpty still means off where configs rely on it:
asap7/aes-blocksetsPWR_NETS_VOLTAGESandGND_NETS_VOLTAGESempty (no IR-drop analysis) andgf180/aes-hybridsetsFILL_CELLSempty (no fill cells); both behave as before.BLOCKSis still a plain list in Tcl, and the Makefile's use of it is unchanged:variables.mkapplies the defaults after the design and platformconfig.mk, andifneq ($(BLOCKS),)sees an empty or unsetBLOCKSalike.Every stage that reads each variable is in its
stages:list, or the variable has nostages:list (DONT_USE_CELLS,REMOVE_CELLS_FOR_LEC) anderase_non_stage_variablesnever erases it.FlowVariables.mdrendersdefault: ""as it renders no default, so it is unchanged.Two reads in
synth.tclkeep their helper for now, because rewriting them touches lines that open pull requests change (#4918, #4912): the guard around theSYNTH_KEEP_MODULESloop andset synth_blackboxes [env_var_or_empty SYNTH_BLACKBOXES]. Both are correct as they stand, since the variable is now always set; whichever lands last can drop them.TclContract.mdgets the rule: an optional list defaults to""and is iterated or spliced without a test.Why
Easier to read:
foreach block $::env(BLOCKS)says what it does. Failures are hard and early: a misspelled or erased variable fails at the line that reads it, where today it silently means "none". And fewer squirrels for AI to chase: a guard around a loop that already does nothing on an empty list is a code path no CI run takes, and an agent reading the scripts chases it instead of the real problem.Test
Full flows, master vs this branch, logs (runtimes, memory and paths dropped) and every stage metric compared:
KEEP_VARS=1synsynthesis, grt, fill, IR dropSYNTH_USE_SYN=0KEEP_VARS=1KEEP_VARS=1KEEP_VARS=1BLOCKS(two blocks + parent, to6_report), IR drop offKEEP_VARS=1BLOCKS, gf180 fillFILL_CELLSempty: no fillThe
BLOCKSparents show-dont_use aes_rcon -dont_use aes_sbox(and-dont_use uart_rx) in theirabccall, and aes-block's report says IR drop analysis is skipped, before and after.Non-default values take effect, identically before and after (0 logs, 0 metrics differ):
VERILOG_DEFINES="-D FOO"with an extra source that does not parse unlessFOOis defined: synthesis passes with the yosys, slang andsynfrontends, and fails without the define (negative control).SYNTH_BLACKBOXES=<gcd's datapath module>with the yosys, slang andsynfrontends: the module is left a black box.SYNTH_RETIME_MODULES=gcd: the retiming ABC pass runs (nangate45/gcd, 416 instances vs 518).INFER_CLKGATES=1withPOS_CLKGATE_AND_PORTS, withNEG_CLKGATE_AND_PORTS, and withINFER_CLKGATES_EXCLUDE=gcd:clockgate -pos ICGx1_ASAP7_75t_R ENA:CLK:GCLK,clockgate -neg ..., andclockgate -liberty ... * gcd %d.REMOVE_CELLS_FOR_LEC="BUF_X*"inwrite_lec_verilogon a routed nangate45 design: 7BUF_Xmatches left (theCLKBUF_Xcells) vs 190 with it empty.FILL_CELLS,PWR_NETS_VOLTAGESandGND_NETS_VOLTAGESempty, and withDONT_USE_CELLSempty, to6_report. The only difference: withSYNTH_USE_SYN=1andDONT_USE_CELLSempty,synsynthesis now logs a no-opset_dont_usewith an empty list (no platform in the tree leaves it empty); its metrics are identical.Unset (in the tool's environment, or in a
PRE_GLOBAL_ROUTE_TCLhook): master runs on as if the list were empty; this branch stops at the read,can't read "::env(X)": no such variable, for each of the thirteen exceptSYNTH_KEEP_MODULES(above). Checked in synthesis (yosys and slang) forVERILOG_DEFINES,SYNTH_BLACKBOXES,SYNTH_RETIME_MODULES, the three clock-gate lists,BLOCKSandDONT_USE_CELLS; in grt forDONT_USE_CELLS; in fillcell forFILL_CELLS(master skips fill silently); in the final report forPWR_NETS_VOLTAGESandGND_NETS_VOLTAGES; inwrite_lec_verilogforREMOVE_CELLS_FOR_LEC.tclint/tclfmt0.9.0 are clean;flow/testtest_generate_vars.pyandtest_make_issue.pypass; this merges cleanly with #4910, #4911, #4912, #4913, #4914, #4915, #4916, #4917, #4918 and #4919. (The gcd and aes-hybrid arms, before and after alike, stop at the final GDS merge, as the klayout Python module is not installed in that environment; theBLOCKSarms ran with it, to the end.)🤖 Generated with Claude Code