Skip to content

tasks: test values that a task in a loop moves, copies or borrows - #4588

Open
minzyfox wants to merge 2 commits into
vx-lang:mainfrom
minzyfox:tasks/tests-for-values-moved-in-a-loop
Open

minzyfox wants to merge 2 commits into
vx-lang:mainfrom
minzyfox:tasks/tests-for-values-moved-in-a-loop

Conversation

@minzyfox

@minzyfox minzyfox commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Issue: #4345

This PR adds the tests of #4345 for the compiler fix in #4356. It changes only tests. The
GenMC clients, the formal models and the doc updates of #4345 come in later PRs.

The tests

The values test of #4356 already fails on the old compiler. So each test here must catch a
different way to break the code.

Test What it adds
Unit tests in src/hir/check/tasks.rs The checker lists a moved variable and a copied Copy value as taken at the spawn. It does not list a variable that the task writes, or a reference. Before, only a_cancel_or_a_time_limit_ends_sleep_and_tick.vx found a break of the reference rule, by chance.
a_task_gets_a_moved_sender_by_value_and_a_borrowed_variable_by_address.vx On the real front end, a moved struct with a Sender goes into the task by value, and a borrowed variable goes by address. It does not depend on the order of the tasks.
Values test: field_read_before_the_whole_value The task reads a field of a struct, and then moves the whole struct. The struct holds no channel end, so the compiler adds no read of its own.
Drop test: sender_in_a_struct The program drops each struct that holds a Sender once.
a_deadlock_report_names_the_holder_of_each_channel_end_moved_into_a_task_in_a_loop.vx Each pass moves both ends of its channel into a task. The report must show one wait on each channel.
thread_sanitizer_finds_no_race_with_channel_ends_moved_into_tasks_in_a_loop.vx ThreadSanitizer runs a loop of tasks that move channel ends, on each PR.

The checks in the MLIR test are written by hand. utils/update_mlir_test_checks.rs writes the
whole module (about 1,600 lines) and cannot run a RUN line that pipes into vx-opt.

How I checked that the tests can fail

What I broke What failed
The old lowering: lowerTask ignores the markers, and its check is off The MLIR test, at the load of the whole struct. ThreadSanitizer reported a data race. The deadlock report showed two waits on channel 1. field_read_before_the_whole_value printed pass 0 got 11. dropped 42 printed twice.
The checker does not take moved variables Only a_task_takes_a_variable_that_it_moves.
The checker does not take Copy values Only a_task_takes_a_copy_value_that_it_only_reads.
The checker takes variables that the task writes Only a_task_does_not_take_a_variable_that_it_writes, and the MLIR test at the borrowed variable.
The checker takes references Only a_task_does_not_take_a_reference_that_it_copies.

On macOS arm64, all the RUN lines of the new and changed tests pass, and so do the 11
a_deadlock_report_* tests. I did not run the full cargo test --workspace.

For the reviewer

#4345 says that the checker does not mark a copied Copy capture. #4356 marks it, and
copy_struct_read_by_field needs that. The unit tests check what the code does.

🤖 Generated with Claude Code

minzyfox and others added 2 commits December 3, 2026 23:34
Add the tests of vx-lang#4345 for the compiler fix in vx-lang#4356. In each pass of a
loop, a task must get the value of its own pass, and the program must
drop each channel end once.

- Unit tests in src/hir/check/tasks.rs: the checker lists a moved
  variable and a copied Copy value as taken at the spawn. It does not
  list a variable that the task writes, or a reference.
- An MLIR test: a moved struct with a Sender goes into the task by
  value, and a borrowed variable goes by address.
- The values test gets a case where the task reads a field of a
  struct with a Sender, and then moves the whole struct.
- The drop test gets three Sender cases: in a struct, two fields
  deep, and a field read before the move.
- A deadlock report test: each pass moves both ends of its channel
  into a task. The report must show one wait on each channel.
- A ThreadSanitizer test with Receivers and Senders moved in a loop.

To check the tests, I broke the compiler. With the old lowering (no
copy at the spawn), each new backend test failed, and ThreadSanitizer
reported a data race. Each of four breaks of the checker failed its
own unit test.

Issue: vx-lang#4345

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the values test, the case where a task reads a field and then moves
the whole struct used a struct with a Sender. The compiler already adds
a read of a field to such a task, for the deadlock report. So the case
tested the same thing as struct_with_a_sender. Now the struct holds two
numbers, and the read in the code is the only read before the move. On
the old lowering, this case gets the values of a later pass.

The drop test keeps one Sender case, sender_in_a_struct. The two other
Sender cases failed in the same way as that case on the old lowering.
The lines that said the channel closed passed on the old lowering too:
one Sender was dropped twice and one never, and the two cancel out.

Issue: vx-lang#4345

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant