jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Late error due to kind mismatch

Open vbgl opened this issue 10 months ago • 2 comments

When giving a ptr array to a function expecting a stack argument, the error message arises too late (variable allocation) and is little informative (no mention of what variable is problematic, location spans the whole function with the wrong call, but after inlining). Here is an example:

inline
fn leaf(stack u32[1] y) -> reg u32 {
  reg u32 z = y[0];
  return z;
}

inline
fn load(reg ptr u32[1] a) -> reg u32 {
  reg u32 b = leaf(a);
  return b;
}

export fn main(reg ptr u8[4] x) -> reg u32 {
  reg u32 r = load(x);
  return r;
}

And the error message:

"bug_1095.jazz", line 11 (1) to line 16 (1):
compilation error in function main:
variable allocation: cannot put a reg ptr argument into the local stack

vbgl avatar Mar 14 '25 16:03 vbgl

In your example, if we replace the stack storage type of function leaf argument by a reg, we get :

"test.jazz", line 9 (2-22)
from line 14 (2-22):
compilation error in function main:
array expansion: cannot expand variable y (the array cannot be manipulated alone, you need to access its cells instead)

Do you find this error more informative than the one with stack or an error should be raised earlier as well ? In this case, what we would need to implement is a "extended" type check that also verify if storage types match on function arguments

MrDaiki avatar Apr 22 '25 08:04 MrDaiki

This error message is similarly very bad. But I would argue that your change makes the program wrong whereas the initial program could be OK.

vbgl avatar Apr 22 '25 08:04 vbgl