E3070
E3070 — A shape inTensor<T, [..]>::new([..]),::uninit([..])or::fill([..], v)that does not match the type. The shape is a list in brackets with one extent for each dimension, and a fixed dimension gets the extent of the type:Tensor<f32, [?, 4]>::new([n, 4]).
What the compiler reports
Error[E3070] at {{.*}}:[[#@LINE+1]]:40: dimension 1 of `Tensor<i32, [?, 4]>` has the extent 4, so write 4 for it in the shape
Error[E3070] at {{.*}}:[[#@LINE+1]]:38: `Tensor<i32, [?, 4]>` has 2 dimensions, so its shape needs 2 extents, one for each dimension. This shape has 1 extent
Error[E3070] at {{.*}}:[[#@LINE+1]]:48: `Tensor<i32, [?]>` has 1 dimension, so its shape needs 1 extent, one for each dimension. This shape has 2 extents
Error[E3070] at {{.*}}:[[#@LINE+1]]:44: dimension 1 of `Tensor<i32, [?, 4]>` has the extent 4, so write 4 for it in the shape
Error[E3070] at {{.*}}:[[#@LINE+1]]:40: write the shape of `Tensor<i32, [?, ?]>` as a list of extents in brackets, such as `[n, m]`
Error[E3070] at {{.*}}:[[#@LINE+1]]:46: dimension 1 of `Tensor<f32, [?, 2]>` has the extent 2, so write 2 for it in the shape
Error at {{.*}}:[[#@LINE+2]]:3: 'Tensor::fill' expects 2 argument(s): a run-time extent is not in the type, so `::fill` takes the shape and then the value: `::fill([n, m], v)`
Error[E3070] at {{.*}}:[[#@LINE+1]]:44: write the shape of `Tensor<f32, [?, 2]>` as a list of extents in brackets, such as `[n, m]`
Error[E3070] at {{.*}}:15:40: dimension 1 of `Tensor<i32, [?, 5]>` has the extent 5, so write 5 for it in the shape
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
//
// `Tensor<T, [?, 4]>::new([n, 4])`, `::uninit([n, 4])` and `::fill([n, 4], v)` make the tensor
// from the list of extents. So the list has one extent for each dimension, and a fixed dimension
// gets the extent of the type. A shape in a variable is not a list.
//
fn with_a_parameter<const C : i32>(n : i32, k : i32) -> i32 {
let t = Tensor<i32, [?, C]>::new([n, k]);
return t.extent(0);
}
// The checker cannot compute `k`, so it cannot know that `k` is 4.
fn from_a_parameter(n : i32, k : i32) -> i32 {
let t = Tensor<i32, [?, 4]>::new([n, k]);
return t.extent(0);
}
fn main() -> i32 {
let n = 3;
let few = Tensor<i32, [?, 4]>::new([n]);
let many = unsafe { Tensor<i32, [?]>::uninit([n, 4]) };
let other = Tensor<i32, [?, 4]>::new([n, 5]);
let shape = [n, 4];
let named = Tensor<i32, [?, ?]>::new(shape);
let filled = Tensor<f32, [?, 2]>::fill([n, 3], 1.5);
let no_shape = Tensor<f32, [?, 2]>::fill(1.5);
let r = with_a_parameter<5>(n, 5) + from_a_parameter(n, 4);
println!("{} {} {} {} {} {} {}", few.extent(0), many.extent(0), other.extent(0), named.extent(0), filled.extent(0), no_shape.extent(0), r);
return 0;
}
From tests/frontend/fail/a_tensor_shape_that_does_not_match_its_type.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.
E3069A variable of the body with the name of an extent, or an assignment to an extent name.
?n in the type of a parameter makes n a variable of the body that nothing changes.