Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninit error on multi-dimensional Vector #755

Open
quark17 opened this issue Dec 23, 2024 · 0 comments
Open

Uninit error on multi-dimensional Vector #755

quark17 opened this issue Dec 23, 2024 · 0 comments

Comments

@quark17
Copy link
Collaborator

quark17 commented Dec 23, 2024

The following code:

import Vector::*;

(* synthesize *)
module mkTest();
  rule r;
    Vector#(2,Vector#(4,Bit#(8))) v;
    for (Integer i=0; i<2; i=i+1)
      for (Integer j=0; j<4; j=j+1)
        v[i][j] = 0;
    $display("%h", v);
  endrule
endmodule

results in this error, when synthesized (with -verilog, say):

Error: "Test.bsv", line 6, column 35: (G0028)
  `v' uses uninitialized value (the position shown is the object's
  declaration). If this error is unexpected, please consult KPNS #32.
  During elaboration of the body of rule `r' at "Test.bsv", line 5, column 8.
  During elaboration of `mkTest' at "Test.bsv", line 4, column 8.

I thought there was already an issue filed for this, but I don't see one.

A workaround is to give an initial assignment, but then we lose the ability to track whether any elements are not assigned -- for which we would still like to receive uninit errors. It would help if the Vector package exported a function that returns a Vector with uninitialized elements, and then we could replicate that to make a 2D Vector with uninitialized leaves. (Alternatively, if the Vector package defined and exported primMarkVectorInitialized, then we could call that on v -- as a workaround.)

A possible fix might be to define an instance of primMakeUninitialized for Vector n (Vector m a) that doesn't call markVectorUninitialized on the outer Vector. However, if the user failed to initialize one of the elements of the outer Vector, they would get m errors (for each of the elements of the sub Vector). It would be preferable to report just one error. So I'd like to find a better fix.

I assume that the error is because the assignment to v[i][j] is desugared into primUpdateFn applied to v[i], which therefore has to access v[i] that hasn't been assigned. Maybe we need a version of primUpdateFn that, instead of taking the new value of type t, takes a function t -> t that takes the current value as an argument -- and then we could nest calls to primUpdateFn.

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

No branches or pull requests

1 participant