Skip to content

Commit

Permalink
make edges word for method tables and sketch hasmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Jul 30, 2019
1 parent a4f17c1 commit 7d8510a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
12 changes: 2 additions & 10 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function store_backedges(frame::InferenceState)
toplevel = !isa(frame.linfo.def, Method)
if !toplevel && (frame.cached || frame.parent !== nothing)
caller = frame.result.linfo
for edges in frame.stmt_edges
for edges in (frame.stmt_edges..., frame.src.edges)
edges === nothing && continue
i = 1
while i <= length(edges)
Expand All @@ -191,15 +191,7 @@ function store_backedges(frame::InferenceState)
end
end
end
edges = frame.src.edges
if edges !== nothing
edges = edges::Vector{MethodInstance}
for edge in edges
@assert isa(edge, MethodInstance)
ccall(:jl_method_instance_add_backedge, Cvoid, (Any, Any), edge, caller)
end
frame.src.edges = nothing
end
frame.src.edges = nothing
end
end

Expand Down
19 changes: 16 additions & 3 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1239,9 +1239,22 @@ true
```
"""
function hasmethod(@nospecialize(f), @nospecialize(t); world=typemax(UInt))
t = to_tuple_type(t)
t = signature_type(f, t)
return ccall(:jl_gf_invoke_lookup, Any, (Any, UInt), t, world) !== nothing
hasmethod(f, to_tuple_type(t); world=world)
end

@generated function hasmethod(@nospecialize(f), @nospecialize(t::Type{<:Tuple}); world=typemax(UInt))
fi = fi.instance #TODO: make this work with constructors and functors.
typ = signature_type(fi, t)
method_exists_already = ccall(:jl_gf_invoke_lookup, Any, (Any, UInt), typ, world) !== nothing
method_exists_already && return true # We are done, it exists, no need to recompile ever
# except if it is deleted. TODO: deal with Base.delete_method

ci = CodeInfo(...[:(return false)]...) #TODO write this, should be trivial enough
ci.edges == nothing && (ci.edges = [])
mt = f.name.mt
push!(ci.edges, mt)
push!(ci.edges, typ)
return ci
end

function hasmethod(@nospecialize(f), @nospecialize(t), kwnames::Tuple{Vararg{Symbol}}; world=typemax(UInt))
Expand Down

0 comments on commit 7d8510a

Please sign in to comment.