Description
We have at least two places (soon to be three) where we rely in IL that the GC doesn't run between certain IL instructions.
sdk/runtime/vm/compiler/frontend/kernel_to_il.cc
Lines 1303 to 1308 in 7d115ed
sdk/runtime/vm/compiler/frontend/kernel_to_il.cc
Lines 1416 to 1436 in 7d115ed
Currently, we:
- force optimize them
- prevent them from being inlined (by being force optimized)
Preventing inlining gives us enough confidence that code motion doesn't move any GCing instructions in between currently.
If we start inlining these, we need to take special care that code motion doesn't move an instruction that can trigger GC in between those instructions:
We should consider adding a NoGC
-scope construct that:
- Checks that only IL instructions with
kNoGC
are added to that scope - Prevents code motion of any
kNoGC
instructions out of that scope and prevents code motion of any non-kNoGC
into that scope.
cc @mkustermann @mraleph (I don't believe we had a tracking issue yet.)
Edit: For the two existing cases running GC is fine, they happen to be idempotent, for the new case it is not. Having this NoGC
-scope clarifies the difference.