aft icon indicating copy to clipboard operation
aft copied to clipboard

Feature request: Add SystemVerilog support

Open henry-hsieh opened this issue 1 month ago • 8 comments

Description

I’d like to contribute first-class SystemVerilog support to AFT. I’d like to align on the architecture and feature scope first.

The proposal is to extend AFT’s existing tools with complementary source-structural and compiler-backed views of HDL projects.

Architecture

Two complementary frontends

  • Use tree-sitter-systemverilog for written-source structure: symbols, outlines, source zoom, structural search, and AST-based edits. These capabilities should remain available without a configured or successfully compiling design.
  • Use Slang, through Rust bindings, for configured-design semantics: resolved declarations, types, references, package imports, procedural calls, argument bindings, and elaborated hierarchy.

Tree-sitter describes the source as written; Slang explains its meaning within a selected build. Physical declarations and elaborated instances should remain distinct in the tool results.

A shared compiler service in the Rust engine

Keep compiler integration in the engine so OpenCode, Pi, standalone, and Subc share the same behavior. Run native Slang compilations in a supervised helper process and return bounded, owned compiler facts rather than sharing native compiler objects across engine threads.

Analyze captured source snapshots, with filelists, includes, and library loading mediated by AFT’s file-access policy. Cache analysis per checkout and selected build, invalidating it when source files, configuration, or dependencies change.

Explicit build context

Support named build profiles containing source files and filelists, include directories, macro definitions, library files/directories, top modules, and compiler options. Compiler-backed tools should consistently use the selected profile, while structural tools remain independent of build configuration.

Complementary LSP integration

Integrate slang-server through AFT’s existing LSP infrastructure for diagnostics, definition/reference navigation, and rename proposals. Use the compiler service for captured build analysis and validation of proposed changes.

Features

Area Proposed capabilities
Reading Structural outline and zoom; compiler-resolved declaration/type views; a separate elaborated hierarchy view.
Navigation Definitions, references, and compiler-resolved procedural callgraph queries based on declaration identity.
Imports Scope-aware package import add/remove/organize, with compiler-backed checks that existing bindings are preserved.
Editing Selected-build compilation validation for writes, text edits, symbol edits, and coordinated AST replacements.
Rename Reference-aware rename with compiler validation of proposed edits and affected bindings.
Tracing Procedural value flow through assignments and function/task arguments, accounting for argument directions.
Refactoring Compiler-validated extract, inline, and top-level declaration moves, introduced incrementally through explicitly supported cases.

Compilation acceptance and binding preservation are different checks: an edit can compile while changing which declaration a name refers to. Tools should make that distinction clear and report partial coverage when errors or unsupported constructs prevent a complete answer.

Integration approach

Extend the existing AFT tools rather than introduce a separate HDL tool suite. Keep harness adapters thin and preserve shared preview, backup, undo, cancellation, and path-policy behavior.

Would this dual-frontend architecture fit AFT’s direction? If so, I’d propose incremental contributions: structural support and LSP integration, then the shared compiler service and semantic tools, followed by validated editing and refactoring.

Use case

SystemVerilog projects commonly depend on filelists, include paths, macros, packages, libraries, and selected top-level modules. Understanding a file in isolation is often insufficient to resolve a reference or determine the effect of an edit.

This would let coding agents use AFT’s existing workflow to:

  • Explore source structure immediately, even before the design builds successfully.
  • Resolve references and procedural calls using the actual build context instead of matching names alone.
  • Inspect elaborated instances while retaining links to their physical source definitions.
  • Follow procedural data flow across assignments and function/task boundaries.
  • Edit imports, rename declarations, and perform supported refactors with compiler-backed checks before applying changes.
  • Validate coordinated edits against the selected design and use the existing preview/undo workflow.

Keeping these capabilities in AFT’s shared engine would make them available consistently across supported harnesses, including mixed-language repositories containing HDL alongside software and build tooling.

henry-hsieh avatar Oct 24 '26 02:10 henry-hsieh

Thanks for the detailed proposal, @henry-hsieh.

The first two parts fit how AFT supports other languages, and we would welcome contributions for them:

  1. Structural support with tree-sitter-systemverilog: symbols, outline, zoom, structural search and replace, and syntax checks after edits. A new language plugs in through crates/aft/src/language.rs and parser.rs. Import editing would be a SystemVerilog engine under crates/aft/src/imports/.
  2. slang-server through the existing language-server layer (crates/aft/src/lsp/): diagnostics in aft_inspect and after edits, plus definition and reference navigation.

We would like to hold off on the embedded Slang compiler service for now. AFT gets semantic answers from language servers rather than embedding compilers. A native C++ dependency would also have to build and ship in the release binaries for macOS, Linux and Windows. Once structural support and slang-server are in, we can look at which answers slang-server cannot give and decide then whether a compiler service is worth it. Build profiles (filelists, include paths, defines, top modules) are probably best left to slang-server's own project configuration rather than new AFT settings.

For a first PR, please keep it to the tree-sitter support, with tests on a small real design that uses packages, interfaces and includes. A draft PR early is welcome, so we can agree on the shape before it grows.

aft-alfonso[bot] avatar Oct 24 '26 16:10 aft-alfonso[bot]

I have completed the structural support with tree-sitter-systemverilog in #985. The slang-server and slang compiler integration is held for now.

henry-hsieh avatar Oct 27 '26 13:10 henry-hsieh

@ualtinok, would you be open to discussing whether AFT could support SystemVerilog?

SystemVerilog is one of the most complex languages, but it’s also widely used across the IC design industry. Giving LLMs access to SystemVerilog syntax and diagnostics could make them much more helpful for development.

I understand that supporting every language in AFT’s current implementation may be difficult, especially since the SystemVerilog tree-sitter parser is much larger than those for many other languages. I’d be happy to explore ways to integrate tree-sitter parsers without adding maintenance burden—for example, dynamically loading parsers instead of statically linking them into the AFT binary, as editors like Neovim and Helix do.

henry-hsieh avatar Oct 31 '26 07:10 henry-hsieh

Hi @henry-hsieh,

We will definitely support it but needs a bit time because we're currently benchmarking grammar support via wasm which will help us support every language that Zed supports (albeit with an overlay as AFT does have more complex requirements)

Will keep you updated!

ualtinok avatar Oct 31 '26 09:10 ualtinok

Thanks for the information. It's definitely better than that we keeps adding more and more languages inside the AFT binary and makes the AFT binary size fat. Looking forward to the updates!

henry-hsieh avatar Oct 31 '26 09:10 henry-hsieh

Hi @henry-hsieh,

The benchmark is done, and we're going ahead with grammars loaded as WebAssembly for languages outside AFT's built-in set. In our measurements they produce the same parse trees as built-in grammars and parse about 1.5 to 2 times slower. That's a good trade for less common languages, and it keeps their parser code out of the AFT binary for everyone else. Each grammar will be pinned to a reviewed version and checked before AFT loads it.

A grammar alone gives parse trees, not outlines or call graphs, so each language also needs its own symbol and call extraction in AFT. Luau goes first to prove the loader, then SystemVerilog.

Your work in #985 is still useful: the SystemVerilog symbol extraction can move onto the loader once it lands. We'll comment there when the loader is ready, and you're welcome to port it then if you'd like.

aft-alfonso[bot] avatar Oct 31 '26 21:10 aft-alfonso[bot]

Now that AFT ships a downloadable WASM grammar for Luau, would you be open to a small first PR that brings SystemVerilog onto the same path? I’d start from the latest upstream main, leave #985 unchanged, and reuse its symbol extractor and test design.

The first version would support aft_outline and aft_zoom for .sv, .svh, .v, and .vh. In a local test, the native and WASM parsers produced identical syntax trees for all five files in #985’s design. I’d add tests that check for the expected modules, interfaces, packages, functions, and tasks, and verify that AFT can reuse the cached grammar offline and gives a clear error if it isn’t available.

I’d leave AST search, replace, and edit validation for a follow-up. Outline and zoom already let AFT set up the parser, but ast-grep starts its own parser without WASM support. AFT would need to parse both the search pattern and the target file before handing their syntax trees to ast-grep. Edit validation would use the same parser to distinguish invalid syntax from a check that couldn’t run because the grammar was unavailable.

Does that sound like the right first step, or would you prefer a separate PR to make the loader handle a second grammar first?

henry-hsieh avatar Nov 19 '26 14:11 henry-hsieh

Thanks @henry-hsieh, yes: SystemVerilog as a downloaded grammar is the right path, and outline plus zoom is a good first step. Leaving AST search, replace and edit validation for later makes sense too.

On your loader question: the grammar manifest and loader handle exactly one grammar today (Luau), so they need a small change before a second grammar can ship. We'll make that change on our side as its own PR first, because it touches the pinned-hash manifest and the release job that builds and publishes the .wasm files. We'll post here when it's merged.

For your PR, on top of that:

  • Grammar source: name the upstream tree-sitter SystemVerilog repository and the exact commit you tested with. We build and publish the .wasm from that commit in our own grammar job; please don't commit a built .wasm.
  • Scope: file extensions, the symbol extractor reused from #985, and the outline and zoom wiring.
  • Tests: the expected modules, interfaces, packages, functions and tasks; the offline cached-grammar path; and the error when the grammar isn't available. Please reuse the wording Luau already uses for that error rather than adding a new one.

Once the downloaded path covers SystemVerilog, #985's native grammar is no longer needed, so we'd close #985 when your new PR lands.

aft-alfonso[bot] avatar Nov 19 '26 15:11 aft-alfonso[bot]