Skip to content

Impossible to set configured_value_ors in a dslx_library to any non-default value. #4995

Description

@allight

Describe the bug
DSLX has a system where you can use configured_value_or<ty>("ident", default_value) to create build-time set constants similar to rusts cfg! or -D macros in C/C++. These values are set using either the configured_values option on build targets that create verilog/xls-ir or with the --configured_values flag on ir_convert.

With the way that these values are propagated right now however only flags in files directly in the srcs build attribute of the ir/verilog target, or in the list of the cmdline have their value set. All other uses of configured_value_or in imported files have their default value, even if the same value is used in the 'top' files.

This behavior is very surprising and is done entirely silently.

To Reproduce

library.x

pub fn foo() -> u32 {
  configured_value_or<u32>("foo", u32:0)
}

main.x

import library;

fn main() -> (u32, u32) {
  (library::foo(), configured_value_or<u32>("foo", u32:0))
} 

BUILD

dslx_library(
  name = "lib",
  srcs = ["library.x"]
)

xls_dslx_opt_ir(
  name = "foo_is_42",
  srcs = ["main.x"],
  dslx_top = "main",
  deps = [":lib"],
  configured_values = {"foo": "u32:42"},
)

xls_dslx_opt_ir(
  name = "foo_is_0",
  srcs = ["main.x"],
  dslx_top = "main",
  deps = [":lib"],
)

Looking at the IR

foo_is_42 returns (0, 42)

foo_is_0 returns (0, 0)

Expected behavior

either:

  1. foo_is_42 returns (42, 42)

or

  1. have a way to set configured_values on the dslx_library too so you can do

BUILD

dslx_library(
  name = "lib",
  srcs = ["library.x"]
)

dslx_library(
  name = "lib_is_42",
  srcs = ["library.x"],
  configured_values = {"foo", "u32:42"},
)

xls_dslx_opt_ir(
  name = "foo_is_42",
  srcs = ["main.x"],
  dslx_top = "main",
  deps = [":lib_is_42"],
  configured_values = {"foo": "u32:42"},
)

xls_dslx_opt_ir(
  name = "foo_is_0",
  srcs = ["main.x"],
  dslx_top = "main",
  deps = [":lib"],
)

#4985 is an implementation of (1) though there were some objections that having the config values be globally scoped like that is undesirable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions