legacy codegen: a call whose tensor result nothing takes leaks the buffer

Open
#3,541 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Read the AST code generator and compare its handling of unused call results with drop_temps_here in src/hir/flatten.rs; the issue also points to the checker’s Drop handling. Start by reproducing with the discard.vx example using vxc discard.vx --legacy-codegen --action emit-mlir. Done when both dynamic and fixed-shape tensor results that are unused are freed in the emitted MLIR.

Written by the indexing model from the issue text.

Description

bug codegen

With --legacy-codegen, a call whose tensor result nothing takes does not free the result's buffer.

fn make(n : i32) -> Tensor<f32, [?]> {
  let t = Tensor<f32>([n]);
  return t;
}

fn main() -> i32 {
  make(4);
  return 0;
}

vxc discard.vx --legacy-codegen --action emit-mlir shows the call in main and no vx.drop or memref.dealloc of its result:

%0 = call @make(%c4_i32) : (i32) -> memref<?xf32>

The default code generator drops the result after the statement: the flat path drops each fresh tensor of a statement that nothing took (drop_temps_here in src/hir/flatten.rs). The AST code generator has no such step, and the checker writes a Drop only for a named owner.

The same holds for a result of fixed shape over 4096 bytes. After #3496, its caller makes the result's buffer on the heap, and the AST code generator does not free it when nothing takes the result. Before that change, the buffer was on the stack.

Found while working on #3496.

Dominant language
Rust
Stars
35
Forks
5
Avg merge
12h 26m
Merged PRs (30d)
799

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

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.

More from vx-lang/Vx

All issues in vx-lang/Vx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.