Giter Club home page Giter Club logo

Comments (12)

Keno avatar Keno commented on June 23, 2024 3

Discussed in the context of the meeting we had for #54654 and decided that this is a serious enough oversight that we should attempt to correct this as quickly as possible, keeping in mind that it was in the system for two releases, so we need to at the very least pkgeval and may do a soft deprecation.

from julia.

vtjnash avatar vtjnash commented on June 23, 2024 1

This is a little different, since it not only sets the global, it also creates it if it didn't yet exist and assigns its type. I have entertained the idea of disallowing setting globals that don't exist (it is a 2 line patch roughly), but it breaks a few minor things (Serialization specifically) so it isn't entirely obvious that is beneficial just to help catch typos.

from julia.

KristofferC avatar KristofferC commented on June 23, 2024 1

I suspect that it happened in a triage discussion referenced by #44231 (comment)

But there is nothing in that comment saying that setting globals in different modules should not be allowed? In fact, it explicitly removes the test that checks that this is not allowed https://github.com/JuliaLang/julia/pull/44231/files#diff-829029ba7e34234a5360ccd30854edbcff7fb932c1d2f9a52f1027e881ae9a7a.

Removing this now would be breaking anyway so maybe just best to let this be.

from julia.

cstjean avatar cstjean commented on June 23, 2024

Personally, I love the change. Especially now that globals can be typed properly, being able to just MyPackage.some_global_setting = true is just a very nice and convenient interface for packages.

The former behaviour had that "You are a bad person for using globals" vibe that just felt out of sync with the general permissiveness of a language that allows me to redefine addition if I feel like it.

from julia.

KristofferC avatar KristofferC commented on June 23, 2024

From the discussion at #44231, this seems unintentional.

I'm reading through that PR but can't really find that discussion. Could you link to it explicitly?

Anyway, this seems fine to me, having to go via eval always felt silly to me.

from julia.

LilithHafner avatar LilithHafner commented on June 23, 2024

I suspect that it happened in a triage discussion referenced by #44231 (comment)

from julia.

bvdmitri avatar bvdmitri commented on June 23, 2024

@vtjnash could Serialization use a somewhat private API for it instead of relying on the = operator?

from julia.

vtjnash avatar vtjnash commented on June 23, 2024

Sure, it could use Core.eval(m, :(global $var)) before setglobal!(m, var, val). The patch looks something like this, though apparently some code has refactored so it takes a bit more than 2 lines right now to add it:

diff --git a/src/module.c b/src/module.c
index 7a12552415..470bf3df98 100644
--- a/src/module.c
+++ b/src/module.c
@@ -219,13 +219,16 @@ static void check_safe_newbinding(jl_module_t *m, jl_sym_t *var)
 static jl_module_t *jl_binding_dbgmodule(jl_binding_t *b, jl_module_t *m, jl_sym_t *var) JL_GLOBALLY_ROOTED;
 
 // get binding for assignment
-JL_DLLEXPORT jl_binding_t *jl_get_binding_wr(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *var)
+JL_DLLEXPORT jl_binding_t *jl_get_binding_wr(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *var, int alloc)
 {
     jl_binding_t *b = jl_get_module_binding(m, var, 1);
     jl_binding_t *b2 = jl_atomic_load_relaxed(&b->owner);
     if (b2 != b) {
-        if (b2 == NULL)
+        if (b2 == NULL) {
             check_safe_newbinding(m, var);
+            if (!alloc)
+                jl_errorf("Global %s.%s cannot be set since it does not exist.", jl_symbol_name(m->name), jl_symbol_name(var));
+        }
         if (b2 != NULL || (!jl_atomic_cmpswap(&b->owner, &b2, b) && b2 != b)) {
             jl_module_t *from = jl_binding_dbgmodule(b, m, var);
             if (from == m)

from julia.

LilithHafner avatar LilithHafner commented on June 23, 2024

Perhaps I misunderstood the "don't do setfield!" sentiment as "don't do property access syntax". In any event, this issue has accomplished its objective of double checking that we removed that intentional error intentionally.

from julia.

KristofferC avatar KristofferC commented on June 23, 2024

I think that the statement there is intended to be read that settings and reading globals from modules shouldn't piggy back on the setfield! / getfield intrinsics but have their own. Then setproperty!/getproperty just uses these new intrinsics.

from julia.

topolarity avatar topolarity commented on June 23, 2024

This is a little different, since it not only sets the global, it also creates it if it didn't yet exist and assigns its type.

I think that means that #53750 is incomplete and also needs to consider that binding types can revert to undef, unless we prohibit this behavior

from julia.

LilithHafner avatar LilithHafner commented on June 23, 2024

Triage is are okay with keeping changing values of globals in other modules with Mod.x = 6 syntax and setglobal!.

We want to change setglobal! to no longer create new globals. Mod.x = 6 should keep calling setglobal!.
x = 6 within a module should be special in that it may create a new global (and increment world age)

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.