How to let the compiler know that a global variable is type-stable for duration of function

Basically, Option (2) is a fancy version of the “function barrier” solution you mentioned. I think it’s the option I’m going to go with.