Skip to content

script: filter out unreachable files#297

Open
fischeti wants to merge 11 commits into
masterfrom
fischeti/filter-script
Open

script: filter out unreachable files#297
fischeti wants to merge 11 commits into
masterfrom
fischeti/filter-script

Conversation

@fischeti
Copy link
Copy Markdown
Contributor

@fischeti fischeti commented Apr 2, 2026

script

Similar to the pickle command, the script command gains a new --top flag (can be specified multiple times), that will filter out all unreachable files from said top modules.

bender-slang

Changes resp. fixes the behaviour for duplicate defined symbols. The previous behaviour was actually wrong (also in the pickle command) because it was first-one-wins. Now it is last-one-wins which is also what all EDA tools do afaik.

Further, it adds a slang diagnostic language whenever a module name already exists. The diagnostic is slang style and reuses slang infrastructure for this.

Tests

Integration tests

There are now integration tests for script flist output to check for existence of files (or the lack thereof). The pickle repo test suite is extended for that with an example of a duplicate module definition.

Real-world tests

Tested in cheshire for vsim and vcs target here, pipeline passes. Reduces file list from 670 to 444.

Also tested in FlooNoc for vcs and synopsys (elaboration), where it even discovered a duplicate file in the bender manifest🤓

TODOs

  • Bump bender-slang once approved

@fischeti fischeti force-pushed the fischeti/filter-script branch 6 times, most recently from 0d4580e to 7930fa6 Compare April 2, 2026 14:10
@fischeti fischeti force-pushed the fischeti/filter-script branch 2 times, most recently from 4967432 to c36b891 Compare April 9, 2026 15:31
@fischeti fischeti marked this pull request as ready for review April 9, 2026 16:26
@fischeti fischeti requested a review from micprog April 9, 2026 16:26
@micprog
Copy link
Copy Markdown
Member

micprog commented Apr 16, 2026

One question - does this also filter out the include directories if they are not required? I think that would be useful when restricting the file list.

fischeti and others added 9 commits June 2, 2026 00:20
- script: scope the HashSet import to filter_srcs_by_top so a
  --no-default-features build no longer emits an unused-import warning
- tests/script: assert exact basename-set membership instead of substring
  containment — "top.sv" previously also matched "unused_top.sv", so
  passing tests didn't actually prove what they claimed
- bender-slang/analysis: guard getSourceBufferIds()[0] with an empty
  check, falling back to "<unknown>" in the duplicate-decl warning

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- bender-slang/analysis: replace the STDERR_IS_TTY macro with a small
  stderr_is_tty() helper, lift the duplicate-decl DiagCode and message
  format to file-scope named constants, and cache one
  DiagnosticEngine+TextDiagnosticClient per distinct SourceManager
  instead of constructing fresh ones on every collision. Trees within
  one parse group share an engine; trees across groups get separate
  ones (each SlangContext owns its own SourceManager).
- bender-slang/analysis: the "top module not found" error now reports
  the number of known top-level declarations, which makes "no such
  module" vs "parser saw nothing" easy to distinguish at a glance.
- script: clarify in the --top help text that only Verilog files are
  trimmed; VHDL and untyped files are always retained.
- script: restore the small `concat` helper that the original feature
  commit replaced inline; the inline form (`[xs as &[_], ys].concat()`)
  was a drive-by unrelated to the filter feature and reads worse.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pure reformat of the previous cleanup commit — no behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extend the slang-based filtering to also drop `+incdir+` entries that
slang did not actually resolve any `include directive through. A new
--trim-incdirs flag controls the behavior:

  auto   (default) drop iff --top is set
  always drop unused directories even without --top
  never  keep every directory declared in Bender.yml

bender-slang exposes a new resolved_include_paths_for() helper that
walks each requested tree's getIncludeDirectives() and returns the
deduped canonical paths from getFullPath(). The Rust side compares
those paths against each SourceGroup's include_dirs / export_incdirs
via Path::starts_with (with canonicalize() so symlinks and relative
segments don't cause false negatives).

The file/include-dir filters are now independent: filter_srcs_by_top
was renamed to apply_slang_filters, which only filters files when --top
is non-empty and only trims include dirs when asked. The "no top, no
trim" path short-circuits without spinning up a SlangSession.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@micprog micprog force-pushed the fischeti/filter-script branch from ab1d778 to 9abbc1c Compare June 1, 2026 22:20
micprog and others added 2 commits June 2, 2026 00:46
The new include-dir filter used std::fs::canonicalize to normalize each
SourceGroup's include path before checking it against the canonical
paths slang resolved through. On Windows that returns the `\\?\C:\...`
UNC form, while slang's internal `fs::weakly_canonical` returns plain
`C:\...`. Path::starts_with then never matches, so every include
directory was being dropped on Windows — the new tests fail because
incdir_basenames returns an empty set.

Use the same cfg-gated `canonicalize` import that sess.rs / cli.rs /
cmd/parents.rs already use (std::fs on Unix, dunce on Windows). This
matches the form slang emits and restores prefix matching on Windows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The new --trim-incdirs tests use an incdir_basenames helper that
rsplits each `+incdir+` line on '/' and asserts membership of bare
directory names like "include". On Windows, the Bender.yml entry
`include` is joined with the workspace root using '\\', producing a
fully-backslash path with no '/' anywhere — rsplit returns the whole
path and the assertion fails.

Source-file tests were unaffected because Bender.yml uses entries like
`src/top.sv` (with an embedded '/'), so the final path stays mixed
('\\…\\pickle/src/top.sv') and rsplit('/') still finds 'top.sv'.

Factor out a small `basename` helper that walks back to the last '/'
or '\\' before slicing. Both `source_basenames` and `incdir_basenames`
now use it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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