Open Bug 1817009 Opened 2 years ago Updated 2 years ago

[hazards] Support marking reference types as GC-unsafe

Categories

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

enhancement

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.

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