Skip to content

Commit

Permalink
effects: taint nonoverlayed when bailing out inference (#48838)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored and KristofferC committed Mar 3, 2023
1 parent a6a19e4 commit 09757f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 1 addition & 3 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
if seen napplicable
# there is unanalyzed candidate, widen type and effects to the top
rettype = Any
# there may be unanalyzed effects within unseen dispatch candidate,
# but we can still ignore nonoverlayed effect here since we already accounted for it
all_effects = merge_effects(all_effects, EFFECTS_UNKNOWN)
all_effects = Effects()
elseif isa(matches, MethodMatches) ? (!matches.fullmatch || any_ambig(matches)) :
(!all(matches.fullmatches) || any_ambig(matches))
# Account for the fact that we may encounter a MethodError with a non-covered or ambiguous signature.
Expand Down
23 changes: 23 additions & 0 deletions test/compiler/AbstractInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ import Base.Experimental: @MethodTable, @overlay
@MethodTable(OverlayedMT)
CC.method_table(interp::MTOverlayInterp) = CC.OverlayMethodTable(CC.get_world_counter(interp), OverlayedMT)

function CC.add_remark!(interp::MTOverlayInterp, ::CC.InferenceState, remark)
if interp.meta !== nothing
# Core.println(remark)
push!(interp.meta, remark)
end
return nothing
end

strangesin(x) = sin(x)
@overlay OverlayedMT strangesin(x::Float64) = iszero(x) ? nothing : cos(x)

Expand All @@ -64,6 +72,21 @@ end |> !Core.Compiler.is_nonoverlayed
@invoke strangesin(x::Float64)
end |> !Core.Compiler.is_nonoverlayed

# account for overlay possibility in unanalyzed matching method
callstrange(::Nothing) = Core.compilerbarrier(:type, nothing) # trigger inference bail out
callstrange(::Float64) = strangesin(x)
callstrange_entry(x) = callstrange(x) # needs to be defined here because of world age
let interp = MTOverlayInterp(; meta=Set{Any}())
matches = Core.Compiler.findall(Tuple{typeof(callstrange),Any}, Core.Compiler.method_table(interp)).matches
@test Core.Compiler.length(matches) == 2
if Core.Compiler.getindex(matches, 1).method == which(callstrange, (Nothing,))
@test Base.infer_effects(callstrange_entry, (Any,); interp) |> !Core.Compiler.is_nonoverlayed
@test "Call inference reached maximally imprecise information. Bailing on." in interp.meta
else
@warn "`nonoverlayed` test for inference bailing out is skipped since the method match sort order is changed."
end
end

# but it should never apply for the native compilation
@test Base.infer_effects((Float64,)) do x
strangesin(x)
Expand Down

0 comments on commit 09757f7

Please sign in to comment.