Skip to content

Commit

Permalink
Merge branch 'master' into ib/repl_trailing_quote_path
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Oct 22, 2024
2 parents 73b16a2 + 049d92a commit 3583114
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 219 deletions.
8 changes: 8 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ Standard library changes
`AnnotatedString` with various faces or other attributes applied ([#49586]).

#### Package Manager
* It is now possible to specify "sources" for packages in a `[sources]` section in Project.toml.
This can be used to add non-registered normal or test dependencies.
* Pkg now obeys `[compat]` bounds for `julia` and raises an error if the version of the running Julia binary is incompatible with the bounds in `Project.toml`.
Pkg has always obeyed this compat when working with Registry packages. This change affects mostly local packages
* `pkg> add` and `Pkg.add` will now add compat entries for new direct dependencies if the active environment is a
package (has a `name` and `uuid` entry).
* Dependencies can now be directly added as weak deps or extras via the `pkg> add --weak/extra Foo` or
`Pkg.add("Foo", target=:weakdeps/:extras)` forms.

#### LinearAlgebra
* `cbrt(::AbstractMatrix{<:Real})` is now defined and returns real-valued matrix cube roots of real-valued matrices ([#50661]).
Expand Down
1 change: 0 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ function __init__()
init_load_path()
init_active_project()
append!(empty!(_sysimage_modules), keys(loaded_modules))
empty!(explicit_loaded_modules)
empty!(loaded_precompiles) # If we load a packageimage when building the image this might not be empty
for (mod, key) in module_keys
push!(get!(Vector{Module}, loaded_precompiles, key), mod)
Expand Down
11 changes: 7 additions & 4 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,8 @@ arbitrary code in fixed worlds. `world` may be `UnitRange`, in which case the ma
will error unless the binding is valid and has the same value across the entire world
range.
The `@world` macro is primarily used in the priniting of bindings that are no longer available
in the current world.
The `@world` macro is primarily used in the printing of bindings that are no longer
available in the current world.
## Example
```
Expand All @@ -1283,9 +1283,12 @@ julia> fold
"""
macro world(sym, world)
if isa(sym, Symbol)
return :($(_resolve_in_world)($world, $(QuoteNode(GlobalRef(__module__, sym)))))
return :($(_resolve_in_world)($(esc(world)), $(QuoteNode(GlobalRef(__module__, sym)))))
elseif isa(sym, GlobalRef)
return :($(_resolve_in_world)($world, $(QuoteNode(sym))))
return :($(_resolve_in_world)($(esc(world)), $(QuoteNode(sym))))
elseif isa(sym, Expr) && sym.head === :(.) &&
length(sym.args) == 2 && isa(sym.args[2], QuoteNode) && isa(sym.args[2].value, Symbol)
return :($(_resolve_in_world)($(esc(world)), $(GlobalRef)($(esc(sym.args[1])), $(sym.args[2]))))
else
error("`@world` requires a symbol or GlobalRef")
end
Expand Down
49 changes: 23 additions & 26 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -974,14 +974,14 @@ function explicit_manifest_deps_get(project_file::String, where::PkgId, name::St
entry = entry::Dict{String, Any}
uuid = get(entry, "uuid", nothing)::Union{String, Nothing}
uuid === nothing && continue
# deps is either a list of names (deps = ["DepA", "DepB"]) or
# a table of entries (deps = {"DepA" = "6ea...", "DepB" = "55d..."}
deps = get(entry, "deps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
if UUID(uuid) === where.uuid
found_where = true
# deps is either a list of names (deps = ["DepA", "DepB"]) or
# a table of entries (deps = {"DepA" = "6ea...", "DepB" = "55d..."}
deps = get(entry, "deps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
if deps isa Vector{String}
found_name = name in deps
break
found_name && @goto done
elseif deps isa Dict{String, Any}
deps = deps::Dict{String, Any}
for (dep, uuid) in deps
Expand All @@ -1000,30 +1000,33 @@ function explicit_manifest_deps_get(project_file::String, where::PkgId, name::St
return PkgId(UUID(uuid), name)
end
exts = extensions[where.name]::Union{String, Vector{String}}
weakdeps = get(entry, "weakdeps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
if (exts isa String && name == exts) || (exts isa Vector{String} && name in exts)
weakdeps = get(entry, "weakdeps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
if weakdeps !== nothing
if weakdeps isa Vector{String}
found_name = name in weakdeps
break
elseif weakdeps isa Dict{String, Any}
weakdeps = weakdeps::Dict{String, Any}
for (dep, uuid) in weakdeps
uuid::String
if dep === name
return PkgId(UUID(uuid), name)
for deps′ in [weakdeps, deps]
if deps′ !== nothing
if deps′ isa Vector{String}
found_name = name in deps′
found_name && @goto done
elseif deps′ isa Dict{String, Any}
deps′ = deps′::Dict{String, Any}
for (dep, uuid) in deps′
uuid::String
if dep === name
return PkgId(UUID(uuid), name)
end
end
end
end
end
end
end
# `name` is not an ext, do standard lookup as if this was the parent
return identify_package(PkgId(UUID(uuid), dep_name), name)
end
end
end
end
end
@label done
found_where || return nothing
found_name || return PkgId(name)
# Only reach here if deps was not a dict which mean we have a unique name for the dep
Expand Down Expand Up @@ -1554,7 +1557,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
# TODO: Better error message if this lookup fails?
uuid_trigger = UUID(totaldeps[trigger]::String)
trigger_id = PkgId(uuid_trigger, trigger)
if !haskey(explicit_loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
if !haskey(Base.loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
trigger1 = get!(Vector{ExtensionId}, EXT_DORMITORY, trigger_id)
push!(trigger1, gid)
else
Expand Down Expand Up @@ -2428,9 +2431,8 @@ function __require_prelocked(uuidkey::PkgId, env=nothing)
insert_extension_triggers(uuidkey)
# After successfully loading, notify downstream consumers
run_package_callbacks(uuidkey)
elseif !haskey(explicit_loaded_modules, uuidkey)
explicit_loaded_modules[uuidkey] = m
run_package_callbacks(uuidkey)
else
newm = root_module(uuidkey)
end
return m
end
Expand All @@ -2443,7 +2445,6 @@ end
PkgOrigin() = PkgOrigin(nothing, nothing, nothing)
const pkgorigins = Dict{PkgId,PkgOrigin}()

const explicit_loaded_modules = Dict{PkgId,Module}() # Emptied on Julia start
const loaded_modules = Dict{PkgId,Module}() # available to be explicitly loaded
const loaded_precompiles = Dict{PkgId,Vector{Module}}() # extended (complete) list of modules, available to be loaded
const loaded_modules_order = Vector{Module}()
Expand Down Expand Up @@ -2483,7 +2484,6 @@ end
end
maybe_loaded_precompile(key, module_build_id(m)) === nothing && push!(loaded_modules_order, m)
loaded_modules[key] = m
explicit_loaded_modules[key] = m
module_keys[m] = key
end
nothing
Expand Down Expand Up @@ -2515,9 +2515,6 @@ loaded_modules_array() = @lock require_lock copy(loaded_modules_order)
# after unreference_module, a subsequent require call will try to load a new copy of it, if stale
# reload(m) = (unreference_module(m); require(m))
function unreference_module(key::PkgId)
if haskey(explicit_loaded_modules, key)
m = pop!(explicit_loaded_modules, key)
end
if haskey(loaded_modules, key)
m = pop!(loaded_modules, key)
# need to ensure all modules are GC rooted; will still be referenced
Expand Down Expand Up @@ -3126,7 +3123,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
# build up the list of modules that we want the precompile process to preserve
if keep_loaded_modules
concrete_deps = copy(_concrete_dependencies)
for (pkgreq, modreq) in loaded_modules # TODO: convert all relevant staleness heuristics to use explicit_loaded_modules instead
for (pkgreq, modreq) in loaded_modules
if !(pkgreq === Main || pkgreq === Core || pkgreq === Base)
push!(concrete_deps, pkgreq => module_build_id(modreq))
end
Expand Down
6 changes: 3 additions & 3 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1685,9 +1685,9 @@ end
# The rest of this is defined in essentials.jl, but UnitRange is not available
function _resolve_in_world(worlds::UnitRange, gr::GlobalRef)
# Validate that this binding's reference covers the entire world range
bpart = lookup_binding_partition(first(worlds), gr)
if bpart.max_world < last(world)
bpart = lookup_binding_partition(UInt(first(worlds)), gr)
if bpart.max_world < last(worlds)
error("Binding does not cover the full world range")
end
_resolve_in_world(last(world), gr)
_resolve_in_world(UInt(last(worlds)), gr)
end
63 changes: 61 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,8 @@ function show_type_name(io::IO, tn::Core.TypeName)
sym = (globfunc ? globname : tn.name)::Symbol
globfunc && print(io, "typeof(")
quo = false
world = check_world_bounded(tn)
world !== nothing && print(io, "@world(")
if !(get(io, :compact, false)::Bool)
# Print module prefix unless type is visible from module passed to
# IOContext If :module is not set, default to Main.
Expand All @@ -1078,8 +1080,6 @@ function show_type_name(io::IO, tn::Core.TypeName)
end
end
end
world = check_world_bounded(tn)
world !== nothing && print(io, "@world(")
show_sym(io, sym)
world !== nothing && print(io, ", ", world, ")")
quo && print(io, ")")
Expand Down Expand Up @@ -3359,3 +3359,62 @@ end
function show(io::IO, ::MIME"text/plain", oc::Core.OpaqueClosure{A, R}) where {A, R}
show(io, oc)
end

# printing bindings and partitions
function print_partition(io::IO, partition::Core.BindingPartition)
print(io, partition.min_world)
print(io, ":")
max_world = @atomic partition.max_world
if max_world == typemax(UInt)
print(io, '')
else
print(io, max_world)
end
print(io, " - ")
kind = binding_kind(partition)
if is_some_const_binding(kind)
print(io, "constant binding to ")
print(io, partition_restriction(partition))
elseif kind == BINDING_KIND_GUARD
print(io, "undefined binding - guard entry")
elseif kind == BINDING_KIND_FAILED
print(io, "ambiguous binding - guard entry")
elseif kind == BINDING_KIND_DECLARED
print(io, "undefined, but declared using `global` - guard entry")
elseif kind == BINDING_KIND_IMPLICIT
print(io, "implicit `using` from ")
print(io, partition_restriction(partition))
elseif kind == BINDING_KIND_EXPLICIT
print(io, "explicit `using` from ")
print(io, partition_restriction(partition))
elseif kind == BINDING_KIND_IMPORTED
print(io, "explicit `import` from ")
print(io, partition_restriction(partition))
else
@assert kind == BINDING_KIND_GLOBAL
print(io, "global variable with type ")
print(io, partition_restriction(partition))
end
end

function show(io::IO, ::MIME"text/plain", partition::Core.BindingPartition)
print(io, "BindingPartition ")
print_partition(io, partition)
end

function show(io::IO, ::MIME"text/plain", bnd::Core.Binding)
print(io, "Binding ")
print(io, bnd.globalref)
if !isdefined(bnd, :partitions)
print(io, "No partitions")
else
partition = @atomic bnd.partitions
while true
println(io)
print(io, " ")
print_partition(io, partition)
isdefined(partition, :next) || break
partition = @atomic partition.next
end
end
end
35 changes: 35 additions & 0 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,38 @@ macro timed(ex)
)
end
end

# Exported, documented, and tested in InteractiveUtils
# here so it's possible to time/trace all imports, including InteractiveUtils and its deps
macro time_imports(ex)
quote
try
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
$(esc(ex))
finally
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
end
end
end

macro trace_compile(ex)
quote
try
ccall(:jl_force_trace_compile_timing_enable, Cvoid, ())
$(esc(ex))
finally
ccall(:jl_force_trace_compile_timing_disable, Cvoid, ())
end
end
end

macro trace_dispatch(ex)
quote
try
ccall(:jl_force_trace_dispatch_enable, Cvoid, ())
$(esc(ex))
finally
ccall(:jl_force_trace_dispatch_disable, Cvoid, ())
end
end
end
16 changes: 0 additions & 16 deletions src/codegen-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,6 @@ JL_DLLEXPORT uint64_t jl_getUnwindInfo_fallback(uint64_t dwAddr)

JL_DLLEXPORT void jl_register_passbuilder_callbacks_fallback(void *PB) { }

#define MODULE_PASS(NAME, CLASS, CREATE_PASS) \
JL_DLLEXPORT void LLVMExtraMPMAdd##CLASS##_fallback(void *PM) UNAVAILABLE
#define CGSCC_PASS(NAME, CLASS, CREATE_PASS) \
JL_DLLEXPORT void LLVMExtraCGPMAdd##CLASS##_fallback(void *PM) UNAVAILABLE
#define FUNCTION_PASS(NAME, CLASS, CREATE_PASS) \
JL_DLLEXPORT void LLVMExtraFPMAdd##CLASS##_fallback(void *PM) UNAVAILABLE
#define LOOP_PASS(NAME, CLASS, CREATE_PASS) \
JL_DLLEXPORT void LLVMExtraLPMAdd##CLASS##_fallback(void *PM) UNAVAILABLE

#include "llvm-julia-passes.inc"

#undef MODULE_PASS
#undef CGSCC_PASS
#undef FUNCTION_PASS
#undef LOOP_PASS

//LLVM C api to the julia JIT
JL_DLLEXPORT void* JLJITGetLLVMOrcExecutionSession_fallback(void* JIT) UNAVAILABLE

Expand Down
4 changes: 1 addition & 3 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2566,12 +2566,10 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila
jl_static_show(s_precompile, mi->specTypes);
jl_printf(s_precompile, ")");
if (is_recompile) {
jl_printf(s_precompile, " # recompile");
if (s_precompile == JL_STDERR && jl_options.color != JL_OPTIONS_COLOR_OFF) {
jl_printf(s_precompile, "\e[0m");
}
else {
jl_printf(s_precompile, " # recompile");
}
}
jl_printf(s_precompile, "\n");
if (s_precompile != JL_STDERR)
Expand Down
2 changes: 1 addition & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ static void jl_emit_codeinst_to_jit(
int waiting = jl_analyze_workqueue(codeinst, params);
if (waiting) {
auto release = std::move(params.tsctx_lock); // unlock again before moving from it
incompletemodules.insert(std::pair(codeinst, std::tuple(std::move(params), waiting)));
incompletemodules.insert(std::pair(codeinst, std::make_tuple(std::move(params), waiting)));
}
else {
finish_params(result_m.getModuleUnlocked(), params);
Expand Down
15 changes: 0 additions & 15 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -547,21 +547,6 @@
YY(jl_getUnwindInfo) \
YY(jl_get_libllvm) \
YY(jl_register_passbuilder_callbacks) \
YY(LLVMExtraMPMAddCPUFeaturesPass) \
YY(LLVMExtraMPMAddRemoveNIPass) \
YY(LLVMExtraMPMAddMultiVersioningPass) \
YY(LLVMExtraMPMAddRemoveJuliaAddrspacesPass) \
YY(LLVMExtraMPMAddRemoveAddrspacesPass) \
YY(LLVMExtraMPMAddLowerPTLSPass) \
YY(LLVMExtraFPMAddDemoteFloat16Pass) \
YY(LLVMExtraFPMAddLateLowerGCPass) \
YY(LLVMExtraFPMAddAllocOptPass) \
YY(LLVMExtraFPMAddPropagateJuliaAddrspacesPass) \
YY(LLVMExtraFPMAddLowerExcHandlersPass) \
YY(LLVMExtraFPMAddGCInvariantVerifierPass) \
YY(LLVMExtraFPMAddFinalLowerGCPass) \
YY(LLVMExtraLPMAddJuliaLICMPass) \
YY(LLVMExtraLPMAddLowerSIMDLoopPass) \
YY(JLJITGetLLVMOrcExecutionSession) \
YY(JLJITGetJuliaOJIT) \
YY(JLJITGetExternalJITDylib) \
Expand Down
10 changes: 7 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4854,10 +4854,14 @@ f(x) = yt(x)
;; separate trycatch and tryfinally blocks earlier.
(mark-label catch)
(if finally
(begin (enter-finally-block catchcode #f) ;; enter block via exception
(begin (set! finally-handler last-finally-handler)
(set! catch-token-stack (cons handler-token catch-token-stack))
(compile (caddr e) break-labels #f #f) ;; enter block via exception
(emit '(call (top rethrow)))
(emit-return tail '(null)) ; unreachable
(set! catch-token-stack (cdr catch-token-stack))
(mark-label endl) ;; non-exceptional control flow enters here
(set! finally-handler last-finally-handler)
(compile (caddr e) break-labels #f #f)
(compile (renumber-assigned-ssavalues (caddr e)) break-labels #f #f)
;; emit actions to be taken at exit of finally
;; block, depending on the tag variable `finally`
(let loop ((actions (caddr my-finally-handler)))
Expand Down
Loading

0 comments on commit 3583114

Please sign in to comment.