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

Root sequence<any> params using CustomAutoRooter #19644

Merged
merged 1 commit into from Jan 5, 2018

Conversation

@Xanewok
Copy link
Contributor

Xanewok commented Dec 25, 2017

Attempt at #16678. At the moment this pulls an external remove-handle-conv branch for rust-mozjs (removing FromJSValConvertible implementation for HandleValue and adding one for *mut JSObject)

In short, this roots the sequence<any> and sequence<object> function arguments using CustomAutoRooter (introduced in servo/rust-mozjs#382).

As per #16678 (comment) the underlying vector contains raw gc thing pointers instead of handles. To do that, this introduces new possible isMember = "AutoRoot" value in CodegenRust.py.
The rooted argument is passed to a function wrapped in a CustomAutoRooterGuard RAII root guard (e.g. as CustomAutoRooterGuard<Vec<JSVal>>)

I felt quite out of my depth when trying to adapt CodegenRust.py code, so I'd appreciate any help with how can be done better/in a more clean manner.
Also the name CustomAutoRooterGuard is quite lengthy, so I'm also open to changing it (AutoRoot? AutoRootGuard?)


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #16678 (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 Dec 25, 2017

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon.

@highfive
Copy link

highfive commented Dec 25, 2017

Heads up! This PR modifies the following files:

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

highfive commented Dec 25, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@Xanewok Xanewok changed the title Root seq any Root sequence<any> params using CustomAutoRooter Dec 25, 2017
Copy link
Member

jdm left a comment

This is a good start. I'd like to see what it looks like if we don't overload isMember, as well as having a test that verifies that it works correctly.

@@ -700,6 +700,8 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
assert not (isEnforceRange and isClamp) # These are mutually exclusive

if type.isSequence() or type.isRecord():
if isArgument and type_needs_auto_root(type):
isMember = "AutoRoot"

This comment has been minimized.

@jdm

jdm Dec 29, 2017

Member

Rather than overloading isMember for this, I think we should add a new isAutoRooted argument to getJSToNativeConversionInfo. I think we could remove this logic and just pass isAutoRooted=isAutoRooted to the getJSToNativeConversionInfo on the next line.

@@ -709,6 +711,9 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=" >")

if (isArgument and type_needs_auto_root(type)):

This comment has been minimized.

@jdm

jdm Dec 29, 2017

Member

Similarly, I think this could be replaced by if isAutoRooted:.

default = "UndefinedValue()"
else:
raise TypeError("Can't handle non-null, non-undefined default value here")
return handleOptional("${val}.get()", declType, default)

This comment has been minimized.

@jdm

jdm Dec 29, 2017

Member

Rather than duplicate this code, I would prefer to have a special check around declType.

template, replacementVariables, declType, "arg%d" % index)
template, replacementVariables, declType, arg)

# TODO: Only for sequence<{any,object}> now

This comment has been minimized.

@jdm

jdm Dec 29, 2017

Member

Why is this TODO necessary? Isn't this check encapsulated in type_needs_auto_root?

@@ -449,6 +450,10 @@ impl TestBindingMethods for TestBinding {
fn PassCallbackFunction(&self, _: Rc<Function>) {}
fn PassCallbackInterface(&self, _: Rc<EventListener>) {}
fn PassSequence(&self, _: Vec<i32>) {}
#[allow(unsafe_code)]
unsafe fn PassAnySequence(&self, _: *mut JSContext, _: CustomAutoRooterGuard<Vec<JSVal>>) {}

This comment has been minimized.

@jdm

jdm Dec 29, 2017

Member

It would be useful to have an automated test that verifies that the values passed in actually make sense, since that was a problem with the old sequence<any> code. Perhaps have a method that accepts a sequence and returns it, and compare the array values in JS?

@Xanewok
Copy link
Contributor Author

Xanewok commented Dec 29, 2017

I addressed the review comments in the new commit. I still have to include a test for that.

@jdm I have a question regarding adding the test.
From what I saw, the automated tests for this should be here? Should I test the gc using window.gc() like in transitionend_safety.html?

I figured it'd be good to check if the values inside passed sequence in some test function receiving sequence are not all undefined? Or maybe use specific ones? In the latter case, given how far away the actual tests in html are from testbinding.rs file, I'm not sure the specified value usage will be clear.

By the was, is there a way to run only a specific .html test using ./mach test wpt <test>? Pointing to the tests/wpt/mozilla/tests/mozilla executes the full test suite with 1335 tests, but when I point to a specific .html inside test run starts but doesn't execute a single test.
Found guide at https://github.com/servo/servo/blob/master/tests/wpt/README.md. Running a single test using ./mach test-wpt <path-to-html> now.

@Xanewok
Copy link
Contributor Author

Xanewok commented Dec 29, 2017

Added an additional WPT test. Hope this is what you had in mind, didn't touch Servo tests before 🤔

@Xanewok Xanewok force-pushed the Xanewok:root-seq-any branch 2 times, most recently from a08c5db to 7b66289 Dec 30, 2017
Copy link
Member

emilio left a comment

Thanks a lot for finally fixing this! :)

def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, variadic=False):
info = getJSToNativeConversionInfo(
ty, descriptorProvider, isArgument=True)
ty, descriptorProvider, isArgument=True,
isAutoRooted=True if type_needs_auto_root(ty) else False)

This comment has been minimized.

@emilio

emilio Jan 3, 2018

Member

nit: just isAutoRooted=type_needs_auto_root(ty)?

This comment has been minimized.

@Xanewok

Xanewok Jan 3, 2018

Author Contributor

Right, thanks!

Copy link
Member

jdm left a comment

The codegen changes look much nicer. Thanks!

</head>
<script>
test(function() {
function assert_array_equals(lhs, rhs) {

This comment has been minimized.

This comment has been minimized.

@Xanewok

Xanewok Jan 3, 2018

Author Contributor

Fixed, thanks!

assert_array_equals(seq, t.anySequencePassthrough(seq));

var seq = new Array(null, {'inner': 1, 'a': 'as', 'toString': function() { seq = null; return Object.prototype.toString(this); }}, {'inner': 2}, null, undefined);
assert_array_equals(seq, t.anySequencePassthrough(seq));

This comment has been minimized.

@jdm

jdm Jan 3, 2018

Member

Just to verify, have you checked if any of these tests fail without your codegen changes?

This comment has been minimized.

@Xanewok

Xanewok Jan 3, 2018

Author Contributor

Yes. Previously, with Xanewok@01d1039:

var seq = [5, "str", { key: "val" }, undefined];
console.log("seq: " + seq);
var lvalue = t.anySequencePassthrough(seq);
console.log("lvalue: " + lvalue);
console.log("rvalue: " + t.anySequencePassthrough(seq));
assert_array_equals(seq, t.anySequencePassthrough(seq), "Returned simple array is the same");

errors with:

 0:13.20 PROCESS_OUTPUT: Thread-TestrunnerManager-1 (pid:27314) "seq: 5,str,[object Object],"   
 0:13.20 PROCESS_OUTPUT: Thread-TestrunnerManager-1 (pid:27314) "lvalue: 0,5e-324,5e-324,5e-324"
 0:13.20 PROCESS_OUTPUT: Thread-TestrunnerManager-1 (pid:27314) "rvalue: 0,5e-324,5e-324,5e-324"
...
Expected PASS, got FAIL                                 
assert_array_equals: Returned simple array is the same property 0, expected 0 but got 5

This comment has been minimized.

@jdm

jdm Jan 3, 2018

Member

\o/

@jdm
jdm approved these changes Jan 3, 2018
bors-servo added a commit to servo/rust-mozjs that referenced this pull request Jan 3, 2018
Remove FromJSValConvertible implementation for HandleValue

Needed for servo/servo#19644.

Removes FromJSValConvertible implementations for `HandleValue`, so `Vec<HandleValue>` conversion is impossible.
Also adds the implementation for `*mut JSObject` so the `sequence<object>` -> `CustomAutoRooterGuard<Vec<*mut JSObject>>` conversion works.

<!-- 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/388)
<!-- Reviewable:end -->
@jdm
Copy link
Member

jdm commented Jan 3, 2018

Once servo/rust-mozjs#388 merges then we can update this to not use the branch.

bors-servo added a commit to servo/rust-mozjs that referenced this pull request Jan 3, 2018
Remove FromJSValConvertible implementation for HandleValue

Needed for servo/servo#19644.

Removes FromJSValConvertible implementations for `HandleValue`, so `Vec<HandleValue>` conversion is impossible.
Also adds the implementation for `*mut JSObject` so the `sequence<object>` -> `CustomAutoRooterGuard<Vec<*mut JSObject>>` conversion works.

<!-- 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/388)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 5, 2018

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

bors-servo added a commit to servo/rust-mozjs that referenced this pull request Jan 5, 2018
Remove FromJSValConvertible implementation for HandleValue

Needed for servo/servo#19644.

Removes FromJSValConvertible implementations for `HandleValue`, so `Vec<HandleValue>` conversion is impossible.
Also adds the implementation for `*mut JSObject` so the `sequence<object>` -> `CustomAutoRooterGuard<Vec<*mut JSObject>>` conversion works.

<!-- 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/388)
<!-- Reviewable:end -->
@jdm
Copy link
Member

jdm commented Jan 5, 2018

Upstream PR merged.

@jdm jdm added the S-needs-squash label Jan 5, 2018
Also pulls in mozjs 0.1.10 to support the change.
@Xanewok Xanewok force-pushed the Xanewok:root-seq-any branch from cc568cd to a01d1ea Jan 5, 2018
@Xanewok
Copy link
Contributor Author

Xanewok commented Jan 5, 2018

r? @jdm

@jdm
Copy link
Member

jdm commented Jan 5, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Jan 5, 2018

📌 Commit a01d1ea has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jan 5, 2018

Testing commit a01d1ea with merge 989d2fd...

bors-servo added a commit that referenced this pull request Jan 5, 2018
Root sequence<any> params using CustomAutoRooter

<!-- Please describe your changes on the following line: -->

Attempt at #16678. At the moment this pulls an external [remove-handle-conv](https://github.com/Xanewok/rust-mozjs/tree/remove-handle-conv) branch for rust-mozjs (removing `FromJSValConvertible` implementation for `HandleValue` and adding one for `*mut JSObject`)

In short, this roots the `sequence<any>` and `sequence<object>` function arguments using `CustomAutoRooter` (introduced in servo/rust-mozjs#382).

As per #16678 (comment) the underlying vector contains raw gc thing pointers instead of handles. To do that, this introduces new possible `isMember = "AutoRoot"` value in CodegenRust.py.
The rooted argument is passed to a function wrapped in a `CustomAutoRooterGuard` [RAII root guard](https://github.com/servo/rust-mozjs/blob/ed5e37a288b5738d9b571b8100b4a22a2c00f075/src/rust.rs#L586-L588) (e.g. as `CustomAutoRooterGuard<Vec<JSVal>>`)

I felt quite out of my depth when trying to adapt CodegenRust.py code, so I'd appreciate any help with how can be done better/in a more clean manner.
Also the name `CustomAutoRooterGuard` is quite lengthy, so I'm also open to changing it (`AutoRoot`? `AutoRootGuard`?)

---
<!-- 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
- [x] These changes fix #16678  (github issue number if applicable).

<!-- Either: -->
- [X] 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/19644)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 5, 2018

@bors-servo bors-servo merged commit a01d1ea into servo:master Jan 5, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
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.

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