Skip to content

Commit

Permalink
inference: mark several no-throw results as pure (#38199)
Browse files Browse the repository at this point in the history
Closes #37230
  • Loading branch information
vtjnash authored Oct 28, 2020
1 parent 0f0bc29 commit f7dbd1c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
if la == 2
ft = widenconst(argtypes[2])
if isa(ft, DataType) && isdefined(ft.name, :mt) && isdefined(ft.name.mt, :kwsorter)
return CallMeta(Const(ft.name.mt.kwsorter), false)
return CallMeta(Const(ft.name.mt.kwsorter), MethodResultPure())
end
end
return CallMeta(Any, false)
Expand Down Expand Up @@ -982,17 +982,17 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
return CallMeta(abstract_call_known(interp, <:, fargs, argtypes, sv).rt, false)
elseif la == 2 && isa(argtypes[2], Const) && isa(argtypes[2].val, SimpleVector) && istopfunction(f, :length)
# mark length(::SimpleVector) as @pure
return CallMeta(Const(length(argtypes[2].val)), false)
return CallMeta(Const(length(argtypes[2].val)), MethodResultPure())
elseif la == 3 && isa(argtypes[2], Const) && isa(argtypes[3], Const) &&
isa(argtypes[2].val, SimpleVector) && isa(argtypes[3].val, Int) && istopfunction(f, :getindex)
# mark getindex(::SimpleVector, i::Int) as @pure
svecval = argtypes[2].val::SimpleVector
idx = argtypes[3].val::Int
if 1 <= idx <= length(svecval) && isassigned(svecval, idx)
return CallMeta(Const(getindex(svecval, idx)), false)
return CallMeta(Const(getindex(svecval, idx)), MethodResultPure())
end
elseif la == 2 && istopfunction(f, :typename)
return CallMeta(typename_static(argtypes[2]), false)
return CallMeta(typename_static(argtypes[2]), MethodResultPure())
elseif max_methods > 1 && istopfunction(f, :copyto!)
max_methods = 1
elseif la == 3 && istopfunction(f, :typejoin)
Expand Down

0 comments on commit f7dbd1c

Please sign in to comment.