RFC: during using, define module before include, to solve a minor data-race on UUID#43257
Open
RFC: during using, define module before include, to solve a minor data-race on UUID#43257
using, define module before include, to solve a minor data-race on UUID#43257Conversation
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) |
Member
There was a problem hiding this comment.
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)); |
Member
There was a problem hiding this comment.
This will break some workflows.
Member
Author
There was a problem hiding this comment.
workflows that print WARNINGs are not stable
| @lock require_lock register_root_module(newm, pkg) | ||
| try | ||
| Base.include(Base.__toplevel__, input) | ||
| eval(newm, :(baremodule $(nameof(newm)); $include($newm, $input); end)) |
Member
There was a problem hiding this comment.
Is the extra baremodule layer doing anything here? It seems to me evaluating inside newm is already enough?
Member
Author
There was a problem hiding this comment.
Running __init__ functions is tied to syntactic module definitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
requireimplicitly makes the module it expects. We make the module a baremodule
initially, until the user calls
module Name(orusing Baseanddefines
includeandeval). The module call also (re)sets the scopeof the
__init__call, to preserve the prior behavior and order of it.