E3021

E3021 — An enum variant whose payload is a tensor. A payload is stored into the variant's tagged-union slot with llvm.insertvalue, which takes primitive operands, and a tensor is a memref descriptor. The AST path dropped such a payload silently: the construction emitted the tag and nothing else, so a program carrying a tensor through an enum compiled, ran, and lost it with no diagnostic. A struct field holding a tensor is the same representational gap in another position.

What the compiler reports

E3021 … payload argument 1 of Payload::Weights … cannot carry a tensor

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
//
// An enum payload is stored into the variant's slot with `llvm.insertvalue`,
// which takes primitive operands, and a tensor is a memref descriptor.
//
// This was accepted and miscompiled rather than refused: the construction
// emitted the tag and dropped the tensor, so the program compiled, ran, and
// lost the payload with nothing said. A scalar payload is unaffected and stays
// legal -- `Val(i32)` below constructs and matches.
//

enum Payload {
  Weights(Tensor<f32, [2, 2]>),
  Val(i32),
}

fn main() -> i32 {
  let ok = Payload::Val(7);
  let a = Tensor<f32>([2, 2]);
  let bad = Payload::Weights(a);
  return 0;
}

From tests/frontend/fail/enum_variant_cannot_carry_a_tensor.vx, which asserts this diagnostic on every commit.

Related