Skip to content

Commit 393ee51

Browse files
authored
Merge branch 'master' into ib/active_manifest
2 parents 1054f9a + 3af9170 commit 393ee51

40 files changed

+452
-276
lines changed

Compiler/src/abstractinterpretation.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,11 +3457,8 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, ssta
34573457
return abstract_eval_static_parameter(interp, e, sv)
34583458
elseif ehead === :gc_preserve_begin || ehead === :aliasscope
34593459
return RTEffects(Any, Union{}, Effects(EFFECTS_TOTAL; consistent=ALWAYS_FALSE, effect_free=EFFECT_FREE_GLOBALLY))
3460-
elseif ehead === :gc_preserve_end || ehead === :leave || ehead === :pop_exception ||
3461-
ehead === :global || ehead === :popaliasscope
3460+
elseif ehead === :gc_preserve_end || ehead === :leave || ehead === :pop_exception || ehead === :popaliasscope
34623461
return RTEffects(Nothing, Union{}, Effects(EFFECTS_TOTAL; effect_free=EFFECT_FREE_GLOBALLY))
3463-
elseif ehead === :globaldecl
3464-
return RTEffects(Nothing, Any, EFFECTS_UNKNOWN)
34653462
elseif ehead === :thunk
34663463
return RTEffects(Any, Any, Effects())
34673464
end

Compiler/src/ssair/ir.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ function is_relevant_expr(e::Expr)
584584
:foreigncall, :isdefined, :copyast,
585585
:throw_undef_if_not,
586586
:cfunction, :method, :pop_exception,
587-
:leave, :globaldecl,
587+
:leave,
588588
:new_opaque_closure)
589589
end
590590

Compiler/src/ssair/verify.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if !isdefined(@__MODULE__, Symbol("@verify_error"))
2525
end
2626
end
2727

28-
is_toplevel_expr_head(head::Symbol) = head === :global || head === :method || head === :thunk
28+
is_toplevel_expr_head(head::Symbol) = head === :method || head === :thunk
2929
is_value_pos_expr_head(head::Symbol) = head === :static_parameter
3030
function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int, use_idx::Int, printed_use_idx::Int, print::Bool, isforeigncall::Bool, arg_idx::Int,
3131
allow_frontend_forms::Bool, @nospecialize(raise_error))

Compiler/src/validation.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const VALID_EXPR_HEADS = IdDict{Symbol,UnitRange{Int}}(
2020
:boundscheck => 0:1,
2121
:copyast => 1:1,
2222
:meta => 0:typemax(Int),
23-
:global => 1:1,
24-
:globaldecl => 1:2,
2523
:foreigncall => 5:typemax(Int), # name, RT, AT, nreq, (cconv, effects, gc_safe), args..., roots...
2624
:cfunction => 5:5,
2725
:isdefined => 1:2,
@@ -52,7 +50,6 @@ const SSAVALUETYPES_MISMATCH = "not all SSAValues in AST have a type in ssavalue
5250
const SSAVALUETYPES_MISMATCH_UNINFERRED = "uninferred CodeInfo ssavaluetypes field does not equal the number of present SSAValues"
5351
const SSAFLAGS_MISMATCH = "not all SSAValues have a corresponding `ssaflags`"
5452
const NON_TOP_LEVEL_METHOD = "encountered `Expr` head `:method` in non-top-level code (i.e. `nargs` > 0)"
55-
const NON_TOP_LEVEL_GLOBAL = "encountered `Expr` head `:global` in non-top-level code (i.e. `nargs` > 0)"
5653
const SIGNATURE_NARGS_MISMATCH = "method signature does not match number of method arguments"
5754
const SLOTNAMES_NARGS_MISMATCH = "CodeInfo for method contains fewer slotnames than the number of method arguments"
5855
const INVALID_SIGNATURE_OPAQUE_CLOSURE = "invalid signature of method for opaque closure - `sig` field must always be set to `Tuple`"
@@ -124,7 +121,6 @@ function validate_code!(errors::Vector{InvalidCodeError}, c::CodeInfo, is_top_le
124121
head = x.head
125122
if !is_top_level
126123
head === :method && push!(errors, InvalidCodeError(NON_TOP_LEVEL_METHOD))
127-
head === :global && push!(errors, InvalidCodeError(NON_TOP_LEVEL_GLOBAL))
128124
end
129125
narg_bounds = get(VALID_EXPR_HEADS, head, -1:-1)
130126
nargs = length(x.args)
@@ -149,7 +145,7 @@ function validate_code!(errors::Vector{InvalidCodeError}, c::CodeInfo, is_top_le
149145
head === :gc_preserve_end || head === :meta ||
150146
head === :inbounds || head === :foreigncall || head === :cfunction ||
151147
head === :leave || head === :pop_exception ||
152-
head === :method || head === :global || head === :static_parameter ||
148+
head === :method || head === :static_parameter ||
153149
head === :new || head === :splatnew || head === :thunk || head === :loopinfo ||
154150
head === :throw_undef_if_not || head === :code_coverage_effect || head === :inline || head === :noinline
155151
validate_val!(x)

Compiler/test/special_loading.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# Only run when testing Base compiler
44
if Base.identify_package("Compiler") === nothing
5-
mktempdir() do dir
5+
include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "test", "tempdepot.jl"))
6+
mkdepottempdir() do dir
67
withenv("JULIA_DEPOT_PATH" => dir * (Sys.iswindows() ? ";" : ":"), "JULIA_LOAD_PATH" => nothing) do
78
cd(joinpath(@__DIR__, "CompilerLoadingTest")) do
89
@test success(pipeline(`$(Base.julia_cmd()[1]) --startup-file=no --project=. compiler_loading_test.jl`; stdout, stderr))

base/docs/basedocs.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,17 @@ See also [`setpropertyonce!`](@ref Base.setpropertyonce!) and [`setglobal!`](@re
27582758
"""
27592759
setglobalonce!
27602760

2761+
"""
2762+
declare_global(module::Module, name::Symbol, strong::Bool=false, [ty::Type])
2763+
2764+
Declare the global `name` in module `module`. If `ty` is given, declares a
2765+
"strong" global, which cannot be replaced with a constant binding, otherwise
2766+
declares a weak global.
2767+
2768+
See also [`global`](@ref), [`setglobal!`](@ref), [`get_binding_type`](@ref Core.get_binding_type).
2769+
"""
2770+
Core.declare_global
2771+
27612772
"""
27622773
declare_const(module::Module, name::Symbol, [x])
27632774

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecial
18331833
Expr(:block,
18341834
LineNumberNode(Int(source.line), source.file),
18351835
Expr(:meta, :push_loc, file, :var"@generated body"),
1836-
Expr(:return, body),
1836+
Expr(:return, Expr(:toplevel_pure, body)),
18371837
Expr(:meta, :pop_loc))))
18381838
spnames = g.spnames
18391839
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),

base/file.jl

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ function mkpath(path::AbstractString; mode::Integer = 0o777)
253253
return path
254254
end
255255

256-
# Files that were requested to be deleted but can't be by the current process
257-
# i.e. loaded DLLs on Windows
258-
delayed_delete_dir() = joinpath(tempdir(), "julia_delayed_deletes")
256+
# Files that were requested to be deleted but can't be by the current process,
257+
# i.e. loaded DLLs on Windows, are listed in the directory below
258+
delayed_delete_ref() = joinpath(tempdir(), "julia_delayed_deletes_ref")
259259

260260
"""
261261
rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
@@ -288,13 +288,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false, allo
288288
force && err.code==Base.UV_ENOENT && return
289289
@static if Sys.iswindows()
290290
if allow_delayed_delete && err.code==Base.UV_EACCES && endswith(path, ".dll")
291-
# Loaded DLLs cannot be deleted on Windows, even with posix delete mode
292-
# but they can be moved. So move out to allow the dir to be deleted.
293-
# Pkg.gc() cleans up this dir when possible
294-
dir = mkpath(delayed_delete_dir())
295-
temp_path = tempname(dir, cleanup = false, suffix = string("_", basename(path)))
296-
@debug "Could not delete DLL most likely because it is loaded, moving to tempdir" path temp_path
297-
mv(path, temp_path)
291+
delayed_delete_dll(path)
298292
return
299293
end
300294
end
@@ -330,6 +324,22 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false, allo
330324
end
331325

332326

327+
# Loaded DLLs cannot be deleted on Windows, even with posix delete mode but they can be renamed.
328+
# delayed_delete_dll(path) does so temporarily, until later cleanup by Pkg.gc().
329+
function delayed_delete_dll(path)
330+
# in-use DLL must be kept on the same drive
331+
temp_path = tempname(abspath(dirname(path)); cleanup=false, suffix=string("_", basename(path)))
332+
@debug "Could not delete DLL most likely because it is loaded, moving to a temporary path" path temp_path
333+
mkpath(delayed_delete_ref())
334+
io = last(mktemp(delayed_delete_ref(); cleanup=false))
335+
try
336+
print(io, temp_path) # record the temporary path for Pkg.gc()
337+
finally
338+
close(io)
339+
end
340+
rename(path, temp_path) # do not call mv which could recursively call rm(path)
341+
end
342+
333343
# The following use Unix command line facilities
334344
function checkfor_mv_cp_cptree(src::AbstractString, dst::AbstractString, txt::AbstractString;
335345
force::Bool=false)
@@ -678,8 +688,35 @@ end
678688
# deprecated internal function used by some packages
679689
temp_cleanup_purge(; force=false) = force ? temp_cleanup_purge_all() : @lock TEMP_CLEANUP_LOCK temp_cleanup_purge_prelocked(false)
680690

691+
function temp_cleanup_postprocess(cleanup_dirs)
692+
if !isempty(cleanup_dirs)
693+
rmcmd = """
694+
cleanuplist = readlines(stdin) # This loop won't start running until stdin is closed, which is supposed to be sequenced after the process exits
695+
sleep(1) # Wait for the operating system to hopefully be ready, since the OS implementation is probably incorrect, given the history of buggy work-arounds like this that have existed for ages in dotNet and libuv
696+
for path in cleanuplist
697+
try
698+
rm(path, force=true, recursive=true)
699+
catch ex
700+
@warn "Failed to clean up temporary path \$(repr(path))\n\$ex" _group=:file
701+
end
702+
end
703+
"""
704+
cmd = Cmd(Base.cmd_gen(((Base.julia_cmd(),), ("--startup-file=no",), ("-e",), (rmcmd,))); ignorestatus = true, detach = true)
705+
pw = Base.PipeEndpoint()
706+
run(cmd, pw, devnull, stderr; wait=false)
707+
join(pw, cleanup_dirs, "\n")
708+
Base.dup(Base._fd(pw)) # intentionally leak a reference, until the process exits
709+
close(pw)
710+
end
711+
end
712+
713+
function temp_cleanup_atexit()
714+
temp_cleanup_purge_all()
715+
@lock TEMP_CLEANUP_LOCK temp_cleanup_postprocess(keys(TEMP_CLEANUP))
716+
end
717+
681718
function __postinit__()
682-
Base.atexit(temp_cleanup_purge_all)
719+
Base.atexit(temp_cleanup_atexit)
683720
end
684721

685722
const temp_prefix = "jl_"

base/rational.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fma(x::Rational, y::Rational, z::Rational) = x*y+z
443443

444444
function ==(x::AbstractFloat, q::Rational)
445445
if isfinite(x)
446-
(count_ones(q.den) == 1) & (ldexp(x, top_set_bit(q.den-1)) == q.num)
446+
(count_ones(q.den) == 1) && (ldexp(x, top_set_bit(q.den-1)) == q.num)
447447
else
448448
x == q.num/q.den
449449
end

base/subarray.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ Calling [`getindex`](@ref) or [`setindex!`](@ref) on the returned value
173173
(often a [`SubArray`](@ref)) computes the indices to access or modify the
174174
parent array on the fly. The behavior is undefined if the shape of the parent array is
175175
changed after `view` is called because there is no bound check for the parent array; e.g.,
176-
it may cause a segmentation fault.
176+
it may cause a segmentation fault. It is likewise undefined behavior to modify the `inds`
177+
array(s) after construction of the view.
177178
178179
Some immutable parent arrays (like ranges) may choose to simply
179180
recompute a new array in some circumstances instead of returning

0 commit comments

Comments
 (0)