Skip to content

Fix uses of JS<T> as a type on the stack - #8026

Merged
bors-servo merged 7 commits into
servo:masterfrom
eefriedman:js-rooting
Oct 16, 2015
Merged

bors-servo merged 7 commits into
servo:masterfrom
eefriedman:js-rooting

Conversation

@eefriedman

Copy link
Copy Markdown
Contributor

JS<T> belongs on the heap, and only on the heap. This is a collection of fixes so that code uses either Root<T> or &T to pass around garbage-collected pointers.

Ideally, we could completely ban constructing a JS<T> outside of constructor functions, but we aren't quite there yet.

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 15, 2015
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@nox nox added A-content/dom Interacting with the DOM from web content I-safety Some piece of code violates memory safety guarantees. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 15, 2015
@nox

nox commented Oct 15, 2015

Copy link
Copy Markdown
Contributor

Nice work!

-S-awaiting-review +S-needs-code-changes


Reviewed 7 of 7 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, 11 of 11 files at r4, 7 of 7 files at r5, 1 of 1 files at r6.
Review status: all files reviewed at latest revision, 4 unresolved discussions, all commit checks successful.


components/script/dom/bindings/js.rs, line 232 [r1] (raw file):
Why not bound T with HeapSizeOf and derive that impl?


components/script/dom/bindings/js.rs, line 305 [r1] (raw file):
Why not bound T with HeapSizeOf and derive that impl?


components/script/dom/document.rs, line 304 [r4] (raw file):
base.r() should work just fine.


components/script/dom/nodelist.rs, line 106 [r5] (raw file):
last_visited.r() should work just fine.


Comments from the review on Reviewable.io

@nox nox self-assigned this Oct 15, 2015
@eefriedman

Copy link
Copy Markdown
Contributor Author

Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


components/script/dom/bindings/js.rs, line 232 [r1] (raw file):
The derive macro can't derive the impl because of the UnsafeCell. As for delegating... it seems kind of pointless.


components/script/dom/document.rs, line 304 [r4] (raw file):
Ah... I didn't realize the RootedReference trait existed.


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

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

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 15, 2015
A copy of a JS<T> doesn't have the rooting properties of the original,
so it makes no sense for it to implement Copy.
It's never correct to return a JS<T>.  Maybe the lint should catch this?
MutNullableHeap is going away in favor of MutNullableHeapJS.
get() must always return a rooted value, because we have no way of
ensuring the value won't be invalidated. set() takes an &T because it's
convenient; there isn't any need to expose JS<T>.
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Oct 15, 2015
@eefriedman

Copy link
Copy Markdown
Contributor Author

Rebased, addressed review comments.

@jdm

jdm commented Oct 15, 2015

Copy link
Copy Markdown
Member

I'm curious if eefriedman@7a08b29 passes the rooting static analysis. I believe it shouldn't, since DOMRefCell isn't a must_root type.

@eefriedman

Copy link
Copy Markdown
Contributor Author

Yes, this branch passes the lint. Why were you expecting it to trigger? (The current version of the must_root lint doesn't really reason about type parameters: it essentially just assumes Generic<Foo> is must_root if Foo is must_root.)

@jdm

jdm commented Oct 15, 2015

Copy link
Copy Markdown
Member

Mmm, I forgot that the work in #4336 only blacklisted some particular types, rather than fully supporting generic types :(

@nox

nox commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

@bors-servo r+

-S-needs-rebase


Reviewed 11 of 11 files at r7.
Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from the review on Reviewable.io

@nox nox removed the S-needs-rebase There are merge conflict errors. label Oct 16, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 9de42c8 has been approved by nox

@highfive highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 16, 2015
@highfive highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 16, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 9de42c8 with merge 7c7dbde...

bors-servo pushed a commit that referenced this pull request Oct 16, 2015
Fix uses of JS<T> as a type on the stack

`JS<T>` belongs on the heap, and only on the heap.  This is a collection of fixes so that code uses either `Root<T>` or `&T` to pass around garbage-collected pointers.

Ideally, we could completely ban constructing a `JS<T>` outside of constructor functions, but we aren't quite there yet.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8026)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt

@bors-servo
bors-servo merged commit 9de42c8 into servo:master Oct 16, 2015
This was referenced Oct 16, 2015
@bholley

bholley commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

Can someone explain to me why &T is safe but JS is not?

@nox

nox commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

Because the only way to obtain &T is from Root<T> or a similar type.

@bholley

bholley commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

I see. But what happens if the GC moves the T you're referencing with the &T? It seems like we'd need to be passing around &Root<T> for that to be safe.

@jdm

jdm commented Oct 16, 2015

Copy link
Copy Markdown
Member

The T will never be moved, since it's a Rust-allocated object instead of a JS reflector.

@bholley

bholley commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

I see - so what happens when the GC wants to move the JS object allocated in the same buffer? Or are we not doing that anymore?

@jdm

jdm commented Oct 16, 2015

Copy link
Copy Markdown
Member

The future of fused/magic DOM objects is still undecided.

@bholley

bholley commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

Ok - but what is the current behavior? Does the GC move the reflectors, or is moving GC disabled?

@jdm

jdm commented Oct 16, 2015

Copy link
Copy Markdown
Member

Moving GC should be enabled; the only GC feature I'm aware of that's disabled is incremental GC.

@bholley

bholley commented Oct 16, 2015

Copy link
Copy Markdown
Contributor

Oh - so the thing that isn't enabled is fused objects? I thought those were there from the start, but I suppose I'm probably wrong.

@jdm

jdm commented Oct 16, 2015

Copy link
Copy Markdown
Member

Right, we've always had separate reflectors and Rust DOM objects.

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

Labels

A-content/dom Interacting with the DOM from web content I-safety Some piece of code violates memory safety guarantees. S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants