Skip to content

ISyntax: replace SYB traversals with explicit ones#1045

Open
nanavati wants to merge 1 commit into
B-Lang-org:mainfrom
nanavati:isyntax-explicit-traversal
Open

ISyntax: replace SYB traversals with explicit ones#1045
nanavati wants to merge 1 commit into
B-Lang-org:mainfrom
nanavati:isyntax-explicit-traversal

Conversation

@nanavati

Copy link
Copy Markdown
Collaborator

Replaces the two Data.Generics (syb) traversals over ISyntax with explicit ones, and drops the now-unused Data/Typeable derivings from ISyntax and the evaluator heap types.

Motivation

Generic traversals over a compiler IR fail in the worst way available: when a constructor or field is added, everywhere/listify silently skip it rather than failing to compile. The two ISyntax users are rewritten as explicit traversals with exhaustive constructor matches, so any future ISyntax change surfaces at the traversal site as an incomplete-pattern warning. This also removes the obligation to keep Data instances over types embedding IORef-backed heap references, and leaves ISyntax free to evolve its representation without generic-traversal compatibility as a constraint.

Changes

  • IExpand.removeInlinedPositions: the everywhere rewrite becomes an explicit traversal. It must remain lazy — clock/reset/inout wires are cyclic through IStateVar, and only lazy unrolling terminates (now documented at the site). One behavior made explicit rather than incidental: the Pred set is rebuilt with S.map, since PTerm's Ord consults inlined positions and removing them can reorder or collapse elements (this matches the old syb-era rebuild through fromList).
  • bluetcl.find_vmodinfo: listify becomes a direct query, preserving left-to-right, duplicate-keeping order. The site now documents the invariant that makes the direct query complete: VModInfo reaches an IPackage only through ICVerilog — the synthesis boundary re-abstracts every synthesized module as a Verilog wrapper (the same representation as a hand-written import "BVI"), and the richer elaboration products never re-enter package vocabulary.
  • ISyntax.hs / IExpandUtils.hs: drop all Data/Typeable deriving sites (16 in ISyntax, plus PExpr/HeapCell/HeapData), the now-dead DeriveDataTypeable pragmas, and a stale commented-out constrIndex alternative. The remaining syb users in src/comp traverse Verilog syntax only.

Validation

  • Full build clean (install-src, install-extra), typecheck closures for both bsc and bluetcl.
  • Testsuite, clean + localcheck on the exercising directories: 515 PASS / 0 FAIL, including bsc.misc/method_conditions 134/0 (the end-to-end exerciser of -keep-method-conds, the flag gating removeInlinedPositions), bsc.showrules 48/0, and the bsc.bluetcl directories.
  • Behavioral identity spot-check: sysMethodConds_RegWrite.bluetcl-out byte-identical to its golden — position tuples are exactly the data this transformation shapes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LVL9ornS6uf9hVxAuL7GhK

quark17
quark17 previously approved these changes Jul 14, 2026

@quark17 quark17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good. I wonder if deriving can be removed from more files, then? For example, the deriving in IStateLoc.hs, IType.hs, VModInfo.hs, Wires.hs, etc may only have been to support the deriving in ISyntax?

Also, tangentially, PR #722 was interested in removing the syb dependency by at least changing the imports to Data.Data.

Generic.everywhere rebuilds every node of the IModule whether
changed or not; the transformation only rewrites ICon identifiers.
An explicit traversal covers the same reachable ICon sites (heap
references are leaves either way, since the cells sit behind
IORefs), preserves untouched subtrees instead of reallocating
them, and answers the old XXX about IAps recursion explicitly.

bluetcl's find_vmodinfo becomes a direct query (ICVerilog is the
only VModInfo carrier reachable in an IPackage), and with the last
generic traversals gone, the Data/Typeable derivings on ISyntax
and HeapData are removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KHVhEzJpur1ZRjNjpzBVj
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