Skip to content

Commit 46ba16a

Browse files
authored
Merge pull request #46376 from JuliaLang/backports-release-1.8
release-1.8: Backports for Julia 1.8.1
2 parents 5544a0f + 173f336 commit 46ba16a

Some content is hidden

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

54 files changed

+552
-236
lines changed

Make.inc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,9 @@ else
12251225
NO_WHOLE_ARCHIVE := -Wl,--no-whole-archive
12261226
endif
12271227

1228+
# Initialize these once, then add to them in OS-specific blocks
1229+
JLIBLDFLAGS :=
1230+
12281231
ifeq ($(OS), Linux)
12291232
OSLIBS += -Wl,--no-as-needed -ldl -lrt -lpthread -latomic -Wl,--export-dynamic,--as-needed,--no-whole-archive
12301233
# Detect if ifunc is supported
@@ -1238,12 +1241,12 @@ ifneq ($(SANITIZE),1)
12381241
JLDFLAGS += -Wl,-no-undefined
12391242
endif
12401243
ifeq (-Bsymbolic-functions, $(shell $(LD) --help | grep -o -e "-Bsymbolic-functions"))
1241-
JLIBLDFLAGS := -Wl,-Bsymbolic-functions
1244+
JLIBLDFLAGS += -Wl,-Bsymbolic-functions
12421245
else
1243-
JLIBLDFLAGS :=
12441246
endif
1245-
else ifneq ($(OS), Darwin)
1246-
JLIBLDFLAGS :=
1247+
ifeq (--enable-new-dtags, $(shell $(LD) --help | grep -o -e "--enable-new-dtags"))
1248+
JLIBLDFLAGS += -Wl,--enable-new-dtags
1249+
endif
12471250
endif
12481251

12491252
ifeq ($(OS), FreeBSD)
@@ -1266,7 +1269,7 @@ OSLIBS += -framework CoreFoundation
12661269
WHOLE_ARCHIVE := -Xlinker -all_load
12671270
NO_WHOLE_ARCHIVE :=
12681271
HAVE_SSP := 1
1269-
JLIBLDFLAGS := -Wl,-compatibility_version,$(SOMAJOR) -Wl,-current_version,$(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)
1272+
JLIBLDFLAGS += -Wl,-compatibility_version,$(SOMAJOR) -Wl,-current_version,$(JULIA_MAJOR_VERSION).$(JULIA_MINOR_VERSION).$(JULIA_PATCH_VERSION)
12701273
endif
12711274

12721275
ifeq ($(OS), WINNT)

Makefile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,23 +365,33 @@ endif
365365
# Set rpath for libjulia-internal, which is moving from `../lib` to `../lib/julia`. We only need to do this for Linux/FreeBSD
366366
ifneq (,$(findstring $(OS),Linux FreeBSD))
367367
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal.$(SHLIB_EXT)
368+
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-codegen.$(SHLIB_EXT)
368369
ifeq ($(BUNDLE_DEBUG_LIBS),1)
369370
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-internal-debug.$(SHLIB_EXT)
371+
$(PATCHELF) --set-rpath '$$ORIGIN:$$ORIGIN/$(reverse_private_libdir_rel)' $(DESTDIR)$(private_libdir)/libjulia-codegen-debug.$(SHLIB_EXT)
370372
endif
371373
endif
372374

373375

374376
ifneq ($(LOADER_BUILD_DEP_LIBS),$(LOADER_INSTALL_DEP_LIBS))
375377
# Next, overwrite relative path to libjulia-internal in our loader if $$(LOADER_BUILD_DEP_LIBS) != $$(LOADER_INSTALL_DEP_LIBS)
376378
$(call stringreplace,$(DESTDIR)$(shlibdir)/libjulia.$(JL_MAJOR_MINOR_SHLIB_EXT),$(LOADER_BUILD_DEP_LIBS)$$,$(LOADER_INSTALL_DEP_LIBS))
379+
ifeq ($(OS),Darwin)
380+
# Codesign the libjulia we just modified
381+
$(JULIAHOME)/contrib/codesign.sh "$(MACOS_CODESIGN_IDENTITY)" "$(DESTDIR)$(shlibdir)/libjulia.$(JL_MAJOR_MINOR_SHLIB_EXT)"
382+
endif
377383

378384
ifeq ($(BUNDLE_DEBUG_LIBS),1)
379385
$(call stringreplace,$(DESTDIR)$(shlibdir)/libjulia-debug.$(JL_MAJOR_MINOR_SHLIB_EXT),$(LOADER_DEBUG_BUILD_DEP_LIBS)$$,$(LOADER_DEBUG_INSTALL_DEP_LIBS))
386+
ifeq ($(OS),Darwin)
387+
# Codesign the libjulia we just modified
388+
$(JULIAHOME)/contrib/codesign.sh "$(MACOS_CODESIGN_IDENTITY)" "$(DESTDIR)$(shlibdir)/libjulia-debug.$(JL_MAJOR_MINOR_SHLIB_EXT)"
389+
endif
380390
endif
381391
endif
382392

383-
# On FreeBSD, remove the build's libdir from each library's RPATH
384393
ifeq ($(OS),FreeBSD)
394+
# On FreeBSD, remove the build's libdir from each library's RPATH
385395
$(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(libdir) $(build_libdir)
386396
$(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(private_libdir) $(build_libdir)
387397
$(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(bindir) $(build_libdir)
@@ -428,16 +438,9 @@ endif
428438
ifeq ($(OS), WINNT)
429439
cd $(BUILDROOT)/julia-$(JULIA_COMMIT)/bin && rm -f llvm* llc.exe lli.exe opt.exe LTO.dll bugpoint.exe macho-dump.exe
430440
endif
431-
# If we're on macOS, and we have a codesigning identity, then codesign the binary-dist tarball!
432441
ifeq ($(OS),Darwin)
433-
ifneq ($(MACOS_CODESIGN_IDENTITY),)
434-
echo "Codesigning with identity $(MACOS_CODESIGN_IDENTITY)"; \
435-
MACHO_FILES=$$(find "$(BUILDROOT)/julia-$(JULIA_COMMIT)" -type f -perm -0111 | cut -d: -f1); \
436-
for f in $${MACHO_FILES}; do \
437-
echo "Codesigning $${f}..."; \
438-
codesign -s "$(MACOS_CODESIGN_IDENTITY)" --option=runtime --entitlements $(JULIAHOME)/contrib/mac/app/Entitlements.plist -vvv --timestamp --deep --force "$${f}"; \
439-
done
440-
endif
442+
# If we're on macOS, and we have a codesigning identity, then codesign the binary-dist tarball!
443+
$(JULIAHOME)/contrib/codesign.sh "$(MACOS_CODESIGN_IDENTITY)" "$(BUILDROOT)/julia-$(JULIA_COMMIT)"
441444
endif
442445
cd $(BUILDROOT) && $(TAR) zcvf $(JULIA_BINARYDIST_FILENAME).tar.gz julia-$(JULIA_COMMIT)
443446

base/bitset.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,10 @@ function union!(s::BitSet, r::AbstractUnitRange{<:Integer})
137137

138138
# grow s.bits as necessary
139139
if diffb >= len
140-
_growend!(s.bits, diffb - len + 1)
141-
# we set only some values to CHK0, those which will not be
142-
# fully overwritten (i.e. only or'ed with `|`)
143-
s.bits[end] = CHK0 # end == diffb + 1
144-
if diffa >= len
145-
s.bits[diffa + 1] = CHK0
146-
end
140+
_growend0!(s.bits, diffb - len + 1)
147141
end
148142
if diffa < 0
149-
_growbeg!(s.bits, -diffa)
150-
s.bits[1] = CHK0
151-
if diffb < 0
152-
s.bits[diffb - diffa + 1] = CHK0
153-
end
143+
_growbeg0!(s.bits, -diffa)
154144
s.offset = cidxa # s.offset += diffa
155145
diffb -= diffa
156146
diffa = 0

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function find_matching_methods(argtypes::Vector{Any}, @nospecialize(atype), meth
282282
if result === missing
283283
return FailedMethodMatch("For one of the union split cases, too many methods matched")
284284
end
285-
matches, overlayed = result
285+
(; matches, overlayed) = result
286286
nonoverlayed &= !overlayed
287287
push!(infos, MethodMatchInfo(matches))
288288
for m in matches
@@ -323,7 +323,7 @@ function find_matching_methods(argtypes::Vector{Any}, @nospecialize(atype), meth
323323
# (assume this will always be true, so we don't compute / update valid age in this case)
324324
return FailedMethodMatch("Too many methods matched")
325325
end
326-
matches, overlayed = result
326+
(; matches, overlayed) = result
327327
fullmatch = _any(match->(match::MethodMatch).fully_covers, matches)
328328
return MethodMatches(matches.matches,
329329
MethodMatchInfo(matches),

base/compiler/compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ something(x::Any, y...) = x
123123
############
124124

125125
include("compiler/cicache.jl")
126+
include("compiler/methodtable.jl")
126127
include("compiler/types.jl")
127128
include("compiler/utilities.jl")
128129
include("compiler/validation.jl")
129-
include("compiler/methodtable.jl")
130130

131131
include("compiler/inferenceresult.jl")
132132
include("compiler/inferencestate.jl")

base/compiler/methodtable.jl

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
abstract type MethodTableView; end
44

5+
struct MethodLookupResult
6+
# Really Vector{Core.MethodMatch}, but it's easier to represent this as
7+
# and work with Vector{Any} on the C side.
8+
matches::Vector{Any}
9+
valid_worlds::WorldRange
10+
ambig::Bool
11+
end
12+
length(result::MethodLookupResult) = length(result.matches)
13+
function iterate(result::MethodLookupResult, args...)
14+
r = iterate(result.matches, args...)
15+
r === nothing && return nothing
16+
match, state = r
17+
return (match::MethodMatch, state)
18+
end
19+
getindex(result::MethodLookupResult, idx::Int) = getindex(result.matches, idx)::MethodMatch
20+
21+
struct MethodMatchResult
22+
matches::MethodLookupResult
23+
overlayed::Bool
24+
end
25+
526
"""
627
struct InternalMethodTable <: MethodTableView
728
@@ -23,25 +44,21 @@ struct OverlayMethodTable <: MethodTableView
2344
mt::Core.MethodTable
2445
end
2546

26-
struct MethodLookupResult
27-
# Really Vector{Core.MethodMatch}, but it's easier to represent this as
28-
# and work with Vector{Any} on the C side.
29-
matches::Vector{Any}
30-
valid_worlds::WorldRange
31-
ambig::Bool
32-
end
33-
length(result::MethodLookupResult) = length(result.matches)
34-
function iterate(result::MethodLookupResult, args...)
35-
r = iterate(result.matches, args...)
36-
r === nothing && return nothing
37-
match, state = r
38-
return (match::MethodMatch, state)
47+
"""
48+
struct CachedMethodTable <: MethodTableView
49+
50+
Overlays another method table view with an additional local fast path cache that
51+
can respond to repeated, identical queries faster than the original method table.
52+
"""
53+
struct CachedMethodTable{T} <: MethodTableView
54+
cache::IdDict{Any, Union{Missing, MethodMatchResult}}
55+
table::T
3956
end
40-
getindex(result::MethodLookupResult, idx::Int) = getindex(result.matches, idx)::MethodMatch
57+
CachedMethodTable(table::T) where T = CachedMethodTable{T}(IdDict{Any, Union{Missing, MethodMatchResult}}(), table)
4158

4259
"""
4360
findall(sig::Type, view::MethodTableView; limit::Int=typemax(Int)) ->
44-
(matches::MethodLookupResult, overlayed::Bool) or missing
61+
MethodMatchResult(matches::MethodLookupResult, overlayed::Bool) or missing
4562
4663
Find all methods in the given method table `view` that are applicable to the given signature `sig`.
4764
If no applicable methods are found, an empty result is returned.
@@ -51,7 +68,7 @@ If the number of applicable methods exceeded the specified limit, `missing` is r
5168
function findall(@nospecialize(sig::Type), table::InternalMethodTable; limit::Int=Int(typemax(Int32)))
5269
result = _findall(sig, nothing, table.world, limit)
5370
result === missing && return missing
54-
return result, false
71+
return MethodMatchResult(result, false)
5572
end
5673

5774
function findall(@nospecialize(sig::Type), table::OverlayMethodTable; limit::Int=Int(typemax(Int32)))
@@ -60,18 +77,20 @@ function findall(@nospecialize(sig::Type), table::OverlayMethodTable; limit::Int
6077
nr = length(result)
6178
if nr 1 && result[nr].fully_covers
6279
# no need to fall back to the internal method table
63-
return result, true
80+
return MethodMatchResult(result, true)
6481
end
6582
# fall back to the internal method table
6683
fallback_result = _findall(sig, nothing, table.world, limit)
6784
fallback_result === missing && return missing
6885
# merge the fallback match results with the internal method table
69-
return MethodLookupResult(
70-
vcat(result.matches, fallback_result.matches),
71-
WorldRange(
72-
max(result.valid_worlds.min_world, fallback_result.valid_worlds.min_world),
73-
min(result.valid_worlds.max_world, fallback_result.valid_worlds.max_world)),
74-
result.ambig | fallback_result.ambig), !isempty(result)
86+
return MethodMatchResult(
87+
MethodLookupResult(
88+
vcat(result.matches, fallback_result.matches),
89+
WorldRange(
90+
max(result.valid_worlds.min_world, fallback_result.valid_worlds.min_world),
91+
min(result.valid_worlds.max_world, fallback_result.valid_worlds.max_world)),
92+
result.ambig | fallback_result.ambig),
93+
!isempty(result))
7594
end
7695

7796
function _findall(@nospecialize(sig::Type), mt::Union{Nothing,Core.MethodTable}, world::UInt, limit::Int)
@@ -85,6 +104,17 @@ function _findall(@nospecialize(sig::Type), mt::Union{Nothing,Core.MethodTable},
85104
return MethodLookupResult(ms::Vector{Any}, WorldRange(_min_val[], _max_val[]), _ambig[] != 0)
86105
end
87106

107+
function findall(@nospecialize(sig::Type), table::CachedMethodTable; limit::Int=typemax(Int))
108+
if isconcretetype(sig)
109+
# as for concrete types, we cache result at on the next level
110+
return findall(sig, table.table; limit)
111+
end
112+
box = Core.Box(sig)
113+
return get!(table.cache, sig) do
114+
findall(box.contents, table.table; limit)
115+
end
116+
end
117+
88118
"""
89119
findsup(sig::Type, view::MethodTableView) ->
90120
(match::MethodMatch, valid_worlds::WorldRange, overlayed::Bool) or nothing
@@ -129,6 +159,10 @@ function _findsup(@nospecialize(sig::Type), mt::Union{Nothing,Core.MethodTable},
129159
return match, valid_worlds
130160
end
131161

162+
# This query is not cached
163+
findsup(@nospecialize(sig::Type), table::CachedMethodTable) = findsup(sig, table.table)
164+
132165
isoverlayed(::MethodTableView) = error("unsatisfied MethodTableView interface")
133166
isoverlayed(::InternalMethodTable) = false
134167
isoverlayed(::OverlayMethodTable) = true
168+
isoverlayed(mt::CachedMethodTable) = isoverlayed(mt.table)

base/compiler/ssair/legacy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
5858
elseif isa(stmt, GotoIfNot)
5959
stmt = GotoIfNot(stmt.cond, first(ir.cfg.blocks[stmt.dest].stmts))
6060
elseif isa(stmt, PhiNode)
61-
stmt = PhiNode(Int32[last(ir.cfg.blocks[edge].stmts) for edge in stmt.edges], stmt.values)
61+
stmt = PhiNode(Int32[edge == 0 ? 0 : last(ir.cfg.blocks[edge].stmts) for edge in stmt.edges], stmt.values)
6262
elseif isa(stmt, Expr) && stmt.head === :enter
6363
stmt.args[1] = first(ir.cfg.blocks[stmt.args[1]::Int].stmts)
6464
end

base/compiler/types.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ struct NativeInterpreter <: AbstractInterpreter
318318
cache::Vector{InferenceResult}
319319
# The world age we're working inside of
320320
world::UInt
321+
# method table to lookup for during inference on this world age
322+
method_table::CachedMethodTable{InternalMethodTable}
321323

322324
# Parameters for inference and optimization
323325
inf_params::InferenceParams
@@ -327,27 +329,21 @@ struct NativeInterpreter <: AbstractInterpreter
327329
inf_params = InferenceParams(),
328330
opt_params = OptimizationParams(),
329331
)
332+
cache = Vector{InferenceResult}() # Initially empty cache
333+
330334
# Sometimes the caller is lazy and passes typemax(UInt).
331335
# we cap it to the current world age
332336
if world == typemax(UInt)
333337
world = get_world_counter()
334338
end
335339

340+
method_table = CachedMethodTable(InternalMethodTable(world))
341+
336342
# If they didn't pass typemax(UInt) but passed something more subtly
337343
# incorrect, fail out loudly.
338344
@assert world <= get_world_counter()
339345

340-
return new(
341-
# Initially empty cache
342-
Vector{InferenceResult}(),
343-
344-
# world age counter
345-
world,
346-
347-
# parameters for inference and optimization
348-
inf_params,
349-
opt_params,
350-
)
346+
return new(cache, world, method_table, inf_params, opt_params)
351347
end
352348
end
353349

@@ -396,6 +392,7 @@ External `AbstractInterpreter` can optionally return `OverlayMethodTable` here
396392
to incorporate customized dispatches for the overridden methods.
397393
"""
398394
method_table(interp::AbstractInterpreter) = InternalMethodTable(get_world_counter(interp))
395+
method_table(interp::NativeInterpreter) = interp.method_table
399396

400397
"""
401398
By default `AbstractInterpreter` implements the following inference bail out logic:

base/deepcopy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function deepcopy_internal(x::GenericCondition, stackdict::IdDict)
140140
if haskey(stackdict, x)
141141
return stackdict[x]
142142
end
143-
y = typeof(x)(deepcopy_internal(x.lock))
143+
y = typeof(x)(deepcopy_internal(x.lock, stackdict))
144144
stackdict[x] = y
145145
return y
146146
end

base/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ end
372372

373373
function setindex!(h::Dict{K,V}, v0, key0) where V where K
374374
key = convert(K, key0)
375-
if !isequal(key, key0)
375+
if !(isequal(key, key0)::Bool)
376376
throw(ArgumentError("$(limitrepr(key0)) is not a valid key for type $K"))
377377
end
378378
setindex!(h, v0, key)

base/logging.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ function handle_message(logger::SimpleLogger, level::LogLevel, message, _module,
669669
end
670670
buf = IOBuffer()
671671
stream = logger.stream
672-
if !isopen(stream)
672+
if !(isopen(stream)::Bool)
673673
stream = stderr
674674
end
675675
iob = IOContext(buf, stream)

0 commit comments

Comments
 (0)