W1014

W1014 — An as cast of a number known while compiling that does not fit the target type, such as 100000 as i8, which gives -96. For a cast to usize, such as (-1i64) as usize, the program stops at that cast.

What the compiler reports

Warning[W1014] at {{.*}}warnings_for_casts_transfers_and_spawns.vx:24:22: 100000 does not fit in i8
Warning[W1022] at {{.*}}warnings_for_casts_transfers_and_spawns.vx:27:11: the value is already in CPU_DRAM
Warning[W1023] at {{.*}}warnings_for_casts_transfers_and_spawns.vx:28:3: `spawn on(Topology::Current)`

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
//
//
// Three lines that compile but do not do what they look like:
//
// - `100000 as i8` gives -96 (W1014); `100 as i8` fits, so it gets no warning;
// - a transfer into the memory the tensor is already in only copies it (W1022);
// - `spawn on(Topology::Current)` runs where the code around it runs (W1023).

// ONCE-COUNT-1: Warning[W1014]
// ONCE-NOT: Warning[W1014]

fn main() -> i32 {
  let small = 100000 as i8;
  let fine = 100 as i8;
  let t = Tensor<f32, [4]>::new();
  let s = transfer(t, Memory::CPU_DRAM);
  spawn on(Topology::Current) {
    print(small);
  }
  print(fine);
  print(s[0]);
  return 0;
}

From tests/frontend/pass/warnings_for_casts_transfers_and_spawns.vx, which asserts this diagnostic on every commit.

Related