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

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

Merged
merged 7 commits into from Oct 16, 2015
Merged

Conversation

@eefriedman
Copy link
Contributor

eefriedman commented Oct 15, 2015

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
Copy link

highfive commented Oct 15, 2015

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@nox
Copy link
Member

nox commented Oct 15, 2015

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
Contributor Author

eefriedman commented Oct 15, 2015

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
Contributor

bors-servo commented Oct 15, 2015

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

eefriedman added 7 commits Oct 14, 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>.
@eefriedman eefriedman force-pushed the eefriedman:js-rooting branch from 11c7cdf to 9de42c8 Oct 15, 2015
@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 15, 2015

Rebased, addressed review comments.

@jdm
Copy link
Member

jdm commented Oct 15, 2015

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
Contributor Author

eefriedman commented Oct 15, 2015

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
Copy link
Member

jdm commented Oct 15, 2015

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

@nox
Copy link
Member

nox commented Oct 16, 2015

@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 label Oct 16, 2015
@bors-servo
Copy link
Contributor

bors-servo commented Oct 16, 2015

📌 Commit 9de42c8 has been approved by nox

@bors-servo
Copy link
Contributor

bors-servo commented Oct 16, 2015

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
Contributor

bors-servo commented Oct 16, 2015

@bors-servo bors-servo merged commit 9de42c8 into servo:master Oct 16, 2015
1 check passed
1 check passed
homu Test successful
Details
This was referenced Oct 16, 2015
@bholley
Copy link
Contributor

bholley commented Oct 16, 2015

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

@nox
Copy link
Member

nox commented Oct 16, 2015

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

@bholley
Copy link
Contributor

bholley commented Oct 16, 2015

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
Copy link
Member

jdm commented Oct 16, 2015

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

@bholley
Copy link
Contributor

bholley commented Oct 16, 2015

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
Copy link
Member

jdm commented Oct 16, 2015

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

@bholley
Copy link
Contributor

bholley commented Oct 16, 2015

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

@jdm
Copy link
Member

jdm commented Oct 16, 2015

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

@bholley
Copy link
Contributor

bholley commented Oct 16, 2015

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
Copy link
Member

jdm commented Oct 16, 2015

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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

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