Skip to content

Commit a7a5453

Browse files
authored
Merge pull request #47602 from JuliaLang/backports-release-1.9
release-1.9: Backports for julia 1.9.0-beta1
2 parents 0540f9d + 6adc428 commit a7a5453

File tree

173 files changed

+8146
-6129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+8146
-6129
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
.DS_Store
3434
.idea/*
3535
.vscode/*
36-
36+
*.heapsnapshot
3737
# Buildkite: Ignore the entire .buildkite directory
3838
/.buildkite
3939

Make.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ JULIA_THREADS := 1
7777
# Set to 1 to enable profiling with OProfile
7878
USE_OPROFILE_JITEVENTS ?= 0
7979

80-
# USE_PERF_JITEVENTS defined below since default is OS specific
80+
# USE_PERF_JITEVENTS, and USE_INTEL_JITEVENTS defined below since default is OS specific
8181

8282
# assume we don't have LIBSSP support in our compiler, will enable later if likely true
8383
HAVE_SSP := 0
@@ -442,8 +442,10 @@ endif
442442
# Set to 1 to enable profiling with perf
443443
ifeq ("$(OS)", "Linux")
444444
USE_PERF_JITEVENTS ?= 1
445+
USE_INTEL_JITEVENTS ?= 1
445446
else
446447
USE_PERF_JITEVENTS ?= 0
448+
USE_INTEL_JITEVENTS ?= 0
447449
endif
448450

449451
JULIACODEGEN := LLVM

Makefile

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ all: debug release
1111
# sort is used to remove potential duplicates
1212
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/stdlib $(build_man1dir))
1313
ifneq ($(BUILDROOT),$(JULIAHOME))
14-
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa cli doc deps stdlib test test/clangsa test/embedding test/llvmpasses)
14+
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa cli doc deps stdlib test test/clangsa test/embedding test/gcext test/llvmpasses)
1515
BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) $(BUILDROOT)/sysimage.mk
1616
DIRS := $(DIRS) $(BUILDDIRS)
1717
$(BUILDDIRMAKE): | $(BUILDDIRS)
@@ -247,13 +247,21 @@ ifeq ($(OS),WINNT)
247247
-$(INSTALL_M) $(wildcard $(build_bindir)/*.dll) $(DESTDIR)$(bindir)/
248248
ifeq ($(JULIA_BUILD_MODE),release)
249249
-$(INSTALL_M) $(build_libdir)/libjulia.dll.a $(DESTDIR)$(libdir)/
250+
-$(INSTALL_M) $(build_libdir)/libjulia-internal.dll.a $(DESTDIR)$(libdir)/
250251
else ifeq ($(JULIA_BUILD_MODE),debug)
251252
-$(INSTALL_M) $(build_libdir)/libjulia-debug.dll.a $(DESTDIR)$(libdir)/
253+
-$(INSTALL_M) $(build_libdir)/libjulia-internal-debug.dll.a $(DESTDIR)$(libdir)/
252254
endif
253255

254256
# We have a single exception; we want 7z.dll to live in libexec, not bin, so that 7z.exe can find it.
255257
-mv $(DESTDIR)$(bindir)/7z.dll $(DESTDIR)$(libexecdir)/
256258
-$(INSTALL_M) $(build_bindir)/libopenlibm.dll.a $(DESTDIR)$(libdir)/
259+
-$(INSTALL_M) $(build_libdir)/libssp.dll.a $(DESTDIR)$(libdir)/
260+
# The rest are compiler dependencies, as an example memcpy is exported by msvcrt
261+
# These are files from mingw32 and required for creating shared libraries like our caches.
262+
-$(INSTALL_M) $(build_libdir)/libgcc_s.a $(DESTDIR)$(libdir)/
263+
-$(INSTALL_M) $(build_libdir)/libgcc.a $(DESTDIR)$(libdir)/
264+
-$(INSTALL_M) $(build_libdir)/libmsvcrt.a $(DESTDIR)$(libdir)/
257265
else
258266

259267
# Copy over .dSYM directories directly for Darwin
@@ -318,6 +326,11 @@ else ifeq ($(JULIA_BUILD_MODE),debug)
318326
$(INSTALL_M) $(build_private_libdir)/sys-debug.$(SHLIB_EXT) $(DESTDIR)$(private_libdir)
319327
endif
320328

329+
# Cache stdlibs
330+
@$(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --startup-file=no $(JULIAHOME)/contrib/cache_stdlibs.jl)
331+
# CI uses `--check-bounds=yes` which impacts the cache flags
332+
@$(call PRINT_JULIA, $(call spawn,$(JULIA_EXECUTABLE)) --startup-file=no --check-bounds=yes $(JULIAHOME)/contrib/cache_stdlibs.jl)
333+
321334
# Copy in all .jl sources as well
322335
mkdir -p $(DESTDIR)$(datarootdir)/julia/base $(DESTDIR)$(datarootdir)/julia/test
323336
cp -R -L $(JULIAHOME)/base/* $(DESTDIR)$(datarootdir)/julia/base
@@ -371,8 +384,18 @@ endif
371384
fi;
372385
endif
373386

374-
# Set rpath for libjulia-internal, which is moving from `../lib` to `../lib/julia`. We only need to do this for Linux/FreeBSD
375-
ifneq (,$(findstring $(OS),Linux FreeBSD))
387+
# Set rpath for libjulia-internal, which is moving from `../lib` to `../lib/julia`.
388+
ifeq ($(OS), Darwin)
389+
ifneq ($(DARWIN_FRAMEWORK),1)
390+
ifeq ($(JULIA_BUILD_MODE),release)
391+
install_name_tool -add_rpath @loader_path/$(reverse_private_libdir_rel)/ $(DESTDIR)$(private_libdir)/libjulia-internal.$(SHLIB_EXT)
392+
install_name_tool -add_rpath @loader_path/$(reverse_private_libdir_rel)/ $(DESTDIR)$(private_libdir)/libjulia-codegen.$(SHLIB_EXT)
393+
else ifeq ($(JULIA_BUILD_MODE),debug)
394+
install_name_tool -add_rpath @loader_path/$(reverse_private_libdir_rel)/ $(DESTDIR)$(private_libdir)/libjulia-internal-debug.$(SHLIB_EXT)
395+
install_name_tool -add_rpath @loader_path/$(reverse_private_libdir_rel)/ $(DESTDIR)$(private_libdir)/libjulia-codegen-debug.$(SHLIB_EXT)
396+
endif
397+
endif
398+
else ifneq (,$(findstring $(OS),Linux FreeBSD))
376399
ifeq ($(JULIA_BUILD_MODE),release)
377400
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal.$(SHLIB_EXT)
378401
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-codegen.$(SHLIB_EXT)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Standard library changes
9898

9999
#### Package Manager
100100

101+
- "Package Extensions": support for loading a piece of code based on other
102+
packages being loaded in the Julia session.
103+
This has similar applications as the Requires.jl package but also
104+
supports precompilation and setting compatibility.
101105
#### LinearAlgebra
102106

103107
* The methods `a / b` and `b \ a` with `a` a scalar and `b` a vector, which were equivalent to `a * pinv(b)`,

base/Base.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ include("idset.jl")
168168
include("iterators.jl")
169169
using .Iterators: zip, enumerate, only
170170
using .Iterators: Flatten, Filter, product # for generators
171+
using .Iterators: Stateful # compat (was formerly used in reinterpretarray.jl)
171172

172173
include("namedtuple.jl")
173174

@@ -417,6 +418,7 @@ include("threadcall.jl")
417418
include("uuid.jl")
418419
include("pkgid.jl")
419420
include("toml_parser.jl")
421+
include("linking.jl")
420422
include("loading.jl")
421423

422424
# misc useful functions & macros

base/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ ifeq ($(DARWIN_FRAMEWORK), 1)
8181
@echo "const DARWIN_FRAMEWORK_NAME = \"$(FRAMEWORK_NAME)\"" >> $@
8282
else
8383
@echo "const DARWIN_FRAMEWORK = false" >> $@
84+
endif
85+
ifeq ($(OS), Darwin)
86+
@echo "const MACOS_PRODUCT_VERSION = \"$(shell sw_vers -productVersion)\"" >> $@
87+
@echo "const MACOS_PLATFORM_VERSION = \"$(shell xcrun --show-sdk-version)\"" >> $@
8488
endif
8589
@echo "const BUILD_TRIPLET = \"$(BB_TRIPLET_LIBGFORTRAN_CXXABI)\"" >> $@
8690

@@ -227,6 +231,8 @@ else
227231
$(eval $(call symlink_system_library,CSL,libgcc_s,1))
228232
endif
229233
endif
234+
else
235+
$(eval $(call symlink_system_library,CSL,libgcc_s,1))
230236
endif
231237
ifneq (,$(LIBGFORTRAN_VERSION))
232238
$(eval $(call symlink_system_library,CSL,libgfortran,$(LIBGFORTRAN_VERSION)))

base/array.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,8 @@ keepat!(a::Vector, m::AbstractVector{Bool}) = _keepat!(a, m)
27302730
# set-like operators for vectors
27312731
# These are moderately efficient, preserve order, and remove dupes.
27322732

2733-
_unique_filter!(pred, update!, state) = function (x)
2733+
_unique_filter!(pred::P, update!::U, state) where {P,U} = function (x)
2734+
# P, U force specialization
27342735
if pred(x, state)
27352736
update!(state, x)
27362737
true
@@ -2756,7 +2757,7 @@ union!(v::AbstractVector{T}, itrs...) where {T} =
27562757
symdiff!(v::AbstractVector{T}, itrs...) where {T} =
27572758
_grow!(_shrink_filter!(symdiff!(Set{T}(), v, itrs...)), v, itrs)
27582759

2759-
function _shrink!(shrinker!, v::AbstractVector, itrs)
2760+
function _shrink!(shrinker!::F, v::AbstractVector, itrs) where F
27602761
seen = Set{eltype(v)}()
27612762
filter!(_grow_filter!(seen), v)
27622763
shrinker!(seen, itrs...)
@@ -2768,7 +2769,7 @@ setdiff!( v::AbstractVector, itrs...) = _shrink!(setdiff!, v, itrs)
27682769

27692770
vectorfilter(T::Type, f, v) = T[x for x in v if f(x)]
27702771

2771-
function _shrink(shrinker!, itr, itrs)
2772+
function _shrink(shrinker!::F, itr, itrs) where F
27722773
T = promote_eltype(itr, itrs...)
27732774
keep = shrinker!(Set{T}(itr), itrs...)
27742775
vectorfilter(T, _shrink_filter!(keep), itr)

base/boot.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,19 @@ Array{T}(A::AbstractArray{S,N}) where {T,N,S} = Array{T,N}(A)
503503
AbstractArray{T}(A::AbstractArray{S,N}) where {T,S,N} = AbstractArray{T,N}(A)
504504

505505
# primitive Symbol constructors
506+
507+
## Helper for proper GC rooting without unsafe_convert
508+
eval(Core, quote
509+
_Symbol(ptr::Ptr{UInt8}, sz::Int, root::Any) = $(Expr(:foreigncall, QuoteNode(:jl_symbol_n),
510+
Ref{Symbol}, svec(Ptr{UInt8}, Int), 0, QuoteNode(:ccall), :ptr, :sz, :root))
511+
end)
512+
506513
function Symbol(s::String)
507514
@_foldable_meta
508-
return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int),
509-
ccall(:jl_string_ptr, Ptr{UInt8}, (Any,), s),
510-
sizeof(s))
515+
return _Symbol(ccall(:jl_string_ptr, Ptr{UInt8}, (Any,), s), sizeof(s), s)
511516
end
512517
function Symbol(a::Array{UInt8,1})
513-
return ccall(:jl_symbol_n, Ref{Symbol}, (Ptr{UInt8}, Int),
514-
ccall(:jl_array_ptr, Ptr{UInt8}, (Any,), a),
515-
Intrinsics.arraylen(a))
518+
return _Symbol(ccall(:jl_array_ptr, Ptr{UInt8}, (Any,), a), Intrinsics.arraylen(a), a)
516519
end
517520
Symbol(s::Symbol) = s
518521

@@ -617,8 +620,7 @@ end
617620

618621
NamedTuple() = NamedTuple{(),Tuple{}}(())
619622

620-
eval(Core, :(NamedTuple{names}(args::Tuple) where {names} =
621-
$(Expr(:splatnew, :(NamedTuple{names,typeof(args)}), :args))))
623+
NamedTuple{names}(args::Tuple) where {names} = NamedTuple{names,typeof(args)}(args)
622624

623625
using .Intrinsics: sle_int, add_int
624626

base/compiler/abstractinterpretation.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,16 +2180,16 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
21802180
elseif ehead === :splatnew
21812181
t, isexact = instanceof_tfunc(abstract_eval_value(interp, e.args[1], vtypes, sv))
21822182
nothrow = false # TODO: More precision
2183-
if length(e.args) == 2 && isconcretedispatch(t) && !ismutabletype(t)
2183+
if length(e.args) == 2 && isconcretetype(t) && !ismutabletype(t)
21842184
at = abstract_eval_value(interp, e.args[2], vtypes, sv)
21852185
n = fieldcount(t)
21862186
if isa(at, Const) && isa(at.val, Tuple) && n == length(at.val::Tuple) &&
2187-
let t = t, at = at; all(i::Int->getfield(at.val::Tuple, i) isa fieldtype(t, i), 1:n); end
2188-
nothrow = isexact
2187+
let t = t, at = at; _all(i->getfield(at.val::Tuple, i) isa fieldtype(t, i), 1:n); end
2188+
nothrow = isexact && isconcretedispatch(t)
21892189
t = Const(ccall(:jl_new_structt, Any, (Any, Any), t, at.val))
2190-
elseif isa(at, PartialStruct) && at Tuple && n == length(at.fields::Vector{Any}) &&
2191-
let t = t, at = at; all(i::Int->(at.fields::Vector{Any})[i] fieldtype(t, i), 1:n); end
2192-
nothrow = isexact
2190+
elseif isa(at, PartialStruct) && at Tuple && n == length(at.fields::Vector{Any}) &&
2191+
let t = t, at = at; _all(i->(at.fields::Vector{Any})[i] fieldtype(t, i), 1:n); end
2192+
nothrow = isexact && isconcretedispatch(t)
21932193
t = PartialStruct(t, at.fields::Vector{Any})
21942194
end
21952195
end

base/compiler/ssair/passes.jl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,6 @@ function lift_leaves(compact::IncrementalCompact,
401401
end
402402
lift_arg!(compact, leaf, cache_key, def, 1+field, lifted_leaves)
403403
continue
404-
# NOTE we can enable this, but most `:splatnew` expressions are transformed into
405-
# `:new` expressions by the inlinear
406-
# elseif isexpr(def, :splatnew) && length(def.args) == 2 && isa(def.args[2], AnySSAValue)
407-
# tplssa = def.args[2]::AnySSAValue
408-
# tplexpr = compact[tplssa][:inst]
409-
# if is_known_call(tplexpr, tuple, compact) && 1 ≤ field < length(tplexpr.args)
410-
# lift_arg!(compact, tplssa, cache_key, tplexpr, 1+field, lifted_leaves)
411-
# continue
412-
# end
413-
# return nothing
414404
elseif is_getfield_captures(def, compact)
415405
# Walk to new_opaque_closure
416406
ocleaf = def.args[2]
@@ -479,7 +469,7 @@ function lift_arg!(
479469
end
480470
end
481471
lifted_leaves[cache_key] = LiftedValue(lifted)
482-
return nothing
472+
nothing
483473
end
484474

485475
function walk_to_def(compact::IncrementalCompact, @nospecialize(leaf))

base/compiler/tfuncs.jl

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,11 @@ add_tfunc(Core.sizeof, 1, 1, sizeof_tfunc, 1)
407407
function nfields_tfunc(@nospecialize(x))
408408
isa(x, Const) && return Const(nfields(x.val))
409409
isa(x, Conditional) && return Const(0)
410-
xt = widenconst(x)
411-
x = unwrap_unionall(xt)
410+
x = unwrap_unionall(widenconst(x))
412411
isconstType(x) && return Const(nfields(x.parameters[1]))
413412
if isa(x, DataType) && !isabstracttype(x)
414-
if x.name === Tuple.name
415-
isvatuple(x) && return Int
416-
return Const(length(x.types))
417-
elseif x.name === _NAMEDTUPLE_NAME
418-
length(x.parameters) == 2 || return Int
419-
names = x.parameters[1]
420-
isa(names, Tuple{Vararg{Symbol}}) || return nfields_tfunc(rewrap_unionall(x.parameters[2], xt))
421-
return Const(length(names))
422-
else
413+
if !(x.name === Tuple.name && isvatuple(x)) &&
414+
!(x.name === _NAMEDTUPLE_NAME && !isconcretetype(x))
423415
return Const(isdefined(x, :types) ? length(x.types) : length(x.name.names))
424416
end
425417
end
@@ -1660,12 +1652,6 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
16601652
end
16611653
if istuple
16621654
return Type{<:appl}
1663-
elseif isa(appl, DataType) && appl.name === _NAMEDTUPLE_NAME && length(appl.parameters) == 2 &&
1664-
(appl.parameters[1] === () || appl.parameters[2] === Tuple{})
1665-
# if the first/second parameter of `NamedTuple` is known to be empty,
1666-
# the second/first argument should also be empty tuple type,
1667-
# so refine it here
1668-
return Const(NamedTuple{(),Tuple{}})
16691655
end
16701656
ans = Type{appl}
16711657
for i = length(outervars):-1:1

base/compiler/typeinfer.jl

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

3-
# Tracking of newly-inferred MethodInstances during precompilation
3+
# Tracking of newly-inferred CodeInstances during precompilation
44
const track_newly_inferred = RefValue{Bool}(false)
5-
const newly_inferred = MethodInstance[]
5+
const newly_inferred = CodeInstance[]
66

77
# build (and start inferring) the inference frame for the top-level MethodInstance
88
function typeinf(interp::AbstractInterpreter, result::InferenceResult, cache::Symbol)
@@ -344,7 +344,7 @@ function maybe_compress_codeinfo(interp::AbstractInterpreter, linfo::MethodInsta
344344
return ci
345345
end
346346
if may_discard_trees(interp)
347-
cache_the_tree = ci.inferred && (is_inlineable(ci) || isa_compileable_sig(linfo.specTypes, def))
347+
cache_the_tree = ci.inferred && (is_inlineable(ci) || isa_compileable_sig(linfo.specTypes, linfo.sparam_vals, def))
348348
else
349349
cache_the_tree = true
350350
end
@@ -400,13 +400,11 @@ function cache_result!(interp::AbstractInterpreter, result::InferenceResult)
400400
# TODO: also don't store inferred code if we've previously decided to interpret this function
401401
if !already_inferred
402402
inferred_result = transform_result_for_cache(interp, linfo, valid_worlds, result)
403-
code_cache(interp)[linfo] = CodeInstance(result, inferred_result, valid_worlds)
403+
code_cache(interp)[linfo] = ci = CodeInstance(result, inferred_result, valid_worlds)
404404
if track_newly_inferred[]
405405
m = linfo.def
406406
if isa(m, Method) && m.module != Core
407-
ccall(:jl_typeinf_lock_begin, Cvoid, ())
408-
push!(newly_inferred, linfo)
409-
ccall(:jl_typeinf_lock_end, Cvoid, ())
407+
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
410408
end
411409
end
412410
end

base/compiler/utilities.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ function get_compileable_sig(method::Method, @nospecialize(atype), sparams::Simp
152152
mt, atype, sparams, method)
153153
end
154154

155-
isa_compileable_sig(@nospecialize(atype), method::Method) =
156-
!iszero(ccall(:jl_isa_compileable_sig, Int32, (Any, Any), atype, method))
155+
isa_compileable_sig(@nospecialize(atype), sparams::SimpleVector, method::Method) =
156+
!iszero(ccall(:jl_isa_compileable_sig, Int32, (Any, Any, Any), atype, sparams, method))
157157

158158
# eliminate UnionAll vars that might be degenerate due to having identical bounds,
159159
# or a concrete upper bound and appearing covariantly.
@@ -200,7 +200,12 @@ function specialize_method(method::Method, @nospecialize(atype), sparams::Simple
200200
if compilesig
201201
new_atype = get_compileable_sig(method, atype, sparams)
202202
new_atype === nothing && return nothing
203-
atype = new_atype
203+
if atype !== new_atype
204+
sp_ = ccall(:jl_type_intersection_with_env, Any, (Any, Any), new_atype, method.sig)::SimpleVector
205+
if sparams === sp_[2]::SimpleVector
206+
atype = new_atype
207+
end
208+
end
204209
end
205210
if preexisting
206211
# check cached specializations

base/file.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
294294
rm(joinpath(path, p), force=force, recursive=true)
295295
end
296296
catch err
297-
if !(force && isa(err, IOError) && err.code==Base.UV_EACCES)
297+
if !(isa(err, IOError) && err.code==Base.UV_EACCES)
298298
rethrow(err)
299299
end
300300
end

0 commit comments

Comments
 (0)