Skip to content

flow: optional lists default to "" and are read without a guard - #4920

Open
oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:tcl-defaults-lists
Open

oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:tcl-defaults-lists

Conversation

@oharboe

@oharboe oharboe commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Thirteen optional lists have no default in variables.yaml, so every script that reads one guards it with env_var_or_empty or env_var_exists_and_non_empty. This gives each one default: "" and reads it plainly. A list that is iterated with foreach or 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.

variable script(s) now
VERILOG_DEFINES synth_preamble.tcl (slang), synth_syn.tcl {*}$::env(X)
synth_preamble.tcl (verific -vlog-define, yosys verilog_defaults -add) ne ""
SYNTH_BLACKBOXES synth_preamble.tcl (slang), synth_syn.tcl foreach
synth_preamble.tcl (verific error, yosys hierarchy -check + blackbox) ne ""
SYNTH_RETIME_MODULES synth.tcl ne "" (the block lists the modules first)
POS_CLKGATE_AND_PORTS, NEG_CLKGATE_AND_PORTS synth.tcl ne "" (-pos/-neg, else the liberty files)
INFER_CLKGATES_EXCLUDE synth.tcl ne "" (* precedes the list)
BLOCKS synth_preamble.tcl foreach
DONT_USE_CELLS synth_preamble.tcl / synth_syn.tcl, global_route.tcl foreach / set_dont_use $::env(X), as floorplan.tcl, global_place.tcl, resize.tcl and cts.tcl already read it
REMOVE_CELLS_FOR_LEC formal_check.tcl lappend ... {*}$::env(X)
PWR_NETS_VOLTAGES, GND_NETS_VOLTAGES final_outputs.tcl, save_images.tcl ne "" (else: the "skipped" message)
FILL_CELLS fillcell.tcl ne "" (else: copy the routed result)
SYNTH_KEEP_MODULES synth.tcl default only, see below

Empty still means off where configs rely on it: asap7/aes-block sets PWR_NETS_VOLTAGES and GND_NETS_VOLTAGES empty (no IR-drop analysis) and gf180/aes-hybrid sets FILL_CELLS empty (no fill cells); both behave as before. BLOCKS is still a plain list in Tcl, and the Makefile's use of it is unchanged: variables.mk applies the defaults after the design and platform config.mk, and ifneq ($(BLOCKS),) sees an empty or unset BLOCKS alike.

Every stage that reads each variable is in its stages: list, or the variable has no stages: list (DONT_USE_CELLS, REMOVE_CELLS_FOR_LEC) and erase_non_stage_variables never erases it. FlowVariables.md renders default: "" as it renders no default, so it is unchanged.

Two reads in synth.tcl keep their helper for now, because rewriting them touches lines that open pull requests change (#4918, #4912): the guard around the SYNTH_KEEP_MODULES loop and set 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.md gets 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:

design flow covers logs differing metrics differing
asap7/gcd separate / KEEP_VARS=1 syn synthesis, grt, fill, IR drop 0 / 0 0 / 0
asap7/gcd SYNTH_USE_SYN=0 separate yosys synthesis 0 0
nangate45/gcd separate / KEEP_VARS=1 yosys synthesis, grt, fill, IR drop 0 / 0 0 / 0
sky130hd/gcd separate / KEEP_VARS=1 same 0 / 0 0 / 0
asap7/aes-block separate / KEEP_VARS=1 BLOCKS (two blocks + parent, to 6_report), IR drop off 0 / 0 0 / 0
gf180/uart-blocks separate / KEEP_VARS=1 BLOCKS, gf180 fill 0 / 0 0 / 0
gf180/aes-hybrid separate FILL_CELLS empty: no fill 0 0

The BLOCKS parents show -dont_use aes_rcon -dont_use aes_sbox (and -dont_use uart_rx) in their abc call, 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 unless FOO is defined: synthesis passes with the yosys, slang and syn frontends, and fails without the define (negative control).
  • SYNTH_BLACKBOXES=<gcd's datapath module> with the yosys, slang and syn frontends: the module is left a black box.
  • SYNTH_RETIME_MODULES=gcd: the retiming ABC pass runs (nangate45/gcd, 416 instances vs 518).
  • asap7/gcd INFER_CLKGATES=1 with POS_CLKGATE_AND_PORTS, with NEG_CLKGATE_AND_PORTS, and with INFER_CLKGATES_EXCLUDE=gcd: clockgate -pos ICGx1_ASAP7_75t_R ENA:CLK:GCLK, clockgate -neg ..., and clockgate -liberty ... * gcd %d.
  • REMOVE_CELLS_FOR_LEC="BUF_X*" in write_lec_verilog on a routed nangate45 design: 7 BUF_X matches left (the CLKBUF_X cells) vs 190 with it empty.
  • nangate45/gcd with FILL_CELLS, PWR_NETS_VOLTAGES and GND_NETS_VOLTAGES empty, and with DONT_USE_CELLS empty, to 6_report. The only difference: with SYNTH_USE_SYN=1 and DONT_USE_CELLS empty, syn synthesis now logs a no-op set_dont_use with 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_TCL hook): 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 except SYNTH_KEEP_MODULES (above). Checked in synthesis (yosys and slang) for VERILOG_DEFINES, SYNTH_BLACKBOXES, SYNTH_RETIME_MODULES, the three clock-gate lists, BLOCKS and DONT_USE_CELLS; in grt for DONT_USE_CELLS; in fillcell for FILL_CELLS (master skips fill silently); in the final report for PWR_NETS_VOLTAGES and GND_NETS_VOLTAGES; in write_lec_verilog for REMOVE_CELLS_FOR_LEC.

tclint/tclfmt 0.9.0 are clean; flow/test test_generate_vars.py and test_make_issue.py pass; 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; the BLOCKS arms ran with it, to the end.)

🤖 Generated with Claude Code

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]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@openroad-ci

openroad-ci commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

🔍 QoR check

Metrics reflect the PR merge build — i.e. what will land on the target branch.

Commit 86dcbdc · Jenkins build #1 · Baseline: build · View build on dashboard

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 58710a4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants