Skip to content

fix(base-db): handle included SystemVerilog files as include-only units#29

Merged
hongjr03 merged 10 commits into
masterfrom
feat/macro
May 19, 2026
Merged

fix(base-db): handle included SystemVerilog files as include-only units#29
hongjr03 merged 10 commits into
masterfrom
feat/macro

Conversation

@hongjr03
Copy link
Copy Markdown
Member

@hongjr03 hongjr03 commented May 19, 2026

Closes #27, should be merge after #32.

When a .sv file is reached through a SystemVerilog `include and is also discovered by the workspace scan as a standalone source file, semantic compilation can add the same physical file twice.

In projects without an explicit config, Vizsla currently treats scanned .sv files as semantic roots. For a layout like:

// a_pkg.sv
`include "z_frag.sv"

z_frag.sv is first assigned by slang while preprocessing a_pkg.sv, then Vizsla later tries to add z_frag.sv again as an independent compilation root. slang rejects the duplicate source-manager path and aborts with:

internal compiler error: 'Buffer with the given path has already been assigned to the source manager'

This crashes the language server process.

Change

This PR builds a preprocessor file index from slang directive trivia and uses it to classify literal include targets.

  • Adds a preprocessor index for macro directives, including literal `include targets.
  • Builds compile units per source root / compilation profile.
  • Treats .sv files reached by literal includes as include-only units.
  • Provides include-only files to slang through include buffers.
  • Excludes include-only .sv files from standalone semantic roots.
  • Keeps diagnostics mapped back to included files.

Follow-up

While investigating the LSP crashes, we found a second, separate crash class: semantic requests can also abort when stale borrowed slang syntax nodes outlive their backing SyntaxTree.

That issue is not caused by duplicate include buffers and is intentionally not fixed here. It is handled in #31, which makes semantics syntax ownership explicit and replaces long-lived borrowed syntax nodes/tokens with stable syntax pointers.

@hongjr03 hongjr03 marked this pull request as ready for review May 19, 2026 07:29
@hongjr03 hongjr03 requested a review from roife May 19, 2026 07:29
@hongjr03 hongjr03 marked this pull request as draft May 19, 2026 09:30
@hongjr03 hongjr03 marked this pull request as ready for review May 19, 2026 09:45
@hongjr03 hongjr03 merged commit b169609 into master May 19, 2026
16 checks passed
@hongjr03 hongjr03 deleted the feat/macro branch May 19, 2026 09:45
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.

Crashes when a source file is both included and scanned as a root source

1 participant