[hazards] Support marking reference types as GC-unsafe
Categories
(Core :: JavaScript: GC, enhancement, P3)
Tracking
()
People
(Reporter: sfink, Unassigned)
References
(Blocks 1 open bug)
Details
If we have code:
SomeVector<T>& vec = getTs();
for (auto element : vec) { ... }
where the vector can be swept or otherwise modified during a GC, it would be nice to be able to mark the "reference to vector" type (here, SomeVector<T>&
) as GC-unsafe. Currently, we do this by requiring a nogc
token to be passed to getTs()
, which works but is a little too restrictive. Consider:
AutoCheckCannotGC nogc;
SomeVector<T>& vec = getTs(nogc);
for (auto element : vec) {
if (!process(element)) {
JS_ReportError(...);
return false;
}
}
The hazard analysis will reject this because constructing the Error object can GC and we're in a nogc scope. If GC unsafety were associated with vec
, then the analysis would see that vec
is dead (due to the return false
) at that point and would not complain.
Note that this is a "nice to have", not a critical need. The above code can be spot-fixed by calling nogc.reset()
just before the return false
. But that's even more bookkeeping work.
Updated•2 years ago
|
Description
•