Update to latest as-pect, fix compiler errors#26
Conversation
|
Currently, I borrowed the index signatures from Everything seems to work exactly as intended. |
…add in some unreachable tests
|
Thanks to |
assembly/buffer/index.ts
Outdated
| // Node throws an error if size is less than 0 | ||
| if (<u32>size > BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH); | ||
| // range must be valid | ||
| if (i32(<usize>size > BLOCK_MAXSIZE) | i32(size < 0)) throw new RangeError(E_INVALIDLENGTH); |
There was a problem hiding this comment.
Was there an issue with the original code?
There was a problem hiding this comment.
BLOCK_MAXSIZE is a usize right?
I wrote this to make the tests pass, but I'm sure this could be optimized.
Do you think this would suffice?
if (<usize>size > BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH);There was a problem hiding this comment.
I don't know if there is a range gap regarding negative numbers and casting to usize. We just need to make sure all the negative numbers throw an error because we accept a i32 instead of a usize.
There was a problem hiding this comment.
I remember that the original idea was that a negative size would wrap around when cast to unsigned, in turn becoming larger than BLOCK_MAXSIZE (which is < 2^30) when cast to unsigned, so we can use a single instruction. I also remember that there used to be issues with that, just not sure if this line is also affected?
There was a problem hiding this comment.
Right. Thank you for reminding me that we had a conversation about this.
When any negative i32 is cast to usize will it always be bigger than BLOCK_MAXSIZE? I suppose that depends on if we are running in 64 bit wasm right? As long as the max blocksize is (1 << 30) - BLOCK_OVERHEAD then the assertion appears to hold true.
Sounds like we should optimize this check away. :)
Even more, I confirmed that this works practically by spinning up an as-pect test randomly that looked like this:
it("should test something", () => {
Expected.report(true);
for (let i = i32.MIN_VALUE; i < 0; i++) {
let condition1 = (i32(<usize>i > BLOCK_MAXSIZE) | i32(i < 0));
let condition2 = i32(<usize>i > BLOCK_MAXSIZE);
let result = condition1 == condition2;
Actual.report(result);
assert(result, "Result should match.");
}
});The assertion seems to hold true, practically. Thanks for the reminder.
|
Looks like the wat files weren't being output, so I used the same pattern I use in |
Alright! Time to get working on this.
This currently breaks because of a compiler error. Inheriting from
Uint8Arraycauses a compiler error, when accessing the bytes via the index signature:Please advise 👍
Also, there seems to be an issue with
Reflect.equals()which may potentially be a bug in my testing software, or is possibly related to the fact that type information is not passed fromBufferindex signature. I'm confident it's the latter.