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

RFC: during using, define module before include, to solve a minor data-race on UUID #43257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Nov 29, 2021

Passing the UUID via global state can be a data-race, and passing it via
TLS seems more awkward than necessary. Instead, we define that require
implicitly makes the module it expects. We make the module a baremodule
initially, until the user calls module Name (or using Base and
defines include and eval). The module call also (re)sets the scope
of the __init__ call, to preserve the prior behavior and order of it.

Passing the UUID via global state can be a data-race, and passing it via
TLS seems more awkward than necessary. Instead, we define that `require`
implicitly makes the module it expects. We make the module a baremodule
initially, until the user calls `module Name` (or `using Base` and
defines `include` and `eval`). The module call also (re)sets the scope
of the `__init__` call, to preserve the prior behavior and order of it.

is_root_module(m::Module) = @lock require_lock haskey(module_keys, m)
root_module_key(m::Module) = @lock require_lock module_keys[m]
function PkgId(m::Module)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Seems like this can stay in pkgid.jl?

}
if (jl_generating_output())
jl_errorf("cannot replace module %s during compilation", jl_symbol_name(name));
jl_printf(JL_STDERR, "WARNING: replacing module %s.\n", jl_symbol_name(name));
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This will break some workflows.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

workflows that print WARNINGs are not stable

try
Base.include(Base.__toplevel__, input)
eval(newm, :(baremodule $(nameof(newm)); $include($newm, $input); end))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Is the extra baremodule layer doing anything here? It seems to me evaluating inside newm is already enough?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Running __init__ functions is tied to syntactic module definitions

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.

2 participants