I was thinking more about zero-sized array elements in relation to zero-length strings and lists. The motivation for #77 is to avoid forcing checking the size of memory, but I think that the current specification is such that zero-length lists and strings must also force a check against the size of memory as specified.
- Lifting a string has the condition
trap_if(ptr + byte_length > len(opts.memory)) which would force a check against the size of memory in the case that byte_length is 0.
- Lifting a list has the condition
trap_if(ptr + length * size(elem_type) > len(opts.memory)) which would also force a check if length is 0.
- Lowering a string actually doesn't have any
trap_if(...) conditions right now, which I think might be an oversight?
- Lowering a list has the condition
trap_if(ptr + byte_length > len(opts.memory)) which is similar to lifting.
The original motivation for #77 came from eliding checks entirely in the case that fused adapters between wasm modules are themselves compiled to WebAssembly. While zero-size elements can have their length checks statically removed I don't think the check can be removed for the more common non-zero-sized elements in the case that the list length is zero.
Solving this issue could perhaps be done by moving the in-bounds-check to each iteration of the loop if the size of the element is bigger than zero. Solving this for strings though would be a bit trickier in the current spec code since the check would have to only trap if the byte length was bigger than 0.
I was thinking more about zero-sized array elements in relation to zero-length strings and lists. The motivation for #77 is to avoid forcing checking the size of memory, but I think that the current specification is such that zero-length lists and strings must also force a check against the size of memory as specified.
trap_if(ptr + byte_length > len(opts.memory))which would force a check against the size of memory in the case thatbyte_lengthis 0.trap_if(ptr + length * size(elem_type) > len(opts.memory))which would also force a check iflengthis 0.trap_if(...)conditions right now, which I think might be an oversight?trap_if(ptr + byte_length > len(opts.memory))which is similar to lifting.The original motivation for #77 came from eliding checks entirely in the case that fused adapters between wasm modules are themselves compiled to WebAssembly. While zero-size elements can have their length checks statically removed I don't think the check can be removed for the more common non-zero-sized elements in the case that the list length is zero.
Solving this issue could perhaps be done by moving the in-bounds-check to each iteration of the loop if the size of the element is bigger than zero. Solving this for strings though would be a bit trickier in the current spec code since the check would have to only trap if the byte length was bigger than 0.