Skip to content

tests: check that each value a task takes in a loop is dropped exactly once #4543

Done

Description

@hiraditya

#4356 makes each spawn copy the values that its task moves or copies into the task's own memory. Its test checks the value that each task sees, but not the drops. If the copy at the spawn made a value drop twice, or never, no test would fail.

This program moves a Drop value, and one field of a struct, into tasks in a loop. Each value must print its dropped line exactly once:

import core::ops;

const PASSES : i64 = 3;

struct Loud {
  id : i64,
}

impl Drop for Loud {
  fn drop(self : &mut Loud) -> void {
    println!("dropped {}", self.id);
  }
}

struct Two {
  a : Loud,
  b : Loud,
}

fn take(l : Loud) -> void {
  println!("task has {}", l.id);
}

fn take_a(a : Loud, b_id : i64) -> void {
  println!("task has {} and reads {}", a.id, b_id);
}

fn moved_whole() -> void {
  tasks {
    for i in 0i64..PASSES {
      let l = Loud {
        id : i
      };
      spawn {
        take(l);
      };
    }
  };
}

fn one_field_moved() -> void {
  tasks {
    for i in 0i64..PASSES {
      let t = Two {
        a : Loud {
          id : 10i64 + i
        }, b : Loud {
          id : 20i64 + i
        }
      };
      spawn {
        take_a(t.a, t.b.id);
      };
    }
  };
}

fn main() -> i32 {
  moved_whole();
  println!("--");
  one_field_moved();
  return 0;
}

On main today, each of the 9 dropped lines prints once, with both code generators, and with VX_TASK_RUNTIME unset, threads and shared. Each task also sees the value of its own pass. So the test guards against a regression, and it should pass with #4356 too.

The tasks can end in any order, so the drops can print in any order. The RUN line can sort the output before FileCheck. Then one CHECK-NEXT line for each id checks that it prints exactly once.

Found in the review of #4356.

Generated With Claude Code

Activity

  1. added a commit that references this issue on Dec 4, 2026
    f251234
  2. added a commit that references this issue on Dec 4, 2026
    08d21b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions