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

Don't let setglobal! implicitly create bindings #54678

Merged
merged 1 commit into from
Jun 8, 2024
Merged

Don't let setglobal! implicitly create bindings #54678

merged 1 commit into from
Jun 8, 2024

Commits on Jun 8, 2024

  1. Don't let setglobal! implicitly create bindings

    PR #44231 (part of Julia 1.9) introduced the ability to modify globals with `Mod.sym = val` syntax.
    However, the intention of this syntax was always to modify *existing* globals in other modules.
    Unfortunately, as implemented, it also implicitly creates new bindings in the other module, even
    if the binding was not previously declared. This was not intended, but it's a bit of a syntax corner
    case, so nobody caught it at the time.
    
    After some extensive discussions and taking into account the near future direction we want to go
    with bindings (#54654 for both), the consensus was reached that we should try to undo the implicit
    creation of bindings (but not the ability to assign the *value* of globals in other modules).
    Note that this was always an error until Julia 1.9, so hopefully it hasn't crept into too many
    packages yet. We'll see what pkgeval says. If use is extensive, we may want to consider a softer
    removal strategy.
    
    Across base and stdlib, there's two cases affected by this change:
    1. A left over debug statement in `precompile` that wanted to assign a new variable in Base for debugging. Removed in this PR.
    2. Distributed wanting to create new bindings. This is a legimitate use case for wanting to
       create bindings in other modules. This is fixed in JuliaLang/Distributed.jl#102.
    
    As noted in that PR, the recommended replacement where implicit binding creation is desired is:
    ```
    Core.eval(mod, Expr(:global, sym))
    invokelatest(setglobal!, mod, sym, val)
    ```
    
    The `invokelatest` is not presently required, but may be needed by #54654, so it's included
    in the recommendation now.
    
    Fixes #54607
    Keno committed Jun 8, 2024
    Configuration menu
    Copy the full SHA
    fd70b3a View commit details
    Browse the repository at this point in the history