E3068
E3068 — A call that gives one extent name two different extents. Infn add(a : Tensor<f32, [?n]>, b : Tensor<f32, [?n]>), both?nare one extent, soadd(x, y)with the extents 5 and 7 is an error. When the compiler does not know an extent, it does not check it.
What the compiler reports
Error[E3068] at {{.*}}:[[#@LINE+1]]:11: this call to 'dot' gives `?n` the extents 6 and 8, but each `?n` of 'dot' is the same extent
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
//
// `?n` in the tensor type of a parameter names that run-time extent. A call must show the
// `requires` about `n`, and it cannot give one name two different extents. The callee's `n` is
// the extent of the argument, never a name of the caller. The body cannot have a variable with
// the name `n` or change `n`, and it cannot read `n` after a move of the tensor. The compiler
// gives its warnings before its errors, so the functions that warn come first.
//
import tests::modules::a_function_that_names_an_extent;
const k : usize = 3;
fn hides(t : &Tensor<f32, [?k]>) -> usize {
return k;
}
// The instance that `main` makes gives no second W1039.
fn hides_in_a_generic<T>(t : &Tensor<T, [?k]>) -> usize {
return k;
}
fn hides_a_parameter<const m : usize>(t : &Tensor<f32, [?m]>) -> usize {
return m;
}
fn quarter(t : &Tensor<f32, [?n]>) -> usize
requires n % 4 == 0
{
return n / 4;
}
fn length(t : &Tensor<f32, [?n]>) -> usize
ensures return == n
{
return n;
}
// After the `let`, `t` is `u`, whose extent the caller does not know.
fn shadows(t : &Tensor<f32, [?j]>, u : &Tensor<f32, [?]>) -> usize
requires j % 4 == 0
{
let t = u;
return quarter(t);
}
// The `n` of `quarter` is the extent of `u`, not the `n` of this function.
fn another_n(t : &Tensor<f32, [?n]>, u : &Tensor<f32, [?]>) -> usize
requires n % 4 == 0
{
return quarter(u);
}
// `length(u)` is the extent of `u`, not the `n` of this function.
fn through_a_let(t : &Tensor<f32, [?n]>, u : &Tensor<f32, [?]>) -> usize
requires n == 8
ensures return == 8
{
let r = length(u);
return r;
}
fn through_a_return(t : &Tensor<f32, [?n]>, u : &Tensor<f32, [?]>) -> usize
requires n == 8
ensures return == 8
{
return length(u);
}
fn dot(a : &Tensor<f32, [?n]>, b : &Tensor<f32, [?n]>) -> f32 {
return a[0] * b[0];
}
// `m % 2 == 0` does not show `n % 4 == 0`.
fn only_even(t : &Tensor<f32, [?m]>) -> usize
requires m % 2 == 0
{
return quarter(t);
}
fn binds(t : &Tensor<f32, [?n]>) -> usize {
let n = 3;
return n;
}
fn in_a_closure(t : &Tensor<f32, [?n]>) -> usize {
let f = |n : usize| n + 1;
return f(1);
}
fn assigns(t : &Tensor<f32, [?n]>) -> usize {
n = 3;
return n;
}
fn take(t : Tensor<f32, [?]>) -> usize {
return t.len() as usize;
}
fn moved(t : Tensor<f32, [?n]>) -> usize {
take(t);
return n;
}
fn main() -> i32 {
let six = Tensor<f32, [6]>::fill(1.0);
let eight = Tensor<f32, [8]>::fill(1.0);
let unknown = Tensor<f32, [?]>::new([8]);
let a = quarter(&six);
let b = quarter(&unknown);
let c = quarter_of(&six);
let d = dot(&six, &eight);
let e = quarter(&eight) + quarter_of(&eight);
let g = dot(&eight, &eight) + (hides_in_a_generic(&eight) as f32);
println!("{} {} {} {} {} {}", a, b, c, d, e, g);
return 0;
}
From tests/frontend/fail/calls_and_bodies_that_break_the_rules_of_extent_names.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.
E3067A read or a write through a
void pointer, as *p or p[i]. A *const void is only an address, for example one that p as *const void made to give to a C function. It has no element type, so the compiler does not know what to read.
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.