jasmin
jasmin copied to clipboard
Pointer mutability information after type-checking is not trustworthy
Keeping track of the writability (const
/ mut
) property of variables during the compilation passes is difficult and probably not needed. When compiling this example, we can notice that after inlining and removal of “renaming” assignments, variables arg
and ro
get merged and the single variable that represent both has wrong mutability. Unfortunately, “stack allocation” trusts this mutability information and wrongly rejects the program.
inline
fn read(reg const ptr u64[1] ro) -> reg u64 {
reg u64 v;
v = ro[0];
return v;
}
fn write(reg mut ptr u64[1] arg) -> reg ptr u64[1] {
reg u64 x;
arg[0] = 0;
x = read(arg);
arg[0] = x;
return arg;
}
export
fn test() -> reg u64 {
reg u64 r;
stack u64[1] s;
reg mut ptr u64[1] rw;
rw = s;
rw = write(rw);
r = rw[0];
return r;
}
Starting from "After variable renaming to remove copies", the reg ptr
becomes const
. Isn't it the problem? It doesn't mean that we cannot make the code of stack_alloc simpler.
(sry, didn't want to close)