Skip to content

Conversation

@vtjnash
Copy link
Member

@vtjnash vtjnash commented Mar 26, 2022

This optimizes setglobal! in codegen, as well as fixes some issues encountered with it

side note: our set of random things that might happen when you declare something global (e.g. assign to it, look up its type, using it, import it–possibly as something else–create a method, or write the global keyword in some context—all conditional on whether it was const somewhere at some point) is quite a bit intractable to deal with

Copy link
Member

@simeonschaub simeonschaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super familiar with all the codegen parts, but otherwise LGTM

if (ty == (jl_value_t*)jl_nothing) {
jl_binding_t *b = jl_get_binding_wr(mod, sym, 0);
if (b) {
if (b && b->owner == mod) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch!

vtjnash added 3 commits March 28, 2022 15:18
The codegen declares this is callee rooted (since we do not usually
alllocate), but we might call jl_isa now, which could. The annotations
on this function previously were incorrect.
Main exports everything, so it is not useful to include in this test.

Refs: #44740
Fixes some atomic ordering issues also where we were ignoring the
argument. Uses the new builtin where we could. But also fixes some cases
where we would allocate the global binding at the wrong time (which is a
globally visible side-effect of compilation), or might throw from inside
codegen accidentally there instead.
@vtjnash vtjnash force-pushed the jn/setglobal-optimize branch from ccd83f2 to bcbdfc3 Compare March 28, 2022 19:28
@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Mar 28, 2022
@DilumAluthge DilumAluthge merged commit 0deb28a into master Mar 28, 2022
@DilumAluthge DilumAluthge deleted the jn/setglobal-optimize branch March 28, 2022 21:36
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Mar 28, 2022
@vtjnash
Copy link
Member Author

vtjnash commented Mar 29, 2022

This should probably not have been squashed, as the commit message now is somewhat gibberish

Keno pushed a commit that referenced this pull request Jun 5, 2024
* add missing gc root for typed global assignment

The codegen declares this is callee rooted (since we do not usually
alllocate), but we might call jl_isa now, which could. The annotations
on this function previously were incorrect.

* test: make exports of modules check ignore Main

Main exports everything, so it is not useful to include in this test.

Refs: #44740

* codegen: optimize setglobal like assignment

Fixes some atomic ordering issues also where we were ignoring the
argument. Uses the new builtin where we could. But also fixes some cases
where we would allocate the global binding at the wrong time (which is a
globally visible side-effect of compilation), or might throw from inside
codegen accidentally there instead.
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

Successfully merging this pull request may close these issues.

3 participants