vx-lang / vx-lang/Vx

A dynamic tensor's rank is assumed to be 2 at a type annotation, so a rank-1 one produces invalid MLIR

Open
#404 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug codegen core-lang
Dominant language
Rust
Stars
14
Forks
2
Avg merge
12h 42m
Merged PRs (30d)
61

Description

A tensor type with no dimensions lowers to memref<?x?xT> — rank 2, assumed. A dynamic value keeps its real rank, so the two disagree at a call boundary.

fn takes(t : DynTensor<f32>) -> i32 { return 0; }
fn k(n : i32) -> i32 {
  let a = Tensor<f32>([n]);   // rank-1, extent runtime
  a[0] = 1.0;
  return takes(a);
}
'memref.cast' op operand type 'memref<?xf32>' and result type 'memref<?x?xf32>' are cast incompatible
MLIR verification failed

The value lowers correctly (memref.alloc(%0) : memref<?xf32>); the parameter's type is what invents rank 2, because the type carries no rank to read.

Pre-existing and inherited, not caused by the DynTensor split (#399): the identical program with the old dims-less Tensor<f32> parameter fails the same way, since that spelling lowered to ?x? too.

The design question

Rank and extents are different kinds of unknown. MLIR already separates them — memref<?x?xf32> is known rank, unknown extents, and memref<*xf32> is unranked. Nearly all real code knows its rank statically and only learns extents at run time, which is the case DynTensor exists for.

So DynTensor<T> probably wants to carry a rank: the shape is dynamic, the rank is not. Spelling options include an explicit DynTensor<f32, 2>, or inferring it where the value is constructed. Lowering to an unranked memref<*xT> instead would be honest but pushes a rank recovery onto every index.

Until that is settled, a rank-1 dynamic tensor cannot cross a function boundary.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name files, tests, or entry points. Start by tracing lowering for the dynamic tensor parameter and the rank-1 value at the function call boundary, then compare their MLIR types. Done means the rank-1 dynamic tensor can cross the boundary without an MLIR verification failure, after the rank representation design is settled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.