Jacajack / hdl

A proof-of-concept, Rust-inspired, declarative hardware description language optimized for RTL coding
MIT License
17 stars 1 forks source link

[panic] Declaring a signal with width `128s8` causes panic #342

Closed Jacajack closed 10 months ago

Jacajack commented 11 months ago

Input

module X {}
impl X {
    const ubus<(128s8)> data;
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidSignalWidth', hdllang/src/analyzer/variable.rs:188:38
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/result.rs:1687:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/result.rs:1089:23
   4: hdllang::analyzer::variable::Variable::register
             at ./hdllang/src/analyzer/variable.rs:188:10
   5: hdllang::analyzer::variable_dependency_graph::DependencyGraph::register
             at ./hdllang/src/analyzer/variable_dependency_graph.rs:134:16
   6: hdllang::analyzer::module_implementation_scope::ModuleImplementationScope::register_all_variables_in_scope
             at ./hdllang/src/analyzer/module_implementation_scope.rs:490:4
   7: hdllang::parser::ast::top_definition::module_implementation::ModuleImplementation::codegen_pass
             at ./hdllang/src/parser/ast/top_definition/module_implementation.rs:80:5
   8: hdllang::analyzer::semantical_analyzer::codegen_pass
             at ./hdllang/src/analyzer/semantical_analyzer.rs:229:2
   9: hdllang::analyzer::semantical_analyzer::SemanticalAnalyzer::compile_and_elaborate
             at ./hdllang/src/analyzer/semantical_analyzer.rs:89:5
  10: hdllang::utils::elaborate
             at ./hdllang/src/utils.rs:239:2
  11: hdl::main
             at ./src/main.rs:123:4
  12: core::ops::function::FnOnce::call_once
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Signal building fails in the API. Semantic analyzer should verify that this numeric constant is only valid if preceded by the unary minus operator.

Jacajack commented 11 months ago

On a related note:

module X {}
impl X {
    const ubus<(- -128s8)> data;
}

Produces the following output:

[2023-11-22T18:02:28Z ERROR hirn::elab::multi_pass_elab::signal_graph_pass::gen_signal] Signal data has width -128 which is out of range
[2023-11-22T18:02:28Z ERROR hirn::elab::multi_pass_elab::signal_graph_pass] Module ModuleId { id: 1 } contains errors (InvalidSignalWidth(-128))
module X;
        wire unsigned[383:0] data;

endmodule

  × Error: Invalid signal width
    ╭─[tests/input/ignore/jesus.hirl:74:1]
 74 │ module X {}
 75 │ impl X {
    · ───┬──
    ·    ╰── Other elaboration warning/error occured
 76 │     const ubus<(- -128s8)> data;
    ╰────

Note that the signal width is 383. Perhaps it's not filtered out properly on the HIRN side as well.

Jacajack commented 11 months ago
module X {}
impl X {
    const ubus<(128s8-1s1)> data;
}

Also panics. Not sure if related, needs investigation.