Outline potentially undefined globals during lowering (#51970)
Currently [1] it is illegal [2] in IRCode to have a GlobalRef in value
position that could potentially throw. This is because in IRCode, we
want to assign flags to every statement and if there are multiple things
with effects in a statement, we lose precision in tracking which they
apply to. However, we currently do allow this in `CodeInfo`. Now that
we're starting to make more use of flags in inference also, this is
becoming annoying (as it did for IRCode), so I would like to do this
transformation earlier. This is an attempt to do this during lowering.
It is not entirely clear that this is precisely the correct place for
it. We could alternatively consider doing it during the global resolve
pass in method.c, but that currently does not renumber SSAValues, so
doing it during the renumbering inside lowering may be easier.
N.B.: This is against #51853, because this needs some of the inference
precision improvements in that PR to avoid regressing the try/catch
elision tests (which before that PR, we were incorrectly computing
effects for statement-position GlobalRefs).
[1]
https://github.com/JuliaLang/julia/commit/39c278b728deb04c3a32d70e3e35dcef7822c0c0
[2]
https://github.com/JuliaLang/julia/blob/2f63cc99fb134fb4adb7f11ba86a4e2ab5adcd48/base/compiler/ssair/verify.jl#L54-L58
---------
Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
Co-authored-by: Oscar Smith <oscardssmith@gmail.com>