Skip to content

Commit 3a5d040

Browse files
authored
Merge branch 'master' into iterate_reverse
2 parents 8f839d0 + b265dba commit 3a5d040

File tree

15 files changed

+66
-31
lines changed

15 files changed

+66
-31
lines changed

Compiler/src/abstractinterpretation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, ssta
34093409
elseif ehead === :cfunction
34103410
return abstract_eval_cfunction(interp, e, sstate, sv)
34113411
elseif ehead === :method
3412-
rt = (length(e.args) == 1) ? Any : Nothing
3412+
rt = (length(e.args) == 1) ? Any : Method
34133413
return RTEffects(rt, Any, EFFECTS_UNKNOWN)
34143414
elseif ehead === :copyast
34153415
return abstract_eval_copyast(interp, e, sstate, sv)

Compiler/src/optimize.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,16 @@ function optimize(interp::AbstractInterpreter, opt::OptimizationState, caller::I
988988
return nothing
989989
end
990990

991-
macro pass(name, expr)
991+
const ALL_PASS_NAMES = String[]
992+
macro pass(name::String, expr)
992993
optimize_until = esc(:optimize_until)
993994
stage = esc(:__stage__)
994-
macrocall = :(@timeit $(esc(name)) $(esc(expr)))
995+
macrocall = :(@timeit $name $(esc(expr)))
995996
macrocall.args[2] = __source__ # `@timeit` may want to use it
997+
push!(ALL_PASS_NAMES, name)
996998
quote
997999
$macrocall
998-
matchpass($optimize_until, ($stage += 1), $(esc(name))) && $(esc(:(@goto __done__)))
1000+
matchpass($optimize_until, ($stage += 1), $name) && $(esc(:(@goto __done__)))
9991001
end
10001002
end
10011003

@@ -1006,8 +1008,13 @@ matchpass(::Nothing, _, _) = false
10061008
function run_passes_ipo_safe(
10071009
ci::CodeInfo,
10081010
sv::OptimizationState,
1009-
optimize_until = nothing, # run all passes by default
1010-
)
1011+
optimize_until::Union{Nothing, Int, String} = nothing) # run all passes by default
1012+
if optimize_until isa String && !contains_is(ALL_PASS_NAMES, optimize_until)
1013+
error("invalid `optimize_until` argument, no such optimization pass")
1014+
elseif optimize_until isa Int && (optimize_until < 1 || optimize_until > length(ALL_PASS_NAMES))
1015+
error("invalid `optimize_until` argument, no such optimization pass")
1016+
end
1017+
10111018
__stage__ = 0 # used by @pass
10121019
# NOTE: The pass name MUST be unique for `optimize_until::String` to work
10131020
@pass "convert" ir = convert_to_ircode(ci, sv)

Compiler/src/typeinfer.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState, validation
127127
if inferred_result !== nothing
128128
uncompressed = inferred_result
129129
debuginfo = get_debuginfo(inferred_result)
130+
# Inlining may fast-path the global cache via `VolatileInferenceResult`, so store it back here
131+
result.src = inferred_result
130132
end
131133
# TODO: do we want to augment edges here with any :invoke targets that we got from inlining (such that we didn't have a direct edge to it already)?
132134
if inferred_result isa CodeInfo
133-
result.src = inferred_result
134135
if may_compress(interp)
135136
nslots = length(inferred_result.slotflags)
136137
resize!(inferred_result.slottypes::Vector{Any}, nslots)

Compiler/test/irpasses.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ function f_with_early_try_catch_exit()
14591459
result
14601460
end
14611461

1462-
let ir = first(only(Base.code_ircode(f_with_early_try_catch_exit, (); optimize_until="compact")))
1462+
let ir = first(only(Base.code_ircode(f_with_early_try_catch_exit, (); optimize_until="slot2reg")))
14631463
for i = 1:length(ir.stmts)
14641464
expr = ir.stmts[i][:stmt]
14651465
if isa(expr, PhiCNode)

Compiler/test/ssair.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,3 +821,6 @@ let cl = Int32[32, 1, 1, 1000, 240, 230]
821821
cl2 = ccall(:jl_uncompress_codelocs, Any, (Any, Int), str, 2)
822822
@test cl == cl2
823823
end
824+
825+
@test_throws ErrorException Base.code_ircode(+, (Float64, Float64); optimize_until = "nonexisting pass name")
826+
@test_throws ErrorException Base.code_ircode(+, (Float64, Float64); optimize_until = typemax(Int))

base/arraymath.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ _reverse!(A::AbstractArray{<:Any,N}, ::Colon) where {N} = _reverse!(A, ntuple(id
7272
_reverse!(A, dim::Integer) = _reverse!(A, (Int(dim),))
7373
_reverse!(A, dims::NTuple{M,Integer}) where {M} = _reverse!(A, Int.(dims))
7474
function _reverse!(A::AbstractArray{<:Any,N}, dims::NTuple{M,Int}) where {N,M}
75+
dims === () && return A # nothing to reverse
7576
dimrev = ntuple(k -> k in dims, Val{N}()) # boolean tuple indicating reversed dims
7677

7778
if N < M || M != sum(dimrev)
7879
throw(ArgumentError("invalid dimensions $dims in reverse!"))
7980
end
80-
M == 0 && return A # nothing to reverse
8181

8282
# swapping loop only needs to traverse ≈half of the array
8383
halfsz = ntuple(k -> k == dims[1] ? size(A,k) ÷ 2 : size(A,k), Val{N}())

base/libdl.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Libdl
55
Interface to libdl. Provides dynamic linking support.
66
""" Libdl
77

8-
import Base.DL_LOAD_PATH
8+
import Base: DL_LOAD_PATH, isdebugbuild
99

1010
export DL_LOAD_PATH, RTLD_DEEPBIND, RTLD_FIRST, RTLD_GLOBAL, RTLD_LAZY, RTLD_LOCAL,
1111
RTLD_NODELETE, RTLD_NOLOAD, RTLD_NOW, dlclose, dlopen, dlopen_e, dlsym, dlsym_e,
@@ -341,7 +341,8 @@ Base.print(io::IO, llp::LazyLibraryPath) = print(io, string(llp))
341341
# Helper to get `$(private_shlibdir)` at runtime
342342
struct PrivateShlibdirGetter; end
343343
const private_shlibdir = Base.OncePerProcess{String}() do
344-
dirname(dlpath("libjulia-internal"))
344+
libname = ifelse(isdebugbuild(), "libjulia-internal-debug", "libjulia-internal")
345+
dirname(dlpath(libname))
345346
end
346347
Base.string(::PrivateShlibdirGetter) = private_shlibdir()
347348

base/linking.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22
module Linking
33

4+
import Base: isdebugbuild
45
import Base.Libc: Libdl
56

67
# from LLD_jll
@@ -123,7 +124,6 @@ else
123124
"-shared"
124125
end
125126

126-
is_debug() = ccall(:jl_is_debugbuild, Cint, ()) == 1
127127
libdir() = abspath(Sys.BINDIR, Base.LIBDIR)
128128
private_libdir() = abspath(Sys.BINDIR, Base.PRIVATE_LIBDIR)
129129
if Sys.iswindows()
@@ -137,7 +137,7 @@ verbose_linking() = something(Base.get_bool_env("JULIA_VERBOSE_LINKING", false),
137137
function link_image_cmd(path, out)
138138
PRIVATE_LIBDIR = "-L$(private_libdir())"
139139
SHLIBDIR = "-L$(shlibdir())"
140-
LIBS = is_debug() ? ("-ljulia-debug", "-ljulia-internal-debug") :
140+
LIBS = isdebugbuild() ? ("-ljulia-debug", "-ljulia-internal-debug") :
141141
("-ljulia", "-ljulia-internal")
142142
@static if Sys.iswindows()
143143
LIBS = (LIBS..., "-lopenlibm", "-lssp", "-lgcc_s", "-lgcc", "-lmsvcrt")

base/reshapedarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function _reshape(parent::AbstractArray, dims::Dims)
225225
end
226226

227227
@noinline function _throw_dmrs(n, str, dims)
228-
throw(DimensionMismatch("parent has $n elements, which is incompatible with $str $dims"))
228+
throw(DimensionMismatch("parent has $n elements, which is incompatible with $str $dims ($(prod(dims)) elements)"))
229229
end
230230

231231
# Reshaping a ReshapedArray

src/interpreter.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ static jl_value_t *eval_methoddef(jl_expr_t *ex, interpreter_state *s)
106106
}
107107
atypes = eval_value(args[1], s);
108108
meth = eval_value(args[2], s);
109-
jl_method_def((jl_svec_t*)atypes, mt, (jl_code_info_t*)meth, s->module);
109+
jl_method_t *ret = jl_method_def((jl_svec_t*)atypes, mt, (jl_code_info_t*)meth, s->module);
110110
JL_GC_POP();
111-
return jl_nothing;
111+
return (jl_value_t *)ret;
112112
}
113113

114114
// expression evaluator
@@ -626,7 +626,8 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip,
626626
}
627627
else if (toplevel) {
628628
if (head == jl_method_sym && jl_expr_nargs(stmt) > 1) {
629-
eval_methoddef((jl_expr_t*)stmt, s);
629+
jl_value_t *res = eval_methoddef((jl_expr_t*)stmt, s);
630+
s->locals[jl_source_nslots(s->src) + s->ip] = res;
630631
}
631632
else if (head == jl_toplevel_sym) {
632633
jl_value_t *res = jl_toplevel_eval(s->module, stmt);

0 commit comments

Comments
 (0)