Skip to content

Commit 4a45773

Browse files
authored
Merge branch 'master' into Base_strings_StringIndexError_nospecialize
2 parents 3e88da9 + 7d84c53 commit 4a45773

File tree

42 files changed

+668
-316
lines changed

Some content is hidden

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

42 files changed

+668
-316
lines changed

Compiler/src/Compiler.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,22 @@ end
193193
module IRShow end # relies on string and IO operations defined in Base
194194
baremodule TrimVerifier end # relies on IRShow, so define this afterwards
195195

196-
function load_irshow!()
197-
if isdefined(Base, :end_base_include)
198-
# This code path is exclusively for Revise, which may want to re-run this
199-
# after bootstrap.
200-
Compilerdir = Base.dirname(Base.String(@__SOURCE_FILE__))
201-
include(IRShow, Base.joinpath(Compilerdir, "ssair/show.jl"))
202-
include(TrimVerifier, Base.joinpath(Compilerdir, "verifytrim.jl"))
203-
else
196+
if isdefined(Base, :end_base_include)
197+
# When this module is loaded as the standard library, include these files as usual
198+
include(IRShow, "ssair/show.jl")
199+
include(TrimVerifier, "verifytrim.jl")
200+
else
201+
function load_irshow!()
202+
Base.delete_method(Base.which(verify_typeinf_trim, (IO, Vector{Any}, Bool)),)
204203
include(IRShow, "ssair/show.jl")
205204
include(TrimVerifier, "verifytrim.jl")
206205
end
207-
end
208-
if !isdefined(Base, :end_base_include)
209-
# During bootstrap, skip including this file and defer it to base/show.jl to include later
210-
else
211-
# When this module is loaded as the standard library, include this file as usual
212-
load_irshow!()
206+
function verify_typeinf_trim(io::IO, codeinfos::Vector{Any}, onlywarn::Bool)
207+
# stub implementation
208+
msg = "--trim verifier not defined"
209+
onlywarn ? println(io, msg) : error(msg)
210+
end
211+
# During bootstrap, skip including these files and defer to base/show.jl to include it later
213212
end
214213

215214
end # baremodule Compiler

Compiler/src/typeinfer.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
876876
end
877877
end
878878
end
879-
if ccall(:jl_get_module_infer, Cint, (Any,), method.module) == 0
879+
if !InferenceParams(interp).force_enable_inference && ccall(:jl_get_module_infer, Cint, (Any,), method.module) == 0
880880
add_remark!(interp, caller, "[typeinf_edge] Inference is disabled for the target module")
881881
return Future(MethodCallResult(interp, caller, method, Any, Any, Effects(), nothing, edgecycle, edgelimited))
882882
end
@@ -1160,15 +1160,17 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance, source_mod
11601160
end
11611161
end
11621162
end
1163-
if isa(def, Method) && ccall(:jl_get_module_infer, Cint, (Any,), def.module) == 0
1164-
src = retrieve_code_info(mi, get_inference_world(interp))
1165-
if src isa CodeInfo
1166-
finish!(interp, mi, ci, src)
1167-
else
1168-
engine_reject(interp, ci)
1163+
if !InferenceParams(interp).force_enable_inference
1164+
if isa(def, Method) && ccall(:jl_get_module_infer, Cint, (Any,), def.module) == 0
1165+
src = retrieve_code_info(mi, get_inference_world(interp))
1166+
if src isa CodeInfo
1167+
finish!(interp, mi, ci, src)
1168+
else
1169+
engine_reject(interp, ci)
1170+
end
1171+
ccall(:jl_typeinf_timing_end, Cvoid, (UInt64,), start_time)
1172+
return ci
11691173
end
1170-
ccall(:jl_typeinf_timing_end, Cvoid, (UInt64,), start_time)
1171-
return ci
11721174
end
11731175
result = InferenceResult(mi, typeinf_lattice(interp))
11741176
result.ci = ci
@@ -1314,7 +1316,10 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_m
13141316
# first compute the ABIs of everything
13151317
latest = true # whether this_world == world_counter()
13161318
for this_world in reverse(sort!(worlds))
1317-
interp = NativeInterpreter(this_world)
1319+
interp = NativeInterpreter(
1320+
this_world;
1321+
inf_params = InferenceParams(; force_enable_inference = trim_mode != TRIM_NO)
1322+
)
13181323
for i = 1:length(methods)
13191324
# each item in this list is either a MethodInstance indicating something
13201325
# to compile, or an svec(rettype, sig) describing a C-callable alias to create.
@@ -1355,7 +1360,7 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_m
13551360
src = codeinfo_for_const(interp, mi, callee.rettype_const)
13561361
elseif haskey(interp.codegen, callee)
13571362
src = interp.codegen[callee]
1358-
elseif isa(def, Method) && ccall(:jl_get_module_infer, Cint, (Any,), def.module) == 0 && trim_mode == TRIM_NO
1363+
elseif isa(def, Method) && !InferenceParams(interp).force_enable_inference && ccall(:jl_get_module_infer, Cint, (Any,), def.module) == 0
13591364
src = retrieve_code_info(mi, get_inference_world(interp))
13601365
else
13611366
# TODO: typeinf_code could return something with different edges/ages/owner/abi (needing an update to callee), which we don't handle here
@@ -1380,7 +1385,6 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_m
13801385
return codeinfos
13811386
end
13821387

1383-
verify_typeinf_trim(io::IO, codeinfos::Vector{Any}, onlywarn::Bool) = (msg = "--trim verifier not defined"; onlywarn ? println(io, msg) : error(msg))
13841388
verify_typeinf_trim(codeinfos::Vector{Any}, onlywarn::Bool) = invokelatest(verify_typeinf_trim, stdout, codeinfos, onlywarn)
13851389

13861390
function return_type(@nospecialize(f), t::DataType) # this method has a special tfunc

Compiler/src/types.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ Parameters that control abstract interpretation-based type inference operation.
191191
it will `throw`). Defaults to `false` since this assumption does not hold in Julia's
192192
semantics for native code execution.
193193
---
194+
- `inf_params.force_enable_inference::Bool = false`\\
195+
If `true`, inference will be performed on functions regardless of whether it was disabled
196+
at the module level via `Base.Experimental.@compiler_options`.
197+
---
194198
"""
195199
struct InferenceParams
196200
max_methods::Int
@@ -202,6 +206,7 @@ struct InferenceParams
202206
aggressive_constant_propagation::Bool
203207
assume_bindings_static::Bool
204208
ignore_recursion_hardlimit::Bool
209+
force_enable_inference::Bool
205210

206211
function InferenceParams(
207212
max_methods::Int,
@@ -212,7 +217,9 @@ struct InferenceParams
212217
ipo_constant_propagation::Bool,
213218
aggressive_constant_propagation::Bool,
214219
assume_bindings_static::Bool,
215-
ignore_recursion_hardlimit::Bool)
220+
ignore_recursion_hardlimit::Bool,
221+
force_enable_inference::Bool,
222+
)
216223
return new(
217224
max_methods,
218225
max_union_splitting,
@@ -222,7 +229,9 @@ struct InferenceParams
222229
ipo_constant_propagation,
223230
aggressive_constant_propagation,
224231
assume_bindings_static,
225-
ignore_recursion_hardlimit)
232+
ignore_recursion_hardlimit,
233+
force_enable_inference,
234+
)
226235
end
227236
end
228237
function InferenceParams(
@@ -235,7 +244,9 @@ function InferenceParams(
235244
#=ipo_constant_propagation::Bool=# true,
236245
#=aggressive_constant_propagation::Bool=# false,
237246
#=assume_bindings_static::Bool=# false,
238-
#=ignore_recursion_hardlimit::Bool=# false);
247+
#=ignore_recursion_hardlimit::Bool=# false,
248+
#=force_enable_inference::Bool=# false
249+
);
239250
max_methods::Int = params.max_methods,
240251
max_union_splitting::Int = params.max_union_splitting,
241252
max_apply_union_enum::Int = params.max_apply_union_enum,
@@ -244,7 +255,9 @@ function InferenceParams(
244255
ipo_constant_propagation::Bool = params.ipo_constant_propagation,
245256
aggressive_constant_propagation::Bool = params.aggressive_constant_propagation,
246257
assume_bindings_static::Bool = params.assume_bindings_static,
247-
ignore_recursion_hardlimit::Bool = params.ignore_recursion_hardlimit)
258+
ignore_recursion_hardlimit::Bool = params.ignore_recursion_hardlimit,
259+
force_enable_inference::Bool = params.force_enable_inference,
260+
)
248261
return InferenceParams(
249262
max_methods,
250263
max_union_splitting,
@@ -254,7 +267,9 @@ function InferenceParams(
254267
ipo_constant_propagation,
255268
aggressive_constant_propagation,
256269
assume_bindings_static,
257-
ignore_recursion_hardlimit)
270+
ignore_recursion_hardlimit,
271+
force_enable_inference,
272+
)
258273
end
259274

260275
"""

Compiler/src/verifytrim.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ end
310310
# driver / verifier implemented by juliac-buildscript.jl for the purpose of extensibility.
311311
# For now, it is part of Base.Compiler, but executed with invokelatest so that packages
312312
# could provide hooks to change, customize, or tweak its behavior and heuristics.
313-
Base.delete_method(Base.which(verify_typeinf_trim, (IO, Vector{Any}, Bool)),)
314313
function verify_typeinf_trim(io::IO, codeinfos::Vector{Any}, onlywarn::Bool)
315314
errors, parents = get_verify_typeinf_trim(codeinfos)
316315

@@ -328,16 +327,19 @@ function verify_typeinf_trim(io::IO, codeinfos::Vector{Any}, onlywarn::Bool)
328327
end
329328

330329
let severity = 0
331-
if counts[2] > 0
332-
print("Trim verify finished with ", counts[2], counts[2] == 1 ? " warning.\n\n" : " warnings.\n\n")
330+
if counts[1] > 0 || counts[2] > 0
331+
print("Trim verify finished with ")
332+
print(counts[1], counts[1] == 1 ? " error" : " errors")
333+
print(", ")
334+
print(counts[2], counts[2] == 1 ? " warning" : " warnings")
335+
print(".\n")
333336
severity = 2
334337
end
335338
if counts[1] > 0
336-
print("Trim verify finished with ", counts[1], counts[1] == 1 ? " error.\n\n" : " errors.\n\n")
337339
severity = 1
338340
end
339341
# messages classified as errors are fatal, warnings are not
340-
0 < severity <= 1 && !onlywarn && error("verify_typeinf_trim failed")
342+
0 < severity <= 1 && !onlywarn && throw(Core.TrimFailure())
341343
end
342344
nothing
343345
end

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ New language features
2525
* Support for Unicode 16 ([#56925]).
2626
* `Threads.@spawn` now takes a `:samepool` argument to specify the same threadpool as the caller.
2727
`Threads.@spawn :samepool foo()` which is shorthand for `Threads.@spawn Threads.threadpool() foo()` ([#57109]).
28+
* The `@ccall` macro can now take a `gc_safe` argument, that if set to true allows the runtime to run garbage collection concurrently to the `ccall` ([#49933]).
2829

2930
Language changes
3031
----------------

NEWS.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
Julia v1.12 Release Notes
1+
Julia v1.13 Release Notes
22
========================
33

44
New language features
55
---------------------
66

7-
* The `@ccall` macro can now take a `gc_safe` argument, that if set to true allows the runtime to run garbage collection concurrently to the `ccall`
8-
97
Language changes
108
----------------
119

base/boot.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ struct ABIOverride
475475
end
476476

477477
struct PrecompilableError <: Exception end
478+
struct TrimFailure <: Exception end
478479

479480
String(s::String) = s # no constructor yet
480481

base/char.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ isless(x::Char, y::Char) = bitcast(UInt32, x) < bitcast(UInt32, y)
224224
hash(x::Char, h::UInt) =
225225
hash_uint64(((bitcast(UInt32, x) + UInt64(0xd4d64234)) << 32) UInt64(h))
226226

227-
first_utf8_byte(c::Char) = (bitcast(UInt32, c) >> 24) % UInt8
228-
first_utf8_byte(c::AbstractChar) = first_utf8_byte(Char(c)::Char)
229-
230227
# fallbacks:
231228
isless(x::AbstractChar, y::AbstractChar) = isless(Char(x), Char(y))
232229
==(x::AbstractChar, y::AbstractChar) = Char(x) == Char(y)

base/lock.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,10 @@ mutable struct OncePerProcess{T, F} <: Function
711711
end
712712
OncePerProcess{T}(initializer::F) where {T, F} = OncePerProcess{T, F}(initializer)
713713
OncePerProcess(initializer) = OncePerProcess{Base.promote_op(initializer), typeof(initializer)}(initializer)
714-
@inline function (once::OncePerProcess{T})() where T
714+
@inline function (once::OncePerProcess{T,F})() where {T,F}
715715
state = (@atomic :acquire once.state)
716716
if state != PerStateHasrun
717-
(@noinline function init_perprocesss(once, state)
717+
(@noinline function init_perprocesss(once::OncePerProcess{T,F}, state::UInt8) where {T,F}
718718
state == PerStateErrored && error("OncePerProcess initializer failed previously")
719719
once.allow_compile_time || __precompile__(false)
720720
lock(once.lock)
@@ -818,14 +818,14 @@ mutable struct OncePerThread{T, F} <: Function
818818
end
819819
OncePerThread{T}(initializer::F) where {T, F} = OncePerThread{T,F}(initializer)
820820
OncePerThread(initializer) = OncePerThread{Base.promote_op(initializer), typeof(initializer)}(initializer)
821-
@inline (once::OncePerThread)() = once[Threads.threadid()]
822-
@inline function getindex(once::OncePerThread, tid::Integer)
821+
@inline (once::OncePerThread{T,F})() where {T,F} = once[Threads.threadid()]
822+
@inline function getindex(once::OncePerThread{T,F}, tid::Integer) where {T,F}
823823
tid = Int(tid)
824824
ss = @atomic :acquire once.ss
825825
xs = @atomic :monotonic once.xs
826826
# n.b. length(xs) >= length(ss)
827827
if tid <= 0 || tid > length(ss) || (@atomic :acquire ss[tid]) != PerStateHasrun
828-
(@noinline function init_perthread(once, tid)
828+
(@noinline function init_perthread(once::OncePerThread{T,F}, tid::Int) where {T,F}
829829
local ss = @atomic :acquire once.ss
830830
local xs = @atomic :monotonic once.xs
831831
local len = length(ss)
@@ -933,6 +933,6 @@ mutable struct OncePerTask{T, F} <: Function
933933
OncePerTask{T,F}(initializer::F) where {T, F} = new{T,F}(initializer)
934934
OncePerTask(initializer) = new{Base.promote_op(initializer), typeof(initializer)}(initializer)
935935
end
936-
@inline function (once::OncePerTask{T})() where {T}
936+
@inline function (once::OncePerTask{T,F})() where {T,F}
937937
get!(once.initializer, task_local_storage(), once)::T
938938
end

base/range.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,8 @@ StepRange{T1,T2}(r::AbstractRange) where {T1,T2} =
13291329
StepRange(r::AbstractUnitRange{T}) where {T} =
13301330
StepRange{T,T}(first(r), step(r), last(r))
13311331
(StepRange{T1,T2} where T1)(r::AbstractRange) where {T2} = StepRange{eltype(r),T2}(r)
1332+
StepRange(r::StepRangeLen) = StepRange{eltype(r)}(r)
1333+
StepRange{T}(r::StepRangeLen{<:Any,<:Any,S}) where {T,S} = StepRange{T,S}(r)
13321334

13331335
function promote_rule(::Type{StepRangeLen{T1,R1,S1,L1}},::Type{StepRangeLen{T2,R2,S2,L2}}) where {T1,T2,R1,R2,S1,S2,L1,L2}
13341336
R, S, L = promote_type(R1, R2), promote_type(S1, S2), promote_type(L1, L2)

0 commit comments

Comments
 (0)