Skip to content

tcl: compare strings with eq/ne, not ==/!= - #4913

Open
oharboe wants to merge 3 commits into
The-OpenROAD-Project:masterfrom
oharboe:tcl-eq-ne
Open

oharboe wants to merge 3 commits into
The-OpenROAD-Project:masterfrom
oharboe:tcl-eq-ne

Conversation

@oharboe

@oharboe oharboe commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Strings are compared with eq/ne, not ==/!=.

Tcl's == tries a numeric comparison first: "1e3" == "1000" and "0x10" == "16" are true. A name, type or extension that happens to look like a number would compare equal to another. This changes every ==/!= in flow/scripts, flow/platforms and flow/util whose operand is a string ("NULL", "POWER", "GROUND", "BLOCK", "WC", "BC", ".v", "6_final", a layer direction, ...) to eq/ne. $lib_cells == {} tests a list, so it becomes an [llength ...] check. Numeric comparisons (RECOVER_POWER != 0, getId, resistances, coordinates, [llength $x] == 0, catch codes) are left alone. The rule is added to docs/contrib/TclContract.md.

Why: code that is easier to read (the operator says what the operands are), failures that are hard and early rather than a string quietly passing as a number, and fewer squirrels for an AI reading the scripts to chase: a == that turns strings into numbers is one of them.

env_var_equals (util.tcl) is not touched here; it is owned by #4911.

Behaviour

Unchanged for every real value. Evidence: full flow (make finish, synth through report) on master vs this branch, normalised logs and every stage metric JSON diffed. 0 log differences, 0 metric differences on:

design covers
asap7/gcd, nangate45/gcd, sky130hd/gcd floorplan, pdn, report_metrics, load
gf180/gcd (default and KEEP_VARS=1) gf180/setRC.tcl
ihp-sg13g2/i2c-gpio-expander macro placement
asap7/riscv32i macros: floorplan_macro, pdn, macro_place_util.tcl

(Only failure in every arm, before and after alike: the final GDS merge, as the klayout Python module is not installed here.) flow/util/cell-veneer/* is not run by the flow; checked by tclint/tclfmt 0.9.0 only.

🤖 Generated with Claude Code

Tcl's == tries a numeric comparison first, so "1e3" == "1000" and
"0x10" == "16" are true. Every ==/!= whose operand is a string (a
literal such as "NULL", "POWER", "BLOCK", "WC", or a variable holding
a name, type or extension) becomes eq/ne; a list is tested with llength.
Numeric comparisons are left alone. Adds the rule to TclContract.md.

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 standardizes Tcl string comparisons across the flow scripts by replacing the equality operators '==' and '!=' with the more appropriate 'eq' and 'ne' operators. A review comment correctly identified that a temporary file, 'flow/abc.history', was accidentally included in the commit and should be removed. Additionally, the reviewer provided actionable feedback suggesting more idiomatic Tcl patterns for checking variable existence and string emptiness, which improve the maintainability and readability of the updated scripts.

I am having trouble creating individual review comments. Click here to see my feedback.

flow/abc.history (1-23)

medium

This file (abc.history) appears to be a temporary run file/history file generated by Yosys/ABC during execution. It should not be committed to the repository. Please remove it from the pull request and ensure it is ignored (e.g., by adding it to .gitignore if not already present).

flow/scripts/macro_place_util.tcl (1)

medium

Since find_macros returns a string (constructed via append macros " " $inst in util.tcl), checking if it is non-empty using ne "" is more direct and idiomatic than converting it to a list with llength. This also aligns with the PR's goal of using string comparison operators.

if { [find_macros] ne "" } {

flow/util/cell-veneer/lefdef.tcl (108)

medium

In Tcl, info exists is the standard and most efficient way to check if a variable exists. Using [info vars antennamodel] ne "" is a roundabout way of doing this and is less idiomatic.

          if { [info exists antennamodel] } {

flow/util/cell-veneer/lefdef.tcl (122)

medium

In Tcl, ![info exists antennamodel] is the standard and most efficient way to check if a variable does not exist. Using [info vars antennamodel] eq "" is less idiomatic.

              if { ![info exists antennamodel] } {

flow/util/cell-veneer/lefdef.tcl (133)

medium

In Tcl, ![info exists antennamodel] is the standard and most efficient way to check if a variable does not exist. Using [info vars antennamodel] eq "" is less idiomatic.

              if { ![info exists antennamodel] } {

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Øyvind Harboe <[email protected]>
@oharboe

oharboe commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

Gemini review, checked against the code:

  • flow/abc.history: already removed (stray file from the test runs; gone in the current head).
  • macro_place_util.tcl: Taken: find_macros returns a string (append macros " " $inst), so [find_macros] ne "".
  • lefdef.tcl [info vars antennamodel] to info exists (3 sites): Not taken: equivalent, but a different concern from string comparison; the eq/ne change keeps the logic as written. Happy to do it separately.

@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 76c225c · Jenkins build #4 · 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.

An environment variable is a string even when it holds a list, so the
sibling PRs that read optional lists from the environment test them
with ne ""; the rule now says which test goes with which value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Øyvind Harboe <[email protected]>
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