Skip to content

Update to latest as-pect, fix compiler errors#26

Merged
jtenner merged 7 commits intomasterfrom
latest-aspect
Mar 12, 2020
Merged

Update to latest as-pect, fix compiler errors#26
jtenner merged 7 commits intomasterfrom
latest-aspect

Conversation

@jtenner
Copy link
Copy Markdown
Contributor

@jtenner jtenner commented Mar 2, 2020

Alright! Time to get working on this.

This currently breaks because of a compiler error. Inheriting from Uint8Array causes a compiler error, when accessing the bytes via the index signature:

ERROR TS2329: Index signature is missing in type '~lib/buffer/index/Buffer'.

   for (let i = 0; i < values.length; i++) result[i] = values[i];

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 from Buffer index signature. I'm confident it's the latter.

@jtenner jtenner added bug Something isn't working enhancement New feature or request help wanted Extra attention is needed labels Mar 2, 2020
@jtenner jtenner self-assigned this Mar 2, 2020
@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Mar 2, 2020

Currently, I borrowed the index signatures from Uint8Array to force the tests to pass and check out stdout.

Everything seems to work exactly as intended.

@jtenner jtenner requested review from MaxGraey and dcodeIO March 11, 2020 21:36
@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Mar 11, 2020

Thanks to 0.9.3/4 I can remove the index signatures. This whole pull request is basically to bring everything to work with the new ArrayBufferView and latest as-pect

// 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an issue with the original code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

@jtenner jtenner Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jtenner
Copy link
Copy Markdown
Contributor Author

jtenner commented Mar 12, 2020

Looks like the wat files weren't being output, so I used the same pattern I use in as-pect to write the files out without blocking tests.

@jtenner jtenner requested a review from dcodeIO March 12, 2020 15:00
@jtenner jtenner merged commit d3ac890 into master Mar 12, 2020
@dcodeIO dcodeIO deleted the latest-aspect branch June 1, 2021 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants