google / google/xls

[enhancement] Add warnings for unused imports, parameters, and parametrics in DSLX

Open
#2,141 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

### What's hard to do? (limit 100 words)

Right now, DSLX warns about unused variables and return values, however it doesn’t give clear warnings about unused imports, parameters, or parametrics during type checking. This makes it hard to spot code that isn’t being used, leading to unnecessary clutter. Without proper warnings, developers might miss unused code.

### Current best alternative workaround (limit 100 words)

At the moment, developers have to manually check for unused imports, parameters, or parametrics.
This can be time-consuming and error-prone, especially in larger codebases.

### Your view of the "best case XLS enhancement" (limit 100 words)

It would be very helpful if XLS could automatically show warnings for unused imports, parameters, and parametrics during type checking. This would allow developers to identify and remove unnecessary code early, improving the readability and maintainability of the codebase.

Here is a file showing unused construct that are not reported:

```rust
// Example DSLX file demonstrating unused constructs

// Unused use
#![feature(use_syntax)]
use xls::examples::unused::Unused;

// Unused 'import' (commented out because 'use' is enabled)
// import xls.examples.unused;

// Function with an unused parameter
fn unused_parameter(a: u32, b: u32) -> u32 {
// 'b' is never used
a + u32:1
}

#[test]
fn test_with_unused_parameter() {
assert_eq(unused_parameter(u32:10, u32:20), u32:11);
}

// Function with an unused parametric
fn unused_parametric(value: u32) -> u32 {
// 'WIDTH' is not used
value * u32:2
}

#[test]
fn test_with_unused_parametric() {
assert_eq(unused_parametric(u32:5), u32:10);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.