Propagate annotated widths into range literals in nested arrays (Re: #3564)#3597
Propagate annotated widths into range literals in nested arrays (Re: #3564)#3597DeeveshChowdary wants to merge 3 commits intogoogle:mainfrom
Conversation
|
Thanks for tackling this! |
| // If the array type is annotated, as a user convenience, we propagate the | ||
| // element type to bare (unannotated) literal numbers contained in the | ||
| // array. | ||
| for (Expr* member : node->members()) { |
There was a problem hiding this comment.
@richmckeever should this do something similar and propagate over >1 dimension?
There was a problem hiding this comment.
Hey everyone! Sorry I'm late. Checking-in again on this thread. Hope everyone had a great vacation ( and a pleasant next two months ).
I wanted to know if this issue has already been resolved or if it is still relevant now? If not, we can close this PR and I can probably start working on some other issue :)
Please let me know.
cc: @richmckeever @proppy
There was a problem hiding this comment.
I think it's already resolved with the switch to type inference v2. deduce_expr.cc is gone now, but it's probably worth committing your test, and it should pass now.
|
@DeeveshChowdary did you get a chance to look at @richmckeever's suggestion? |
Hey team!
While looking into #3564, I tracked the bug down to the DSLX type inference for array literals. A range like 0..8 infers the narrowest bit width needed for its endpoints, and when I wrote
let data: u32[8][2] = [0..8, 8..16];the outer annotation only enforced the shape, not the inner element width. Because the type checker only propagated the annotated element type into top‑level literal numbers, theRangemembers kept their narrow widths, so data[0][0] wasn’t a u32 and the assertion failed with mismatched widths.I fixed this by extending the existing propagation... when an array literal has an annotation, we now also push that annotated element type down into the start and end of any unannotated
Rangemembers (resolving through one level if the element type itself is an array). With the endpoints coerced to the target bits type, theRangededuces to the right element width and the nested array becomes u32[8][2] as annotated.I added a regression test mirroring the original repro to lock in the behavior.
Thanks in advance for the review. Wishing everyone a bug free and relaxing holiday season!
Fixes: #3564