Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake dictionaries and unions containing GC values safer #17056
Conversation
highfive
commented
May 26, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
May 26, 2017
|
r? @nox |
|
I have tested the PR and it works great, no more GC crashes with dictionary initializers! |
| @@ -4002,12 +3999,18 @@ def __init__(self, enum): | |||
| } | |||
| } | |||
| impl Default for super::%s { | |||
| fn default() -> super::%s { | |||
This comment has been minimized.
This comment has been minimized.
emilio
May 29, 2017
Member
nit: use 4 space indents. Also, perhaps it's worth to use named arguments?
| selfName = self.makeClassName(d) | ||
| if self.membersNeedTracing(): | ||
| actualType = "RootedTraceableBox<%s>" % selfName | ||
| preInitial = "let mut dictionary = RootedTraceableBox::new(%s::default());\n" % selfName |
This comment has been minimized.
This comment has been minimized.
emilio
May 29, 2017
Member
do you need the interpolation? I'd expected RootedTraceableBox::default() to just work.
|
I have had no luck creating a test for this yet. |
|
|
|
@jdm can we merge this? I have to cherry pick the commits each time I want to test/prepare A-Frame demos in a new branch. |
|
My goal was to write an automated test that demonstrated the problem, but it has been more challenging than I anticipated. I'll try to merge this sometime this week. |
|
|
|
@emilio I have addressed your first comment; the one about the RootedTraceableBox default caused compiler errors because it messed up some type inference. |
|
|
Mark dictionaries containing GC values as must_root, and wrap them in RootedTraceableBox in automatically-generated APIs. To accommodate union variants that are now flagged as unsafe, add RootedTraceableBox to union variants that need to be rooted, rather than wrapping the entire union value.
|
@bors-servo: r=emilio |
|
|
Make dictionaries and unions containing GC values safer Problems: * the Heap::new constructor is memory-unsafe with any value other than Undefined/Null * this means that moving dictionaries containing Heap values (ie. any/object) is memory-unsafe * unions containing GC pointers are similarly unsafe Solutions: - dictionaries containing GC pointers are now wrapped in RootedTraceableBox (even inside other dictionaries) - instead of using Heap::new, dictionaries containing GC pointers are now initialized to a default value (by deriving Default) and mutated one field at a time - dictionaries containing GC pointers are marked #[must_root] - FromJSVal for dictionaries containing GC pointers now returns RootedTraceableBox<Dictionary> - unions wrap their variants that require rooting in RootedTraceableBox Rather than attempting to derive Default for all dictionaries, we only do so for the dictionaries that require it. Because some dictionaries that require it inherit from dictionaries that do not, we need to write manual implementations for those parent dictionaries. This is a better option than having to figure out a default value for types like `Root<T>`, which would be required for deriving Default for all dictionaries. I would still like to come up with an automated test for this, but I figured I would get eyes on this first. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #16952 - [ ] There are tests for these changes <!-- 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/17056) <!-- Reviewable:end -->
|
|
jdm commentedMay 26, 2017
•
edited by larsbergstrom
Problems:
Solutions:
Rather than attempting to derive Default for all dictionaries, we only do so for the dictionaries that require it. Because some dictionaries that require it inherit from dictionaries that do not, we need to write manual implementations for those parent dictionaries. This is a better option than having to figure out a default value for types like
Root<T>, which would be required for deriving Default for all dictionaries.I would still like to come up with an automated test for this, but I figured I would get eyes on this first.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is