-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
It might be beneficial to perform some optimization over scoped values.
In particular it would be beneficial for the value lookup to be coalesced within a dynamical scope.
This would require them to be CSE'd or for GVN (#51120) to be aware of their semantics.
We would need to annotate in the IR the extent of a dynamical scope, since
since ScopedValue are only constant within that region.
token = Expr(:dynamical_scope_enter, args::Pair{ScopedValue, Any}...)
...
Expr(:dynamical_scope_exit, token)
This might be a bit frustrating since currently we have:
current_scope = current_task().scope
current_task().scope = Scope(...)
try
finally
current_task().scope = current_scope
end
and thus we would introduce a "silent" new form of a try...finally
block which seems not ideal.
But maybe a representation like:
old_scope = Expr(:dynamical_scope_enter, args::Pair{ScopedValue, Any}...)
try
finally
Expr(:dynamical_scope_exit, old_scope)
end
Could still work?
Of course this is predicated on how folks are using ScopedValues in the wild to determine if this would be useful at all.
Java seems to do this kind of optimization + a very small cache.