8000 Configuration via trait-bound generics by rw1nkler · Pull Request #5589 · google/xls · GitHub
[go: up one dir, main page]

Skip to content

Configuration via trait-bound generics - #5589

Draft
rw1nkler wants to merge 5 commits into
google:mainfrom
antmicro:109013-trait-bound-generics
Draft

rw1nkler wants to merge 5 commits into
google:mainfrom
antmicro:109013-trait-bound-generics

Conversation

@rw1nkler
@rw1nkler rw1nkler commented Dec 1, 2026
Copy link
Copy Markdown
Contributor

Add trait constants to DSLX and allows a struct implementing a trait be passed as a generic type parameter, so a configuration can be a type instead of a long list of parametrics:

trait RamConfig {
    const SIZE: u32 = u32:256;
    const INITIALIZED: bool = false;
}

struct SmallRam {}

impl RamConfig for SmallRam { const SIZE = u32:16; }

proc Wrapper<T: type> {
    const ADDR_WIDTH = std::clog2(T::SIZE);
    ...
}

T::CONST resolves to the impl's override, falling back to the trait's default. Requires #![feature(traits)] and #![feature(generics)].

  • Every trait constant has a default value
  • impl overrides any subset of the constants and rest keep trait's defaults
  • Using other fields of defined trait is possible via Self::NAME, constants using Self need an explicit type
  • Public trait from other module can be implemented as impl other_mod::Cfg for S

Signed-off-by: Kornel Uriasz <kuriasz@antmicro.com>
Signed-off-by: Kornel Uriasz <kuriasz@antmicro.com>
Signed-off-by: Kornel Uriasz <kuriasz@antmicro.com>
Signed-off-by: Kornel Uriasz <kuriasz@antmicro.com>
Signed-off-by: Kornel Uriasz <kuriasz@antmicro.com>

This branch has not been deployed

No deployments
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

0