Skip to content

Commit

Permalink
inference: fix efficiency of tfunc key lookup
Browse files Browse the repository at this point in the history
This was broken when `findfirst` was deprecated in 9bdf07f.
  • Loading branch information
vtjnash committed Oct 29, 2018
1 parent 82c4fce commit 3aeccec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function statement_cost(ex::Expr, line::Int, src::CodeInfo, spvals::SimpleVector
atyp = argextype(ex.args[3], src, spvals, slottypes)
return isknowntype(atyp) ? 4 : params.inline_nonleaf_penalty
end
fidx = findfirst(x->x===f, T_FFUNC_KEY)
fidx = find_tfunc(f)
if fidx === nothing
# unknown/unhandled builtin or anonymous function
# Use the generic cost of a direct function call
Expand Down
9 changes: 8 additions & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const T_IFUNC_COST = Vector{Int}(undef, N_IFUNC)
const T_FFUNC_KEY = Vector{Any}()
const T_FFUNC_VAL = Vector{Tuple{Int, Int, Any}}()
const T_FFUNC_COST = Vector{Int}()
function find_tfunc(@nospecialize f)
for i = 1:length(T_FFUNC_KEY)
if T_FFUNC_KEY[i] === f
return i
end
end
end

const DATATYPE_NAME_FIELDINDEX = fieldindex(DataType, :name)
const DATATYPE_PARAMETERS_FIELDINDEX = fieldindex(DataType, :parameters)
Expand Down Expand Up @@ -1248,7 +1255,7 @@ function builtin_tfunction(@nospecialize(f), argtypes::Array{Any,1},
end
tf = T_IFUNC[iidx]
else
fidx = findfirst(x->x===f, T_FFUNC_KEY)
fidx = find_tfunc(f)
if fidx === nothing
# unknown/unhandled builtin function
return Any
Expand Down

0 comments on commit 3aeccec

Please sign in to comment.