jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Errors with array copies

Open eponier opened this issue 3 years ago • 1 comments

If we copy a stack array into a reg array, we can easily get errors. It is enough to have the size of the target array (in bytes) not a multiple of the cell size of the source array.

If the target array is so small that is cannot store even one element of the source array, we have an internal compilation error.

fn f () -> reg u64 {
  reg u64 res;
  stack u16[1] a;
  reg u256[10] b;

  a = b;
  res = (64u)a[0];
  return res;
}
// internal compilation error in function f:
//  array copy: bad type for copy

If the target array can store at least one element of the source array, we have a type error.

fn f () -> reg u64 {
  reg u64 res;
  stack u16[33] a;
  reg u256[10] b;

  a = b;
  res = (64u)a[0];
  return res;
}
// typing error: the left value a has type u16[33] while u8[64] is expected

The error message is not perfect, because it suggests a good size, but there are other solutions (e.g. u16[16], and even u16[48] if we consider also larger arrays).

eponier avatar Jan 27 '22 11:01 eponier

Is this still valid? I'll give a try tomorrow.

eponier avatar Apr 07 '22 16:04 eponier

The internal compilation error has been fixed in 2022.04.0.

vbgl avatar Sep 02 '22 20:09 vbgl

Indeed, the internal compilation error is not there any more. But I must admit I don't get what the rules now are (in what cases the copy can be inserted, in what cases it's not possible and we should get a type error). I tried some variations for the types of a and b and don't really understand the error messages I receive, but I won't investigate more.

eponier avatar Sep 15 '22 14:09 eponier