Open
Description
While looking at why scoped values weren't performing as expected I saw that we are doing a bunch of runtime calls where I expected it to be none
using Base.ScopedValues
const sval = ScopedValue(1)
function foo()
with(sval => 2) do
sval[]
end
end
code_typed(with, Tuple{var"#foo##0#foo##1", Pair{ScopedValue{Int64}, Int64}})
You can see here that Main.sval
is not getting const propped as it should being a const global (this is not new with binding partitions) so I believe the issue is the OptimizedGenerics pass that is losing the information for that global somewhere.
40 ─ %58 = builtin Base.getfield(Main.sval, :has_default)::Bool
└─── goto #45 if not %58
41 ─ %60 = builtin Base.getfield(Main.sval, :default)::Int64
│ %61 = invoke Core.OptimizedGenerics.KeyValue.get(%49::Base.PersistentDict{ScopedValue, Any}, Main.sval::ScopedValue{Int64})::Union{Nothing, Tuple{Any}}
│ %62 = builtin (%61 === Base.nothing)::Bool