Skip to content

Commit

Permalink
Merge branch 'master' into cjf/juliasyntax-stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith authored Jun 19, 2023
2 parents fde8692 + 690a5f6 commit d8a4810
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ function abstract_apply(interp::AbstractInterpreter, argtypes::Vector{Any}, si::
call = abstract_call(interp, ArgInfo(nothing, ct), si, sv, max_methods)
seen += 1
push!(retinfos, ApplyCallInfo(call.info, arginfo))
res = tmerge(res, call.rt)
res = tmerge(typeinf_lattice(interp), res, call.rt)
effects = merge_effects(effects, call.effects)
if bail_out_apply(interp, InferenceLoopState(ct, res, effects), sv)
add_remark!(interp, sv, "_apply_iterate inference reached maximally imprecise information. Bailing on.")
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function tmerge(lattice::OptimizerLattice, @nospecialize(typea), @nospecialize(t

# type-lattice for MaybeUndef wrapper
if isa(typea, MaybeUndef) || isa(typeb, MaybeUndef)
return MaybeUndef(tmerge(
return MaybeUndef(tmerge(widenlattice(lattice),
isa(typea, MaybeUndef) ? typea.typ : typea,
isa(typeb, MaybeUndef) ? typeb.typ : typeb))
end
Expand Down
8 changes: 6 additions & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function showerror(io::IO, ex::MethodError)
ft = typeof(f)
arg_types_param = arg_types_param[3:end]
kwargs = pairs(ex.args[1])
ex = MethodError(f, ex.args[3:end::Int])
ex = MethodError(f, ex.args[3:end::Int], ex.world)
end
name = ft.name.mt.name
if f === Base.convert && length(arg_types_param) == 2 && !is_arg_types
Expand Down Expand Up @@ -497,7 +497,11 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
if !((min(length(t_i), length(sig)) == 0) && k==1)
print(iob, ", ")
end
if get(io, :color, false)::Bool
if k == 1 && Base.isvarargtype(sigtype)
# There wasn't actually a mismatch - the method match failed for
# some other reason, e.g. world age. Just print the sigstr.
print(iob, sigstr...)
elseif get(io, :color, false)::Bool
let sigstr=sigstr
Base.with_output_color(Base.error_color(), iob) do iob
print(iob, "::", sigstr...)
Expand Down
19 changes: 14 additions & 5 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2819,11 +2819,20 @@ global mkpidlock_hook
global trymkpidlock_hook
global parse_pidfile_hook

# allows processes to wait if another process is precompiling a given source already
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String)
# The preferences hash is only known after precompilation so just assume no preferences
# meaning that if all other conditions are equal, the same package cannot be precompiled
# with different preferences at the same time.
compilecache_pidfile_path(pkg::PkgId) = compilecache_path(pkg, UInt64(0)) * ".pidfile"

# Allows processes to wait if another process is precompiling a given source already.
# The lock file is deleted and precompilation will proceed after `stale_age` seconds if
# - the locking process no longer exists
# - the lock is held by another host, since processes cannot be checked remotely
# or after `stale_age * 25` seconds if it does still exist.
function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=60)
if @isdefined(mkpidlock_hook) && @isdefined(trymkpidlock_hook) && @isdefined(parse_pidfile_hook)
pidfile = string(srcpath, ".pidlock")
cachefile = invokelatest(trymkpidlock_hook, f, pidfile)
pidfile = compilecache_pidfile_path(pkg)
cachefile = invokelatest(trymkpidlock_hook, f, pidfile; stale_age)
if cachefile === false
pid, hostname, age = invokelatest(parse_pidfile_hook, pidfile)
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
Expand All @@ -2834,7 +2843,7 @@ function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String)
end
# wait until the lock is available, but don't actually acquire it
# returning nothing indicates a process waited for another
return invokelatest(mkpidlock_hook, Returns(nothing), pidfile)
return invokelatest(mkpidlock_hook, Returns(nothing), pidfile; stale_age)
end
return cachefile
else
Expand Down
3 changes: 3 additions & 0 deletions doc/src/devdocs/sysimg.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ All features supported by LLVM are supported and a feature can be disabled with
(`+` prefix is also allowed and ignored to be consistent with LLVM syntax).
Additionally, a few special features are supported to control the function cloning behavior.

!!! note
It is good practice to specify either `clone_all` or `base(<n>)` for every target apart from the first one. This makes it explicit which targets have all functions cloned, and which targets are based on other targets. If this is not done, the default behavior is to not clone every function, and to use the first target's function definition as the fallback when not cloning a function.

1. `clone_all`

By default, only functions that are the most likely to benefit from
Expand Down
3 changes: 3 additions & 0 deletions src/codegen-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ JL_DLLEXPORT uint64_t jl_getUnwindInfo_fallback(uint64_t dwAddr)

JL_DLLEXPORT void jl_add_optimization_passes_fallback(void *PM, int opt_level, int lower_intrinsics) UNAVAILABLE

JL_DLLEXPORT void jl_build_newpm_pipeline_fallback(void *MPM, void *PB, int Speedup, int Size,
int lower_intrinsics, int dump_native, int external_use, int llvm_only) UNAVAILABLE

JL_DLLEXPORT void LLVMExtraAddLowerSimdLoopPass_fallback(void *PM) UNAVAILABLE

JL_DLLEXPORT void LLVMExtraAddFinalLowerGCPass_fallback(void *PM) UNAVAILABLE
Expand Down
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
YY(jl_getUnwindInfo) \
YY(jl_get_libllvm) \
YY(jl_add_optimization_passes) \
YY(jl_build_newpm_pipeline) \
YY(LLVMExtraAddLowerSimdLoopPass) \
YY(LLVMExtraAddFinalLowerGCPass) \
YY(LLVMExtraAddPropagateJuliaAddrspaces) \
Expand Down
31 changes: 31 additions & 0 deletions src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,37 @@ static void buildPipeline(ModulePassManager &MPM, PassBuilder *PB, OptimizationL
MPM.addPass(AfterOptimizationMarkerPass());
}

extern "C" JL_DLLEXPORT_CODEGEN void jl_build_newpm_pipeline_impl(void *MPM, void *PB, int Speedup, int Size,
int lower_intrinsics, int dump_native, int external_use, int llvm_only) JL_NOTSAFEPOINT
{
OptimizationLevel O;
switch (Size) {
case 1:
O = OptimizationLevel::Os;
break;
default:
O = OptimizationLevel::Oz;
break;
case 0:
switch (Speedup) {
case 0:
O = OptimizationLevel::O0;
break;
case 1:
O = OptimizationLevel::O1;
break;
case 2:
O = OptimizationLevel::O2;
break;
default:
O = OptimizationLevel::O3;
break;
}
}
buildPipeline(*reinterpret_cast<ModulePassManager*>(MPM), reinterpret_cast<PassBuilder*>(PB), O,
OptimizationOptions{!!lower_intrinsics, !!dump_native, !!external_use, !!llvm_only});
}

#undef JULIA_PASS

namespace {
Expand Down
28 changes: 27 additions & 1 deletion test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ let
end
end

@testset "show for manually thrown MethodError" begin
@testset "show for MethodError with world age issue" begin
global f21006

f21006() = nothing
Expand Down Expand Up @@ -620,6 +620,32 @@ end
end
end

# Issue #50200
using Base.Experimental: @opaque
@testset "show for MethodError with world age issue (kwarg)" begin
test_no_error(f) = @test f() === nothing
function test_worldage_error(f)
ex = try; f(); error("Should not have been reached") catch ex; ex; end
@test occursin("The applicable method may be too new", sprint(Base.showerror, ex))
@test !occursin("!Matched::", sprint(Base.showerror, ex))
end

global callback50200

# First the no-kwargs version
callback50200 = (args...)->nothing
f = @opaque ()->callback50200()
test_no_error(f)
callback50200 = (args...)->nothing
test_worldage_error(f)

callback50200 = (args...; kwargs...)->nothing
f = @opaque ()->callback50200(;a=1)
test_no_error(f)
callback50200 = (args...; kwargs...)->nothing
test_worldage_error(f)
end

# Custom hints
struct HasNoOne end
function recommend_oneunit(io, ex, arg_types, kwargs)
Expand Down

0 comments on commit d8a4810

Please sign in to comment.