Closed Timmmm closed 8 months ago
If you write it in the same way with the intermediate variables, i.e:
function legalize_dcsr(o : Dcsr, v : bits(32)) -> Dcsr = {
let v = [v with 27 .. 18 = zeros()];
let v : Dcsr = Mk_Dcsr(v);
let v = [v with DEBUGVER = zeros()];
...
}
that should work around the issue.
[v with X = a, Y = b, Z = c]
is being de-sugared into [[v with X = a] with Y = b] with Z = c]
, which is causing the nesting you see in the output (but it should be harmless in the C output it's just extra braces). When the error occurs it starts backtracking trying to find an alternate interpretation of the syntax that could work (by treating v
as a bitvector variable and X
, Y
, Z
as expressions with integer values, and it'll go through all possible combinations).
You could get a similar issue if you nested update_Z(update_Y(update_X(v, a), b), c)
, although it would be a little harder to trigger as it would require multiple bitfields with the same field names.
by treating v as a bitvector variable
Doesn't it already know the type of v
at this point though? Or is it just trying to say "btw this would work if v
was a bitvector"?
Also that explains the slow compilation when there's an error, but what about when it compiles successfully?
Do you think this will be easy to fix or should I just go ahead and rewrite all the code?
I think this should fix it: https://github.com/rems-project/sail/commit/5929b9b958a2a2c614782e5d211556fef383cfa5
That was fast! And it works perfectly. Compile time back to normal :tada:
It didn't affect my Vector compile time issue unfortunately but I guess that's not surprising since that's a C issue, and after looking briefly it doesn't seem like Vector used this syntax anyway. I'm still working on narrowing that down.
Thank you!!
Using the new
[foo with a=b]
bitfield syntax instead ofupdate_a(foo, b)
seems to cause a crazy regression in compile time,This is possibly the cause of https://github.com/riscv/sail-riscv/issues/323 though I haven't checked the vector code to see if it actually does this yet.
Actually it didn't seem to affect the C compilation time much which is a bit different to the vector issue. Anyway something is up!
Here's my test case:
Comment out one of the function versions as appropriate, then compile with:
I had a look at the generated C. The new syntax seems to get a load of nested structs:
Another thing I noticed is that if you make a mistake, like:
Then the old syntax gives this immediately:
With the new syntax it takes 46s and the error message is 165 MB! I think that might be a personal record. It starts like this: