Should not need to specialize MapTypeToRootKind just to get default behavior
Categories
(Core :: JavaScript: GC, enhancement, P5)
Tracking
()
People
(Reporter: sfink, Assigned: sfink)
Details
Attachments
(1 file)
Right now, if you aren't an actual GC pointer and you wanted a Rooted<T*> for your type, you'd need to specialize MapTypeToRootKind to set your RootKind to Traceable. We do this for JS::Realm* among others. Seems like a nuisance, for us and for embedders.
Assignee | ||
Comment 1•5 years ago
|
||
Pushed by sfink@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/29b1d70e8032 Pointer types should default to RootKind::Traceable unless a more specific RootKind has been set via MapTypeToTraceKind r=jwalden
Comment 3•5 years ago
|
||
Backed out changeset 29b1d70e8032 (bug 1534430) for build bustage. CLOSED TREE
Log:
https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=233283279&repo=autoland&lineNumber=2180
Push with failure:
https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=29b1d70e8032850d0649e2c6f791c9e4e8d23620
Backout:
https://hg.mozilla.org/integration/autoland/rev/0a3a2f8340e311ade4d7776b85ba8214eae74eb1
Updated•5 years ago
|
Assignee | ||
Comment 4•5 years ago
|
||
Sadly, I don't think this is doable.
The patch I attempted to land is completely bogus -- it would return the right value for MapTypeToRootKind<JSScript*,weirdo type>, but MapTypeToRootKind<JSScript*>::kind would still give Traceable (the wrong result).
I can fix that easily enough (where "easily" == "with strenuous effort and great difficulty and a feeling of foolishness once I boiled it back down to the essence of what was required"). It goes something like this:
template <typename T>
struct MapTypeToRootKind<T*> {
// For pointers to types that declare a TraceKind data member, use that.
template <typename U>
static JS::MapTraceKindToRootKind<U::TraceKind> choose(U*, char);
// For all other types, fall back to Traceable.
static MapTypeToRootKind<void> choose(T*, int);
static const JS::RootKind kind = decltype(choose((T*)nullptr, 'x'))::kind;
};
But that depends on the full type information being available, and if it is not available, it will happily resolve to Traceable. Even worse, this file is typically included before the full type info is available, so will lock in the wrong result. (Identical code loaded later gives a different answer.)
I thought I could fix that by using a hardcoded list of type->TraceKind mappings rather than U::TraceKind, since we already enumerate all of the built-in types, but I'm pretty sure that won't work for subtypes of those explicitly listed types.
In theory, it seems like there might be some way to delay the resolution until the root kind is actually needed, and perhaps even make things fail to compile if you instantiate too early, but I'm giving up on this. It's pretty tough to distinguish between completely unknown types and subtypes that have not yet been defined.
Updated•3 years ago
|
Description
•