Skip to content

Commit 3888176

Browse files
authored
follow up #44786, fix findsup to return correct overlayed value (#44804)
1 parent 70406c9 commit 3888176

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

base/compiler/methodtable.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ In both cases `nothing` is returned.
104104
`overlayed` indicates if any of the matching methods comes from an overlayed method table.
105105
"""
106106
function findsup(@nospecialize(sig::Type), table::InternalMethodTable)
107-
return (_findsup(sig, nothing, table.world)..., true)
107+
return (_findsup(sig, nothing, table.world)..., false)
108108
end
109109

110110
function findsup(@nospecialize(sig::Type), table::OverlayMethodTable)
111111
match, valid_worlds = _findsup(sig, table.mt, table.world)
112-
match !== nothing && return match, valid_worlds, false
112+
match !== nothing && return match, valid_worlds, true
113113
# fall back to the internal method table
114114
fallback_match, fallback_valid_worlds = _findsup(sig, nothing, table.world)
115115
return (
116116
fallback_match,
117117
WorldRange(
118118
max(valid_worlds.min_world, fallback_valid_worlds.min_world),
119119
min(valid_worlds.max_world, fallback_valid_worlds.max_world)),
120-
true)
120+
false)
121121
end
122122

123123
function _findsup(@nospecialize(sig::Type), mt::Union{Nothing,Core.MethodTable}, world::UInt)

test/compiler/AbstractInterpreter.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,31 @@ CC.method_table(interp::MTOverlayInterp) = CC.OverlayMethodTable(CC.get_world_co
4343

4444
strangesin(x) = sin(x)
4545
@overlay OverlayedMT strangesin(x::Float64) = iszero(x) ? nothing : cos(x)
46+
47+
# inference should use the overlayed method table
4648
@test Base.return_types((Float64,); interp=MTOverlayInterp()) do x
4749
strangesin(x)
4850
end |> only === Union{Float64,Nothing}
4951
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
5052
Base.@invoke strangesin(x::Float64)
5153
end |> only === Union{Float64,Nothing}
5254

55+
# effect analysis should figure out that the overlayed method is used
56+
@test Base.infer_effects((Float64,); interp=MTOverlayInterp()) do x
57+
strangesin(x)
58+
end |> !Core.Compiler.is_nonoverlayed
59+
@test Base.infer_effects((Any,); interp=MTOverlayInterp()) do x
60+
Base.@invoke strangesin(x::Float64)
61+
end |> !Core.Compiler.is_nonoverlayed
62+
63+
# but it should never apply for the native compilation
64+
@test Base.infer_effects((Float64,)) do x
65+
strangesin(x)
66+
end |> Core.Compiler.is_nonoverlayed
67+
@test Base.infer_effects((Any,)) do x
68+
Base.@invoke strangesin(x::Float64)
69+
end |> Core.Compiler.is_nonoverlayed
70+
5371
# fallback to the internal method table
5472
@test Base.return_types((Int,); interp=MTOverlayInterp()) do x
5573
cos(x)

0 commit comments

Comments
 (0)