Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Float16Array to all generic TypedArray tests #3849

Merged
merged 5 commits into from
Jan 10, 2024
Merged

add Float16Array to all generic TypedArray tests #3849

merged 5 commits into from
Jan 10, 2024

Conversation

bakkot
Copy link
Contributor

@bakkot bakkot commented Jun 11, 2023

First step of #3828.

I've updated harness/testTypedArray.js so that it includes Float16Array iff it is available as a global, so as to not render all tests using it useless for any implementation which has not yet implemented Float16Array. I've also updated a bunch of tests which weren't using that helper to use it, so that they wouldn't require separate updates for Float16Array.

In principle these should behave identically on existing implementations as prior to this PR.

I'll have a follow-up adding Float16Array-specific tests.

@bakkot bakkot requested a review from a team as a code owner June 11, 2023 22:09
@ljharb
Copy link
Member

ljharb commented Jun 12, 2023

The harness doesn't include the bigint arrays, how are those tested?

@bakkot
Copy link
Contributor Author

bakkot commented Jun 12, 2023

A separate harness: testBigIntTypedArray.js

But they kind of have to be, since otherwise all consumers need to work with both Number and BigInt, which is pretty annoying; might as well just split them up. That's not true for Float16Array, since it's just another Number-containing TA kind.

@ljharb
Copy link
Member

ljharb commented Jun 12, 2023

If the current split is by number type, then this approach seems fine.

@jugglinmike
Copy link
Contributor

I like how this approach minimizes maintenance effort, but I've been wondering if the effect on consumers is acceptable.

As far as I know (which admittedly isn't very far these days), Test262 doesn't make assertions conditionally anywhere else. I think there's value in a test suite that makes the same statement about conformance for everyone (e.g. when comparing results across implementations), so I don't want to give that up unintentionally.

The only alternative comes to mind is to duplicate the tests. I'm not thrilled about that idea, either, but we might mitigate the worst of the maintenance hassle with a new rule for Test262's linter.

@bakkot
Copy link
Contributor Author

bakkot commented Jun 16, 2023

I think in practice it still amounts to the same assertion - "Atomics.wait throws for every numeric typed array kind other than Int32Array", for example. it doesn't make sense for an implementation to fail the assertion because of an engine not supporting a new Typed Array kind.

If we were to duplicate the tests, I think the way to do it would be to migrate all of them to templates, and generate one test per typed array kind. (The current template system isn't ideally suited to this kind of thing, but it would suffice.) That way it would have sufficient granularity for an engine to fail only the Float16Array variants, without needing the logic itself to be duplicated in source. Buuuuuut that migration would be a lot of work; I wouldn't want to block adding these tests on it.

(FWIW, @syg said the approach in this PR would work for V8.)

@ljharb
Copy link
Member

ljharb commented Sep 13, 2023

fwiw I think it's very reasonable to land this now, with a future roadmap item to change these tests to be generated per-typed-array.

@bakkot
Copy link
Contributor Author

bakkot commented Sep 13, 2023

Yes, I'd really like to see this landed as-is, unless we hear from a consumer that it's a big problem for them. As a consumer (in several projects) this works fine for me. Sounded like it was fine for V8 too.

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

It's somewhat unfortunate that the "one file = one result" approach pushes us in this direction, but within that context, this seems fine.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

seems like there's a lot of places the conditional global check isn't needed, if it's conditionally added to typedArrayConstructors?

@bakkot
Copy link
Contributor Author

bakkot commented Nov 19, 2023

@Ms2ger Done. I also updated one test which was defining but not using precision; seemed like it probably meant to use it.

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

Modulo comments below, this looks good to me.

@Ms2ger Ms2ger enabled auto-merge (squash) December 1, 2023 10:38
@Ms2ger Ms2ger disabled auto-merge December 1, 2023 10:42
@Ms2ger
Copy link
Contributor

Ms2ger commented Dec 1, 2023

/home/circleci/test262/test/built-ins/Atomics/add/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/add/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/and/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/and/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/compareExchange/validate-arraytype-before-expectedValue-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/compareExchange/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/compareExchange/validate-arraytype-before-replacementValue-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/exchange/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/exchange/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/load/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/notify/validate-arraytype-before-count-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/notify/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/or/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/or/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/store/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/store/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/sub/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/sub/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/wait/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/wait/validate-arraytype-before-timeout-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/wait/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/xor/validate-arraytype-before-index-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/built-ins/Atomics/xor/validate-arraytype-before-value-coercion.js: HARNESS_FEATURES - Missing from `features`: TypedArray
/home/circleci/test262/test/language/statements/class/subclass/builtin-objects/TypedArray/regular-subclassing.js: HARNESS_FEATURES - Missing: `features: [TypedArray]`
/home/circleci/test262/test/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js: HARNESS_FEATURES - Missing: `features: [TypedArray]`

@bakkot
Copy link
Contributor Author

bakkot commented Dec 28, 2023

@Ms2ger I'm not sure what you want me to do with that error message. test/built-ins/Atomics/add/validate-arraytype-before-index-coercion.js does not currently have the TypedArray feature flag, and this PR doesn't affect it either way. Ditto the other tests. It's just a straight refactoring.

Are you saying that I should fix the tests which currently lack that flag as part of this PR?

@Ms2ger
Copy link
Contributor

Ms2ger commented Jan 8, 2024

It seems like the linter only runs on changed files, so your changes caused it to catch preexisting bugs 🤦

In order of preference, you could:

  1. Fix the linter and any fallout 😇
  2. Add the flags in a separate PR to be landed first (I promise speedy review)
  3. Add the flags here

@bakkot
Copy link
Contributor Author

bakkot commented Jan 9, 2024

Done, but I'm not really looking forward to fixing the resulting merge conflicts... They're all trivial, it's just that it's a lot of them and I don't know of an easy way to make git address them itself.

I'll get to it eventually though if no one else does.

@Ms2ger
Copy link
Contributor

Ms2ger commented Jan 9, 2024

I rebased, thanks!

@bakkot
Copy link
Contributor Author

bakkot commented Jan 10, 2024

I think this is ready then?

@Ms2ger Ms2ger enabled auto-merge (squash) January 10, 2024 13:05
@Ms2ger Ms2ger merged commit 67a5153 into main Jan 10, 2024
9 checks passed
@Ms2ger Ms2ger deleted the float16array branch January 10, 2024 13:07
@@ -29,8 +30,17 @@ var typedArrayConstructors = [
Uint8ClampedArray
];

var floatArrayConstructors = typedArrayConstructors.slice(0, 2);
var intArrayConstructors = typedArrayConstructors.slice(2, 7);
Copy link
Contributor

Choose a reason for hiding this comment

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

intArrayConstructors did not contain Uint8ClampedArray but it is included now. This seems to be an intended change. Unfortunately, some Atomics tests (like built-ins/Atomics/add/good-views.js) still use intArrayConstructors. In other words, these tests are incorrect now. They should be rewritten to use testWithAtomicsFriendlyTypedArrayConstructors(), I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the catch. Would you mind opening an issue for that, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that was not an intended change, I just didn't realize that the .slice above stopped before the end of the list.

In fact the .slice was previously also omitting Uint8Array, which seems wrong. I've left it in, but opened #3984 to remove Uint8ClampedArray.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the original idea was to include Uint8ClampedArray in intArrayConstructors. The author just haven't realized that the second argument in typedArrayConstructors.slice(2, 7); is not the length but an (excluded) end index. That's why Uint8Array and Uint8ClampedArray were missing by accident. I find it correct to include Uint8ClampedArray in this array (it is a typed array with int elements). Some tests may skip Uint8ClampedArray unnecessarily when it is not included. That's why I though that the change was intentional and that just the problematic Atomics tests (that use intArrayConstructors without excluding Uint8ClampedArray) should be fixed/updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iamstolis Do you happen to have a list of such tests? It's a bit painful to track them down manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

The following tests started to fail (when run against graal-js engine). So, this is the correct list, hopefully.

Unexpectedly failed 'built-ins/Atomics/add/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/add/good-views.js'
Unexpectedly failed 'built-ins/Atomics/and/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/and/good-views.js'
Unexpectedly failed 'built-ins/Atomics/compareExchange/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/compareExchange/good-views.js'
Unexpectedly failed 'built-ins/Atomics/exchange/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/exchange/good-views.js'
Unexpectedly failed 'built-ins/Atomics/load/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/load/good-views.js'
Unexpectedly failed 'built-ins/Atomics/or/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/or/good-views.js'
Unexpectedly failed 'built-ins/Atomics/store/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/store/good-views.js'
Unexpectedly failed 'built-ins/Atomics/sub/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/sub/good-views.js'
Unexpectedly failed 'built-ins/Atomics/xor/bad-range.js'
Unexpectedly failed 'built-ins/Atomics/xor/good-views.js'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iamstolis Thanks, see #3984.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, I run the tests from the current revision (62294b592e332bc16da6114e461fd7a8ed90daab) of #3984 against graal-js and I haven't seen any unexpected failures.

* Array containing every non-bigint typed array constructor.
*/

var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR included Float16Array in typedArrayConstructors. Unfortunately, it failed to provide byteConversionValues.expected.Float16 (in harness/byteConversionValues.js). So, the tests that use testTypedArrayConversions(byteConversionValues, ...) fail when Float16Array is enabled. This seems to affect the following tests:

built-ins/TypedArray/prototype/fill/fill-values-conversion-operations.js
built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js
built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js
built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js
built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js
built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js
built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js
built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js

Copy link
Contributor

Choose a reason for hiding this comment

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

@iamstolis Please open an issue - if no-one happens to have time to fix this right when they see it, it'll likely get lost out of their notifications.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I have created #3989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants