Open Bug 1817009 Opened 1 year ago Updated 1 year ago

[hazards] Support marking reference types as GC-unsafe


(Core :: JavaScript: GC, enhancement, P3)





(Reporter: sfink, Unassigned)


(Blocks 1 open bug)


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)) {
          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.

Severity: -- → N/A
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.