E3055
E3055 — A task takes a value that is notSend, or reads a variable whose type is notSync. A task that moves a value, copies it or writes it needsSend. A task that reads a variable in place shares it with the code around the task, so it needsSync. The error names the field that makes the type fail.
What the compiler reports
Error[E3055] at {{.*}}tasks_cannot_share_a_slice_of_cells.vx:[[@LINE+1]]:5: the task reads 's'
The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.
A program that triggers it
//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
// A `Slice<T>` is `Sync` only when `T` is. A `SharedCell` can change through a shared reference,
// so two tasks cannot read a slice of cells at the same time.
import core::cell;
import core::slice;
import std::vec;
fn main() -> i32 {
let mut v = Vec<SharedCell<i64>>::new();
v.push(SharedCell<i64>::new(1));
let s = v.slice(0, 1);
tasks {
spawn {
let _n = s.len();
};
let _m = s.len();
};
return 0;
}
From tests/frontend/fail/tasks_cannot_share_a_slice_of_cells.vx, which asserts this diagnostic on every commit.
Related
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3054
unsafe impl of a trait other than Send, Sync or Owned, or of no trait at all. Only those three traits make a claim that the compiler cannot check. Remove unsafe.
E3056spawn { .. } outside a tasks { .. } block. The end of the tasks block waits for each task, so a task cannot outlive the variables it uses. A spawn in a closure, or directly in another task, is outside the block too. Put the spawn in a tasks block of its own.