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

Support JS typed arrays as arguments and in WebIDL unions #20267

Merged
merged 4 commits into from Mar 14, 2018

Conversation

@Xanewok
Copy link
Contributor

Xanewok commented Mar 10, 2018

Supersedes #20205.
This brings support to receiving typed arrays as function arguments (those are stack-rooted with CustomAutoRooter) and also being a member of a union (which is basically heap-rooted? similarly to other webidl unions).

This is based on my other PR #20265 (which means it has to pull an external rust-mozjs branch and contains some also slightly unrelated changes here) since it shares RootedTraceableBox::from_box here and some other additional changes at rust-mozjs, but it can be easily separated if needed.

I tried adding support to nullable typed arrays but couldn't work around an issue of codegen always sticking a "OrNull" at the end of my type (presumably because of this?). How would I go about avoiding the suffix with nullable arguments?

If we were to add also support for nullable typed arrays then I think we wouldn't be blocked anymore on this in WebGL 1.0.

r? @jdm


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Mar 10, 2018

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/testbinding.rs, components/script/dom/webglrenderingcontext.rs, components/script/dom/bindings/trace.rs, components/script/dom/webidls/TestBinding.webidl
  • @fitzgen: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/testbinding.rs, components/script/dom/webglrenderingcontext.rs, components/script/dom/bindings/trace.rs, components/script/dom/webidls/TestBinding.webidl
  • @KiChjang: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/testbinding.rs, components/script/dom/webglrenderingcontext.rs, components/script/dom/bindings/trace.rs, components/script/dom/webidls/TestBinding.webidl
@highfive
Copy link

highfive commented Mar 10, 2018

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@bors-servo
Copy link
Contributor

bors-servo commented Mar 12, 2018

The latest upstream changes (presumably #20216) made this pull request unmergeable. Please resolve the merge conflicts.

@Xanewok Xanewok force-pushed the Xanewok:typed-arrays-stack-heap-variants branch from ea99f23 to 65c6011 Mar 12, 2018
@jdm
Copy link
Member

jdm commented Mar 12, 2018

Gecko's solution for the nullable name is here. We should be able to do the same thing at https://github.com/servo/servo/pull/20267/files#diff-60d01595cff328c165842fea9e4ccbc2R885.

@@ -870,8 +870,50 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,

return handleOptional(templateBody, declType, handleDefaultNull("None"))

if type.isSpiderMonkeyInterface():
raise TypeError("Can't handle SpiderMonkey interface arguments yet")
if type.isTypedArray() or type.isArrayBuffer() or type.isArrayBufferView() or type.isSharedArrayBuffer():

This comment has been minimized.

@jdm

jdm Mar 12, 2018

Member

This particular check is repeated in enough places that we should put it behind a descriptive is_typed_array function.

# Any code to convert to Object is unused, since we're already converting
# from an Object value.
if t.name == 'Object':
return CGGeneric('')

This comment has been minimized.

@jdm

jdm Mar 12, 2018

Member

What is the reason for this change?

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

Same as above: the type of object members in Unions are currently RootedTraceableBox<Heap<*mut JSObject>> and so we need to convert the incoming raw *mut JSObject somehow; with this we generate a used TryConvertToObject with proper body (constructing a RootedTraceableBox from a boxed Heap value with the raw object pointer)

if hasObjectTypes:
# "object" is not distinguishable from other types
assert not object or not (interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject)
templateBody = CGList([], "\n")
if object:
templateBody.append(object)

This comment has been minimized.

@jdm

jdm Mar 12, 2018

Member

What is the reason for this change?

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

Related to #20265, but I'll leave a note here: without this the contents of if value.get().is_object() { ... } are not generated in from_jsval conversion function

@@ -428,6 +429,9 @@ impl TestBindingMethods for TestBinding {
fn PassByteString(&self, _: ByteString) {}
fn PassEnum(&self, _: TestEnum) {}
fn PassInterface(&self, _: &Blob) {}
fn PassTypedArray(&self, _: CustomAutoRooterGuard<typedarray::Int8Array>) {}
fn PassTypedArray2(&self, _: CustomAutoRooterGuard<typedarray::ArrayBuffer>) {}
fn PassTypedArray3(&self, _: CustomAutoRooterGuard<typedarray::ArrayBufferView>) {}

This comment has been minimized.

@jdm

jdm Mar 12, 2018

Member

It might be nice to typedef these into Int8Array, etc.

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

How should we deal with nullable CustomAutoRooterGuard<Option<Typedarray::Int8Array>> types then? Should we simply pass only reference to rooted arguments, hiding the CustomAutoRooterGuard 'implementation detail'?

This comment has been minimized.

@jdm

jdm Mar 13, 2018

Member

Hmm. Ideally we would have Option<CustomAutoRooterGuard<Typedarray::Int8Array>> instead. Possibly that just requires rearranging the code that applies the CustomAutoRooterGuard templated type?

This comment has been minimized.

@jdm

jdm Mar 13, 2018

Member

Although really passing &typedarray::Int8Array sounds really nice too.


if isMember in ("Dictionary", "Union"):
# TODO: Do we need to do the same for dictionaries?

This comment has been minimized.

@jdm

jdm Mar 12, 2018

Member

Yes.

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

(This is related to #20265, I should've separated the changes in both PRs clearly, I'm sorry)

So I just checked and currently dictionaries are flagged as #[must_root] and their constructor first allocates a dict using RootedTraceableBox with defaults and only then sets values.
With this approach having Heap<*mut JSObject> as dictionary members suffices and moving the dict box is safe, as long as it's not consumed to retrieve the inner value.

Should I still pursue this, then?

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

See 3d532e1 for an attempt.

This comment has been minimized.

@jdm

jdm Mar 13, 2018

Member

Let's leave the current implementation then, since it is less unsafe than previously believed.

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

It seems it didn't require additional work and even simplified the codegen slightly, but I can then not include the change for object in dictionaries here

@bors-servo
Copy link
Contributor

bors-servo commented Mar 13, 2018

The latest upstream changes (presumably #20288) made this pull request unmergeable. Please resolve the merge conflicts.

@Xanewok Xanewok force-pushed the Xanewok:typed-arrays-stack-heap-variants branch from 6254c68 to 477c7ff Mar 13, 2018
Copy link
Member

jdm left a comment

If we can extract the changes from #20265, I think this will be good to merge!

@@ -6418,6 +6468,9 @@ def type_needs_tracing(t):
if t.isUnion():
return any(type_needs_tracing(member) for member in t.flatMemberTypes)

if t.isTypedArray() or t.isArrayBuffer() or t.isArrayBufferView() or t.isSharedArrayBuffer():

This comment has been minimized.

@jdm

jdm Mar 13, 2018

Member

This can still use the helper method.

This comment has been minimized.

@Xanewok

Xanewok Mar 13, 2018

Author Contributor

Ah, missed it, thanks!

@jdm
Copy link
Member

jdm commented Mar 13, 2018

Waiting on merging the changes upstream in rust-mozjs, of course.

bors-servo added a commit to servo/rust-mozjs that referenced this pull request Mar 13, 2018
Add TypedArray API using Heap-wrapped objects

Needed for servo/servo#20267.

This changes TypedArray wrapper type to only contain typed array-related logic and not handle rooting, and introduces 2 different possible storage options for wrapped objects
- `*mut JSObject`, can be rooted on stack (e.g. using CustomAutoRooter)
-  `Box<Heap<*mut JSObject>>`, can be rooted on heap with `JSTraceable` trait (implemented on Servo side)

Since the API changes are breaking, I bumped minor version so that Servo will not break when updating.

r? @jdm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/397)
<!-- Reviewable:end -->
@Xanewok Xanewok mentioned this pull request Mar 13, 2018
2 of 5 tasks complete
@Xanewok Xanewok force-pushed the Xanewok:typed-arrays-stack-heap-variants branch from 477c7ff to 857e484 Mar 13, 2018
@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

💡 This pull request was already approved, no need to approve it again.

  • There's another pull request that is currently being tested, blocking this pull request: #20224
@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

📌 Commit c29fcb8 has been approved by Xanewok

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

Testing commit c29fcb8 with merge f7ee1be...

bors-servo added a commit that referenced this pull request Mar 14, 2018
…newok

Support JS typed arrays as arguments and in WebIDL unions

<!-- Please describe your changes on the following line: -->
Supersedes #20205.
This brings support to receiving typed arrays as function arguments (those are stack-rooted with CustomAutoRooter) and also being a member of a union (which is basically heap-rooted? similarly to other webidl unions).

This is based on my other PR #20265 (which means it has to pull an external rust-mozjs branch and contains some also slightly unrelated changes here) since it shares `RootedTraceableBox::from_box` here and some other additional changes at rust-mozjs, but it can be easily separated if needed.

I tried adding support to nullable typed arrays but couldn't work around an issue of codegen always sticking a "OrNull" at the end of my type (presumably because of [this](https://github.com/servo/servo/blob/master/components/script/dom/bindings/codegen/parser/WebIDL.py#L2241)?). How would I go about avoiding the suffix with nullable arguments?

If we were to add also support for nullable typed arrays then I think we wouldn't be blocked anymore on this in WebGL 1.0.

r? @jdm

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20267)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

💔 Test failed - linux-rel-css

@Xanewok
Copy link
Contributor Author

Xanewok commented Mar 14, 2018

Error when running ./mach filter-intermittents (output here)

Error running mach:

    ['filter-intermittents', 'wpt-errorsummary.log', '--log-intermittents', 'intermittents.log', '--log-filteredsummary', 'filtered-wpt-errorsummary.log', '--tracker-api', 'default', '--reporter-api', 'default']

The error occurred in code that was called by the mach command. This is either
a bug in the called code itself or in the way that mach is calling it.

You should consider filing a bug for this issue.

If filing a bug, please include the full output of mach, including this error
message.

The details of the failure are as follows:

HTTPError: HTTP Error 307: Temporary Redirect

  File "/home/servo/buildbot/slave/linux-rel-css/build/python/servo/testing_commands.py", line 540, in filter_intermittents
    response = urllib2.urlopen(request)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 442, in error
    result = self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 608, in http_error_302
    new = self.redirect_request(req, fp, code, msg, headers, newurl)
  File "/usr/lib/python2.7/urllib2.py", line 569, in redirect_request
    raise HTTPError(req.get_full_url(), code, msg, headers, fp)
@Xanewok
Copy link
Contributor Author

Xanewok commented Mar 14, 2018

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

💔 Test failed - mac-rel-css2

@Xanewok
Copy link
Contributor Author

Xanewok commented Mar 14, 2018

😭

cargo:warning=gfx/angle/checkout/src/common/angleutils.h:33:5: error: unknown type name 'constexpr'

Retrying as in #20265 (comment):

cc @jdm

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2018

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

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.