Replace use of separate functor classes with generic lambdas where possible
Categories
(Core :: JavaScript: GC, enhancement, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox67 | --- | fixed |
People
(Reporter: jonco, Assigned: jonco)
References
Details
Attachments
(3 files)
|
35.75 KB,
patch
|
sfink
:
review+
|
Details | Diff | Splinter Review |
|
9.65 KB,
patch
|
sfink
:
review+
|
Details | Diff | Splinter Review |
|
7.64 KB,
patch
|
sfink
:
review+
|
Details | Diff | Splinter Review |
There are a bunch of places where we use functor classes in the GC, mostly in code that works on tagged pointer types where we want to extract the wrapped pointer, cast it to its actual type and then do something on the result.
Generic lambdas result in less code and are easier to follow because the code being called is inline rather than in a separate class. We should replace functor classes with lambdas where possible.
| Assignee | ||
Comment 1•6 years ago
|
||
Mainly this replaces DispatchTyped functions for tagged pointer arugments with MapGCThingTyped that don't have the behaviour of calling a defaultValue() method on the functor, because that isn't present on lambdas. Instead, for types that don't always wrap a GC thing pointer, they now return a Maybe templated on the functor return value.
I rewrote RewrappedTaggedPointer as TaggedPtr and got rid of the macro expansions. I think it's clearer what's going on this way, and also it doesn't require templating on the type of the arguemt which is a pain in a lambda. This also moved to Marking-inl.h.
I also ended up making some changes to the way we update tagged pointers when we trace them or call IsMarked on them etc. I changed this to only update the value if the new value is different, because this seemed to make more sense. I can split this out into a separate patch if you like because it's really orthogonal to the main point of this bug.
Phew. This was larger than anticipated.
| Assignee | ||
Comment 2•6 years ago
|
||
Along the same lines, convert the version of DispatchTraceKindTyped that handles untyped pointer plus trace kind to MapGCThingTyped.
We can't convert the first version yet because this doesn't pass a typed argument to the functor and hence doesn't work with |[](auto t) {...}|. I discoverted that there's a C++20 feature that will allow this eventually though.
| Assignee | ||
Comment 3•6 years ago
|
||
Finally, convert the other functors in Marking.cpp and remove some functors that are now unused.
Comment 4•6 years ago
|
||
Updated•6 years ago
|
Comment 5•6 years ago
|
||
| Assignee | ||
Comment 6•6 years ago
|
||
(In reply to Steve Fink [:sfink] [:s:] from comment #4)
Do you prefer using pair to using a bool& for these three functors? ... It just seems a little more readable to me than the .first()/.second() stuff.
Agreed. I did it this way because I thought it would turn out simpler but on reflection it didn't.
Comment 8•6 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/9856d1e9c9fa
https://hg.mozilla.org/mozilla-central/rev/f18dc7069087
https://hg.mozilla.org/mozilla-central/rev/2eb1d7ff8fa7
Description
•