Skip to content

Commit bca9e80

Browse files
committed
Merge pull request #11600 from yuyichao/code_typed-fix
Move code_typed and return_types out of inference
2 parents dcfcbea + 336282a commit bca9e80

File tree

2 files changed

+39
-41
lines changed

2 files changed

+39
-41
lines changed

base/inference.jl

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,44 +3269,6 @@ function replace_getfield!(ast, e::ANY, tupname, vals, sv, i0)
32693269
end
32703270
end
32713271

3272-
function code_typed(f, types::ANY; optimize=true)
3273-
types = to_tuple_type(types)
3274-
code_typed(call, Tuple{isa(f,Type)?Type{f}:typeof(f), types.parameters...}, optimize=optimize)
3275-
end
3276-
function code_typed(f::Function, types::ANY; optimize=true)
3277-
types = to_tuple_type(types)
3278-
asts = []
3279-
for x in _methods(f,types,-1)
3280-
linfo = func_for_method(x[3],types,x[2])
3281-
if optimize
3282-
(tree, ty) = typeinf(linfo, x[1], x[2], linfo, true, true)
3283-
else
3284-
(tree, ty) = typeinf_uncached(linfo, x[1], x[2], optimize=false)
3285-
end
3286-
if !isa(tree,Expr)
3287-
push!(asts, ccall(:jl_uncompress_ast, Any, (Any,Any), linfo, tree))
3288-
else
3289-
push!(asts, tree)
3290-
end
3291-
end
3292-
asts
3293-
end
3294-
3295-
function return_types(f, types::ANY)
3296-
types = to_tuple_type(types)
3297-
return_types(call, Tuple{isa(f,Type)?Type{f}:typeof(f), types.parameters...})
3298-
end
3299-
function return_types(f::Function, types::ANY)
3300-
types = to_tuple_type(types)
3301-
rt = []
3302-
for x in _methods(f,types,-1)
3303-
linfo = func_for_method(x[3],types,x[2])
3304-
(tree, ty) = typeinf(linfo, x[1], x[2])
3305-
push!(rt, ty)
3306-
end
3307-
rt
3308-
end
3309-
33103272
#tfunc(f,t) = methods(f,t)[1].func.code.tfunc
33113273

33123274
ccall(:jl_set_typeinf_func, Void, (Any,), typeinf_ext)

base/reflection.jl

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,45 @@ code_native(f::ANY, types::ANY) = code_native(STDOUT, f, types)
225225
code_native(io::IO, f::ANY, t::ANY) =
226226
code_native(io, call, tt_cons(isa(f, Type) ? Type{f} : typeof(f), t))
227227

228-
if isdefined(Core, :Inference) && not_int(is(current_module(), Core.Inference))
229-
code_typed(args...;kwargs...) = Core.Inference.code_typed(args...;kwargs...)
230-
return_types(args...;kwargs...) = Core.Inference.return_types(args...;kwargs...)
228+
function code_typed(f::Function, types::ANY; optimize=true)
229+
types = to_tuple_type(types)
230+
asts = []
231+
for x in _methods(f,types,-1)
232+
linfo = Core.Inference.func_for_method(x[3],types,x[2])
233+
if optimize
234+
(tree, ty) = Core.Inference.typeinf(linfo, x[1], x[2], linfo,
235+
true, true)
236+
else
237+
(tree, ty) = Core.Inference.typeinf_uncached(linfo, x[1], x[2],
238+
optimize=false)
239+
end
240+
if !isa(tree, Expr)
241+
push!(asts, ccall(:jl_uncompress_ast, Any, (Any,Any), linfo, tree))
242+
else
243+
push!(asts, tree)
244+
end
245+
end
246+
asts
247+
end
248+
249+
function code_typed(f, t::ANY; optimize=true)
250+
code_typed(call, tt_cons(isa(f, Type) ? Type{f} : typeof(f), t),
251+
optimize=optimize)
252+
end
253+
254+
function return_types(f::Function, types::ANY)
255+
types = to_tuple_type(types)
256+
rt = []
257+
for x in _methods(f,types,-1)
258+
linfo = Core.Inference.func_for_method(x[3],types,x[2])
259+
(tree, ty) = Core.Inference.typeinf(linfo, x[1], x[2])
260+
push!(rt, ty)
261+
end
262+
rt
263+
end
264+
265+
function return_types(f, t::ANY)
266+
return_types(call, tt_cons(isa(f, Type) ? Type{f} : typeof(f), t))
231267
end
232268

233269
function which(f::ANY, t::ANY)

0 commit comments

Comments
 (0)