Skip to content

Commit

Permalink
Fix incorrect effect free modeling for return_type
Browse files Browse the repository at this point in the history
Inlining had a special case for return_type that was not taking
into account whether or not return_type was being called correctly.
Since we already have the correct modeling in inference, remove
the special case from inlining and simply have inference forward
its conclusions.
  • Loading branch information
Keno committed May 15, 2022
1 parent 5456bcc commit aad9ff6
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ function stmt_effect_free(@nospecialize(stmt), @nospecialize(rt), src::Union{IRC
f = argextype(args[1], src)
f = singleton_type(f)
f === nothing && return false
is_return_type(f) && return true
if isa(f, IntrinsicFunction)
intrinsic_effect_free_if_nothrow(f) || return false
return intrinsic_nothrow(f,
Expand Down
3 changes: 0 additions & 3 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,6 @@ function process_simple!(ir::IRCode, idx::Int, state::InliningState, todo::Vecto
ir[SSAValue(idx)][:inst] = lateres.val
check_effect_free!(ir, idx, lateres.val, rt)
return nothing
elseif is_return_type(sig.f)
check_effect_free!(ir, idx, stmt, rt)
return nothing
end

return stmt, sig
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/stmtinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ effect-free, including being no-throw (typically because the value was computed
by calling an `@pure` function).
"""
struct MethodResultPure
info::Union{MethodMatchInfo,UnionSplitInfo,Bool}
info::Any
end
let instance = MethodResultPure(false)
global MethodResultPure
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, s
sv.restrict_abstract_call_sites = false
call = abstract_call(interp, ArgInfo(nothing, argtypes_vec), sv, -1)
sv.restrict_abstract_call_sites = old_restrict
info = verbose_stmt_info(interp) ? ReturnTypeCallInfo(call.info) : false
info = verbose_stmt_info(interp) ? MethodResultPure(ReturnTypeCallInfo(call.info)) : MethodResultPure()
rt = widenconditional(call.rt)
if isa(rt, Const)
# output was computed to be constant
Expand Down
4 changes: 4 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1275,3 +1275,7 @@ end
return_type_unused(x)
return nothing
end

# Test that inlining doesn't accidentally delete a bad return_type call
f_bad_return_type() = Core.Compiler.return_type(+, 1, 2)
@test_throws MethodError f_bad_return_type()

0 comments on commit aad9ff6

Please sign in to comment.