Skip to content

Commit 9e81a75

Browse files
committed
merge MethodInfo and Method
MethodTable.defs is now a linked list of Method objects and MethodList now contains LambdaInfo specializations, not Methods
1 parent e607294 commit 9e81a75

16 files changed

+578
-525
lines changed

base/boot.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@
6565
# sparam_vals::SimpleVector
6666
# specTypes::Any
6767
# unspecialized::LambdaInfo
68-
# def::MethodInfo
68+
# def::Method
6969
# pure::Bool
7070
#end
7171

72-
#type MethodInfo
72+
#type Method
7373
# ast::Expr
74+
# sig::Type
75+
# tvars::Expr
7476
# sparam_syms::SimpleVector
7577
# tfunc
7678
# name::Symbol
@@ -82,6 +84,10 @@
8284
# line::Int32
8385
# called::Int32
8486
# pure::Bool
87+
# isstaged::Bool
88+
# va::Bool
89+
# invokes::Union{MethodTable,Void}
90+
# next::Union{Method,Void}
8591
#end
8692

8793
#abstract Ref{T}
@@ -138,7 +144,7 @@ export
138144
Tuple, Type, TypeConstructor, TypeName, TypeVar, Union, Void,
139145
SimpleVector, AbstractArray, DenseArray,
140146
# special objects
141-
Box, Function, Builtin, IntrinsicFunction, LambdaInfo, MethodInfo, Method, MethodTable,
147+
Box, Function, Builtin, IntrinsicFunction, LambdaInfo, MethodList, Method, MethodTable,
142148
Module, Symbol, Task, Array, WeakRef,
143149
# numeric types
144150
Number, Real, Integer, Bool, Ref, Ptr,
@@ -311,7 +317,7 @@ TypeVar(n::Symbol, lb::ANY, ub::ANY, b::Bool) =
311317
ccall(:jl_new_typevar_, Any, (Any, Any, Any, Any), n, lb::Type, ub::Type, b)::TypeVar
312318

313319
TypeConstructor(p::ANY, t::ANY) = ccall(:jl_new_type_constructor, Any, (Any, Any), p::SimpleVector, t::Type)
314-
LambdaInfo(ast::MethodInfo, sparam_vals::SimpleVector, specTypes::DataType) = ccall(:jl_new_lambda_info, Any, (Any, Any, Any), ast, sparam_vals, specTypes)
320+
LambdaInfo(ast::Method, sparam_vals::SimpleVector, specTypes::DataType) = ccall(:jl_new_lambda_info, Any, (Any, Any, Any), ast, sparam_vals, specTypes)
315321

316322
Void() = nothing
317323

base/inference.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ let stagedcache=Dict{Any,Any}()
651651
spvals = Any[env[i] for i = 2:2:length(env)]
652652
_any(sp -> isa(sp, TypeVar), spvals) && empty!(spvals)
653653
if !m.isstaged
654-
return LambdaInfo(m.func, svec(spvals...), tt)
654+
return LambdaInfo(m, svec(spvals...), tt)
655655
elseif haskey(stagedcache, (m, tt))
656656
return stagedcache[(m, tt)]
657657
else
@@ -661,7 +661,7 @@ let stagedcache=Dict{Any,Any}()
661661
# we can't guarantee that their type behavior is monotonic.
662662
return NF
663663
end
664-
f = ccall(:jl_instantiate_staged, Any, (Any, Any, Any), m.func, tt, env)
664+
f = ccall(:jl_instantiate_staged, Any, (Any, Any, Any), m, tt, env)
665665
f = LambdaInfo(f, svec(spvals...), tt)
666666
stagedcache[(m, tt)] = f
667667
return f
@@ -1384,7 +1384,7 @@ f_argnames(ast) =
13841384

13851385
is_rest_arg(arg::ANY) = (ccall(:jl_is_rest_arg,Int32,(Any,), arg) != 0)
13861386

1387-
function typeinf_ext(linfo::LambdaInfo, atypes::ANY, def::MethodInfo)
1387+
function typeinf_ext(linfo::LambdaInfo, atypes::ANY, def::Method)
13881388
global inference_stack
13891389
last = inference_stack
13901390
inference_stack = EmptyCallStack()
@@ -1394,7 +1394,7 @@ function typeinf_ext(linfo::LambdaInfo, atypes::ANY, def::MethodInfo)
13941394
end
13951395

13961396
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY) = typeinf(linfo,atypes,sparams,linfo.def,true,false)
1397-
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY,def::MethodInfo) = typeinf(linfo,atypes,sparams,def,true,false)
1397+
typeinf(linfo::LambdaInfo,atypes::ANY,sparams::ANY,def::Method) = typeinf(linfo,atypes,sparams,def,true,false)
13981398

13991399
CYCLE_ID = 1
14001400

@@ -1403,7 +1403,7 @@ CYCLE_ID = 1
14031403

14041404
# def is the original unspecialized version of a method. we aggregate all
14051405
# saved type inference data there.
1406-
function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::MethodInfo, cop, needtree)
1406+
function typeinf(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::Method, cop, needtree)
14071407
if def.module === Core && isempty(sparams) && isempty(linfo.sparam_vals)
14081408
atypes = Tuple
14091409
end
@@ -1484,7 +1484,7 @@ typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::ANY; optimize=true) =
14841484
tupletype_tail(t::ANY, n) = Tuple{t.parameters[n:end]...}
14851485

14861486
# compute an inferred (optionally optimized) AST without global effects (i.e. updating the cache)
1487-
function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::MethodInfo, curtype, cop, optimize)
1487+
function typeinf_uncached(linfo::LambdaInfo, atypes::ANY, sparams::SimpleVector, def::Method, curtype, cop, optimize)
14881488
ast0 = def.ast
14891489
#if dbg
14901490
# print("typeinf ", def.name, " ", object_id(ast0), "\n")
@@ -2298,7 +2298,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
22982298
if linfo === NF
22992299
return NF
23002300
end
2301-
methfunc = meth[3].func
2301+
methfunc = meth[3]
23022302
methsig = meth[3].sig
23032303
if !(atype <: metharg)
23042304
incompletematch = true
@@ -2346,7 +2346,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atype::ANY, sv::VarInfo, enclosing
23462346
# return NF
23472347
# end
23482348
# meth = meth[1]::Tuple
2349-
# linfo2 = meth[3].func.code
2349+
# linfo2 = meth[3].code
23502350
# if linfo2 !== linfo
23512351
# return NF
23522352
# end
@@ -3354,6 +3354,6 @@ function replace_getfield!(ast, e::ANY, tupname, vals, sv, i0)
33543354
end
33553355
end
33563356

3357-
#tfunc(f,t) = methods(f,t)[1].func.code.tfunc
3357+
#tfunc(f,t) = methods(f,t)[1].code.tfunc
33583358

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

base/interactiveutil.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function edit(path::AbstractString, line::Integer=0)
6565
end
6666

6767
function edit(m::Method)
68-
tv, decls, file, line = arg_decl_parts(m)
69-
edit(string(file), line)
68+
edit(string(m.file), m.line)
7069
end
7170

7271
edit(f) = edit(functionloc(f)...)
@@ -599,7 +598,7 @@ function summarysize(obj::MethodTable, seen, excl)
599598
return size
600599
end
601600

602-
function summarysize(m::Method, seen, excl)
601+
function summarysize(m::MethodList, seen, excl)
603602
size::Int = 0
604603
while true
605604
haskey(seen, m) ? (return size) : (seen[m] = true)
@@ -608,10 +607,8 @@ function summarysize(m::Method, seen, excl)
608607
size += summarysize(m.func, seen, excl)::Int
609608
end
610609
size += summarysize(m.sig, seen, excl)::Int
611-
size += summarysize(m.tvars, seen, excl)::Int
612-
size += summarysize(m.invokes, seen, excl)::Int
613610
m.next === nothing && break
614-
m = m.next::Method
611+
m = m.next::MethodList
615612
end
616613
return size
617614
end

base/methodshow.jl

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,50 @@ end
2828

2929
function arg_decl_parts(m::Method)
3030
tv = m.tvars
31-
if !isa(tv,SimpleVector)
31+
if !isa(tv, SimpleVector)
3232
tv = Any[tv]
3333
else
3434
tv = Any[tv...]
3535
end
36-
li = m.func
37-
e = uncompressed_ast(li)
36+
e = uncompressed_ast(m)
3837
argnames = e.args[1]
3938
s = symbol("?")
4039
decls = [argtype_decl(:tvar_env => tv, get(argnames,i,s), m.sig.parameters[i])
4140
for i = 1:length(m.sig.parameters)]
42-
return tv, decls, li.file, li.line
41+
return tv, decls
4342
end
4443

4544
function show(io::IO, m::Method)
46-
tv, decls, file, line = arg_decl_parts(m)
47-
ft = m.sig.parameters[1]
48-
d1 = decls[1]
49-
if ft <: Function &&
50-
isdefined(ft.name.module, ft.name.mt.name) &&
51-
ft == typeof(getfield(ft.name.module, ft.name.mt.name))
52-
print(io, ft.name.mt.name)
53-
elseif isa(ft, DataType) && is(ft.name, Type.name) && isleaftype(ft)
54-
f = ft.parameters[1]
55-
if isa(f, DataType) && isempty(f.parameters)
56-
print(io, f)
45+
if isdefined(m, :sig)
46+
tv, decls = arg_decl_parts(m)
47+
ft = m.sig.parameters[1]
48+
d1 = decls[1]
49+
if ft <: Function &&
50+
isdefined(ft.name.module, ft.name.mt.name) &&
51+
ft == typeof(getfield(ft.name.module, ft.name.mt.name))
52+
print(io, ft.name.mt.name)
53+
elseif isa(ft, DataType) && is(ft.name, Type.name) && isleaftype(ft)
54+
f = ft.parameters[1]
55+
if isa(f, DataType) && isempty(f.parameters)
56+
print(io, f)
57+
else
58+
print(io, "(", d1[1], "::", d1[2], ")")
59+
end
5760
else
5861
print(io, "(", d1[1], "::", d1[2], ")")
5962
end
63+
if !isempty(tv)
64+
show_delim_array(io, tv, '{', ',', '}', false)
65+
end
66+
print(io, "(")
67+
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls[2:end]],
68+
", ", ", ")
69+
print(io, ")")
6070
else
61-
print(io, "(", d1[1], "::", d1[2], ")")
62-
end
63-
if !isempty(tv)
64-
show_delim_array(io, tv, '{', ',', '}', false)
71+
print(io, m.name, "(?)")
6572
end
66-
print(io, "(")
67-
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls[2:end]],
68-
", ", ", ")
69-
print(io, ")")
70-
if line > 0
71-
print(io, " at ", file, ":", line)
73+
if m.line > 0
74+
print(io, " at ", m.file, ":", m.line)
7275
end
7376
end
7477

@@ -114,10 +117,10 @@ end
114117
fileurl(file) = let f = find_source_file(file); f === nothing ? "" : "file://"*f; end
115118

116119
function url(m::Method)
117-
M = m.func.module
118-
(m.func.file == :null || m.func.file == :string) && return ""
119-
file = string(m.func.file)
120-
line = m.func.line
120+
M = m.module
121+
(m.file == :null || m.file == :string) && return ""
122+
file = string(m.file)
123+
line = m.line
121124
line <= 0 || ismatch(r"In\[[0-9]+\]", file) && return ""
122125
if inbase(M)
123126
if isempty(Base.GIT_VERSION_INFO.commit)
@@ -149,39 +152,43 @@ function url(m::Method)
149152
end
150153

151154
function writemime(io::IO, ::MIME"text/html", m::Method)
152-
tv, decls, file, line = arg_decl_parts(m)
153-
ft = m.sig.parameters[1]
154-
d1 = decls[1]
155-
if ft <: Function &&
156-
isdefined(ft.name.module, ft.name.mt.name) &&
157-
ft == typeof(getfield(ft.name.module, ft.name.mt.name))
158-
print(io, ft.name.mt.name)
159-
elseif isa(ft, DataType) && is(ft.name, Type.name) && isleaftype(ft)
160-
f = ft.parameters[1]
161-
if isa(f, DataType) && isempty(f.parameters)
162-
print(io, f)
155+
if isdefined(m, :sig)
156+
tv, decls = arg_decl_parts(m)
157+
ft = m.sig.parameters[1]
158+
d1 = decls[1]
159+
if ft <: Function &&
160+
isdefined(ft.name.module, ft.name.mt.name) &&
161+
ft == typeof(getfield(ft.name.module, ft.name.mt.name))
162+
print(io, ft.name.mt.name)
163+
elseif isa(ft, DataType) && is(ft.name, Type.name) && isleaftype(ft)
164+
f = ft.parameters[1]
165+
if isa(f, DataType) && isempty(f.parameters)
166+
print(io, f)
167+
else
168+
print(io, "(", d1[1], "::<b>", d1[2], "</b>)")
169+
end
163170
else
164171
print(io, "(", d1[1], "::<b>", d1[2], "</b>)")
165172
end
173+
if !isempty(tv)
174+
print(io,"<i>")
175+
show_delim_array(io, tv, '{', ',', '}', false)
176+
print(io,"</i>")
177+
end
178+
print(io, "(")
179+
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::<b>"*d[2]*"</b>"
180+
for d in decls[2:end]], ", ", ", ")
181+
print(io, ")")
166182
else
167-
print(io, "(", d1[1], "::<b>", d1[2], "</b>)")
168-
end
169-
if !isempty(tv)
170-
print(io,"<i>")
171-
show_delim_array(io, tv, '{', ',', '}', false)
172-
print(io,"</i>")
173-
end
174-
print(io, "(")
175-
print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::<b>"*d[2]*"</b>"
176-
for d in decls[2:end]], ", ", ", ")
177-
print(io, ")")
178-
if line > 0
183+
print(io, m.name, "(?)")
184+
end
185+
if m.line > 0
179186
u = url(m)
180187
if isempty(u)
181-
print(io, " at ", file, ":", line)
188+
print(io, " at ", m.file, ":", m.line)
182189
else
183190
print(io, """ at <a href="$u" target="_blank">""",
184-
file, ":", line, "</a>")
191+
m.file, ":", m.line, "</a>")
185192
end
186193
end
187194
end

base/reflection.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ end
170170

171171
tt_cons(t::ANY, tup::ANY) = (@_pure_meta; Tuple{t, (isa(tup, Type) ? tup.parameters : tup)...})
172172

173-
code_lowered(f, t::ANY=Tuple) = map(m->uncompressed_ast(m.func), methods(f, t))
174-
function methods(f::ANY,t::ANY)
173+
code_lowered(f, t::ANY=Tuple) = map(m->uncompressed_ast(m), methods(f, t))
174+
function methods(f::ANY, t::ANY)
175175
if isa(f,Builtin)
176176
throw(ArgumentError("argument is not a generic function"))
177177
end
@@ -240,13 +240,13 @@ function length(mt::MethodTable)
240240
end
241241

242242
start(mt::MethodTable) = mt.defs
243-
next(mt::MethodTable, m::Method) = (m,m.next)
243+
next(mt::MethodTable, m::Method) = (m, m.next)
244244
done(mt::MethodTable, m::Method) = false
245245
done(mt::MethodTable, i::Void) = true
246246

247247
uncompressed_ast(l::LambdaInfo) =
248248
isa(l.inferred_ast,Expr) ? l.inferred_ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l.def, l.inferred_ast)
249-
uncompressed_ast(l::MethodInfo) =
249+
uncompressed_ast(l::Method) =
250250
isa(l.ast,Expr) ? l.ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l, l.ast)
251251

252252
# Printing code representations in IR and assembly
@@ -279,7 +279,7 @@ code_native(f::ANY, types::ANY=Tuple) = code_native(STDOUT, f, types)
279279

280280
# give a decent error message if we try to instantiate a staged function on non-leaf types
281281
function func_for_method_checked(m, types)
282-
linfo = Core.Inference.func_for_method(m[3],m[1],m[2])
282+
linfo = Core.Inference.func_for_method(m[3], m[1], m[2])
283283
if linfo === Core.Inference.NF
284284
error("cannot call @generated function `", m[3], "` ",
285285
"with abstract argument types: ", types)
@@ -348,12 +348,11 @@ function which_module(m::Module, s::Symbol)
348348
end
349349

350350
function functionloc(m::Method)
351-
lsd = m.func::MethodInfo
352-
ln = lsd.line
351+
ln = m.line
353352
if ln <= 0
354353
error("could not determine location of method definition")
355354
end
356-
(find_source_file(string(lsd.file)), ln)
355+
(find_source_file(string(m.file)), ln)
357356
end
358357

359358
functionloc(f::ANY, types::ANY) = functionloc(which(f,types))
@@ -377,7 +376,7 @@ function function_module(f, types::ANY)
377376
if isempty(m)
378377
error("no matching methods")
379378
end
380-
m[1].func.module
379+
m[1].module
381380
end
382381

383382
function method_exists(f::ANY, t::ANY)

0 commit comments

Comments
 (0)