Skip to content

Throw invalid_argument error in case of dynamic indexing of channels array#3896

Open
magancarz wants to merge 3 commits intogoogle:mainfrom
antmicro:warn-dynamic-use-channels-array
Open

Throw invalid_argument error in case of dynamic indexing of channels array#3896
magancarz wants to merge 3 commits intogoogle:mainfrom
antmicro:warn-dynamic-use-channels-array

Conversation

@magancarz
Copy link
Copy Markdown
Contributor

@magancarz magancarz commented Feb 27, 2026

This PR adds throwing an error in case of dynamic indexing of channels array. It is handled by checking constness of value used for indexing an array of channels in semantics_analysis.cc.

  • Fix test_constexpr_rollover_warning test in error_modules_test.py.

@magancarz magancarz force-pushed the warn-dynamic-use-channels-array branch from 75ade97 to 77494a4 Compare February 27, 2026 13:30
@magancarz magancarz marked this pull request as ready for review February 27, 2026 13:30
@magancarz
Copy link
Copy Markdown
Contributor Author

test_constexpr_rollover_warning test was failing, because constant_collector evaluated and noted constexpr value for Binop without rollover warning before evaluator.cc had a chance to do it. I've had to follow the workaround used here. After fixing that test case, I've removed the draft state and the pull request is now ready for review.

@proppy proppy requested review from dplassgit and richmckeever March 3, 2026 06:39
@magancarz magancarz force-pushed the warn-dynamic-use-channels-array branch from 77494a4 to 4d2bd2c Compare March 3, 2026 10:13
@magancarz
Copy link
Copy Markdown
Contributor Author

I've rebased changes on latest main, so Continuous Integration job will now succeed.

Comment thread xls/dslx/type_system/typecheck_module_test.cc
@magancarz magancarz force-pushed the warn-dynamic-use-channels-array branch from 4d2bd2c to 0690ace Compare March 4, 2026 13:46
@magancarz
Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've applied your suggestion.

Comment thread xls/dslx/frontend/semantics_analysis.cc Outdated
@magancarz magancarz force-pushed the warn-dynamic-use-channels-array branch from 0690ace to c490ab7 Compare March 5, 2026 14:34
@magancarz
Copy link
Copy Markdown
Contributor Author

magancarz commented Mar 5, 2026

I've added more descriptive error log. See review comment.

@magancarz
Copy link
Copy Markdown
Contributor Author

Merging #3931 should help with the failing Test ZSTD module job.

@dplassgit
Copy link
Copy Markdown
Contributor

This is failing internal tests; the DSLX index is correctly a const (it's the index in an unroll for) but the new check is claiming it's not a const.

@magancarz
Copy link
Copy Markdown
Contributor Author

magancarz commented Mar 17, 2026

This is failing internal tests; the DSLX index is correctly a const (it's the index in an unroll for) but the new check is claiming it's not a const.

@dplassgit the check is based on confirming that the index value is a known const, so I suspect that constant collector couldn't collect the value before the check (it was a similar case with Binop) or the used type info object is incorrect. Can you help me identify which AST node was used as the index?

@dplassgit
Copy link
Copy Markdown
Contributor

It looks something like this (partially redacted)

 let v =
            unroll_for! (st_slot_idx, store_data_value): (
                u32, common::dv[NS][NV]
            ) in u32:0..NV {
                let (_, sdv) = recv_if(
                    tok, channel_array[st_slot_idx],  // <<< failing on st_slot_idx
                    ready,
                    zero!<...>());
            }(zero!<...>());

@wsipak
Copy link
Copy Markdown
Contributor

wsipak commented Mar 18, 2026

Hey @dplassgit ,
the code sample you've provided doesn't seem sufficient to reproduce the error you're seeing in the test.
I've created a proc with a similar unroll_for and channel array access, but I haven't found a way to trigger the error here.
Is there a chance you can provide more information or a minimal reproducible example with the error?

@magancarz
Copy link
Copy Markdown
Contributor Author

@dplassgit you can find our attempt to reproduce your failing test case in this commit in our fork.

@magancarz magancarz force-pushed the warn-dynamic-use-channels-array branch from c490ab7 to 883bc8c Compare March 26, 2026 09:30
@magancarz
Copy link
Copy Markdown
Contributor Author

I've rebased changes onto the latest main, so Test ZSTD module should pass now and changed instance of for to const for in zstd_dec_test.x which also triggered the dynamic indexing error.

@mikex-oss
Copy link
Copy Markdown
Collaborator

Re-approving to run internal checks.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants