Skip to content

Commit 8f80df8

Browse files
committed
test metadata propagation to keyword sorter
1 parent e1f19e3 commit 8f80df8

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,7 @@ function const_prop_enabled(interp::AbstractInterpreter, sv::InferenceState, mat
799799
add_remark!(interp, sv, "[constprop] Disabled by parameter")
800800
return false
801801
end
802-
method = match.method
803-
if method.constprop == 0x02
802+
if is_no_constprop(match.method)
804803
add_remark!(interp, sv, "[constprop] Disabled by method parameter")
805804
return false
806805
end
@@ -1003,7 +1002,7 @@ function is_all_overridden((; fargs, argtypes)::ArgInfo, sv::InferenceState)
10031002
end
10041003

10051004
function force_const_prop(interp::AbstractInterpreter, @nospecialize(f), method::Method)
1006-
return method.constprop == 0x01 ||
1005+
return is_aggressive_constprop(method) ||
10071006
InferenceParams(interp).aggressive_constant_propagation ||
10081007
istopfunction(f, :getproperty) ||
10091008
istopfunction(f, :setproperty!)

base/compiler/utilities.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ function specialize_method(match::MethodMatch; kwargs...)
209209
return specialize_method(match.method, match.spec_types, match.sparams; kwargs...)
210210
end
211211

212+
"""
213+
is_aggressive_constprop(method::Union{Method,CodeInfo}) -> Bool
214+
215+
Check if `method` is declared as `Base.@constprop :aggressive`.
216+
"""
217+
is_aggressive_constprop(method::Union{Method,CodeInfo}) = method.constprop == 0x01
218+
219+
"""
220+
is_no_constprop(method::Union{Method,CodeInfo}) -> Bool
221+
222+
Check if `method` is declared as `Base.@constprop :none`.
223+
"""
224+
is_no_constprop(method::Union{Method,CodeInfo}) = method.constprop == 0x02
225+
212226
#########
213227
# types #
214228
#########

test/compiler/inline.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,3 +1402,49 @@ end
14021402
end
14031403
end
14041404
end
1405+
1406+
# https://github.com/JuliaLang/julia/issues/45050
1407+
@testset "propagate :meta annotations to keyword sorter methods" begin
1408+
# @inline, @noinline, @constprop
1409+
let @inline f(::Any; x::Int=1) = 2x
1410+
@test ccall(:jl_ir_flag_inlineable, Bool, (Any,), only(methods(f)).source)
1411+
@test ccall(:jl_ir_flag_inlineable, Bool, (Any,), only(methods(Core.kwfunc(f))).source)
1412+
end
1413+
let @noinline f(::Any; x::Int=1) = 2x
1414+
@test !ccall(:jl_ir_flag_inlineable, Bool, (Any,), only(methods(f)).source)
1415+
@test !ccall(:jl_ir_flag_inlineable, Bool, (Any,), only(methods(Core.kwfunc(f))).source)
1416+
end
1417+
let Base.@constprop :aggressive f(::Any; x::Int=1) = 2x
1418+
@test Core.Compiler.is_aggressive_constprop(only(methods(f)))
1419+
@test Core.Compiler.is_aggressive_constprop(only(methods(Core.kwfunc(f))))
1420+
end
1421+
let Base.@constprop :none f(::Any; x::Int=1) = 2x
1422+
@test Core.Compiler.is_no_constprop(only(methods(f)))
1423+
@test Core.Compiler.is_no_constprop(only(methods(Core.kwfunc(f))))
1424+
end
1425+
# @nospecialize
1426+
let f(@nospecialize(A::Any); x::Int=1) = 2x
1427+
@test only(methods(f)).nospecialize == 1
1428+
@test only(methods(Core.kwfunc(f))).nospecialize == 4
1429+
end
1430+
let f(::Any; x::Int=1) = (@nospecialize; 2x)
1431+
@test only(methods(f)).nospecialize == -1
1432+
@test only(methods(Core.kwfunc(f))).nospecialize == -1
1433+
end
1434+
# Base.@assume_effects
1435+
let Base.@assume_effects :notaskstate f(::Any; x::Int=1) = 2x
1436+
@test Core.Compiler.decode_effects_override(only(methods(f)).purity).notaskstate
1437+
@test Core.Compiler.decode_effects_override(only(methods(Core.kwfunc(f))).purity).notaskstate
1438+
end
1439+
# propagate multiple metadata also
1440+
let @inline Base.@assume_effects :notaskstate Base.@constprop :aggressive f(::Any; x::Int=1) = (@nospecialize; 2x)
1441+
@test ccall(:jl_ir_flag_inlineable, Bool, (Any,), only(methods(f)).source)
1442+
@test Core.Compiler.is_aggressive_constprop(only(methods(f)))
1443+
@test ccall(:jl_ir_flag_inlineable, Bool, (Any,), only(methods(Core.kwfunc(f))).source)
1444+
@test Core.Compiler.is_aggressive_constprop(only(methods(Core.kwfunc(f))))
1445+
@test only(methods(f)).nospecialize == -1
1446+
@test only(methods(Core.kwfunc(f))).nospecialize == -1
1447+
@test Core.Compiler.decode_effects_override(only(methods(f)).purity).notaskstate
1448+
@test Core.Compiler.decode_effects_override(only(methods(Core.kwfunc(f))).purity).notaskstate
1449+
end
1450+
end

0 commit comments

Comments
 (0)