Skip to content

Commit 887eec7

Browse files
committed
Move code_typed and return_types out of inference. Fix #11590
1 parent 6b94780 commit 887eec7

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
@@ -3276,44 +3276,6 @@ function replace_getfield!(ast, e::ANY, tupname, vals, sv, i0)
32763276
end
32773277
end
32783278

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

33193281
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
@@ -216,9 +216,45 @@ code_native(f::ANY, types::ANY) = code_native(STDOUT, f, types)
216216
code_native(io::IO, f::ANY, t::ANY) =
217217
code_native(io, call, tt_cons(isa(f, Type) ? Type{f} : typeof(f), t))
218218

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

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

0 commit comments

Comments
 (0)