Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct setting of current_task().scope is undefined behaviour. #1

Open
vchuravy opened this issue Jul 7, 2024 · 0 comments
Open

Direct setting of current_task().scope is undefined behaviour. #1

vchuravy opened this issue Jul 7, 2024 · 0 comments

Comments

@vchuravy
Copy link

vchuravy commented Jul 7, 2024

function scoped_values_set_context(pair::Pair{<:ScopedValue}, rest::Pair{<:ScopedValue}...)
ct = Base.current_task()
original_scope = ct.scope::Union{Nothing, ScopedValues.Scope}
ct.scope = ScopedValues.Scope(original_scope, pair, rest...)
return original_scope
end
function scoped_values_reset_context(old)
ct = current_task()
ct.scope = old
return nothing
end

The direct modification of these fields is undefined behavior. JuliaLang/julia#52309

When I was asked about this in vchuravy/ScopedValues.jl#14 (comment) I stated that this optimization was planned.

scope  = currrent_scope()
scoped_values_reset_context(#=...=#)
scope = current_scope()

Is now being transformed to:

scope  = currrent_scope()
scoped_values_reset_context(#=...=#)

The right way IMO is to "snapshot" the scope with a potential list of scoped values into a PersistentDict and then to write with(snapshot...) do f that sets those scopedvalues to those values again.

(found through Github search for ScopedValue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant