22
33abstract type MethodTableView; end
44
5- struct MethodLookupResult
6- # Really Vector{Core.MethodMatch}, but it's easier to represent this as
7- # and work with Vector{Any} on the C side.
8- matches:: Vector{Any}
9- valid_worlds:: WorldRange
10- ambig:: Bool
11- end
12- length (result:: MethodLookupResult ) = length (result. matches)
13- function iterate (result:: MethodLookupResult , args... )
14- r = iterate (result. matches, args... )
15- r === nothing && return nothing
16- match, state = r
17- return (match:: MethodMatch , state)
18- end
19- getindex (result:: MethodLookupResult , idx:: Int ) = getindex (result. matches, idx):: MethodMatch
20-
215"""
226 struct InternalMethodTable <: MethodTableView
237
@@ -39,19 +23,21 @@ struct OverlayMethodTable <: MethodTableView
3923 mt:: Core.MethodTable
4024end
4125
42- """
43- struct CachedMethodTable <: MethodTableView
44-
45- Overlays another method table view with an additional local fast path cache that
46- can respond to repeated, identical queries faster than the original method table.
47- """
48- struct CachedMethodTable{T} <: MethodTableView
49- cache:: IdDict{Any, Union{Missing, MethodLookupResult}}
50- table:: T
26+ struct MethodLookupResult
27+ # Really Vector{Core.MethodMatch}, but it's easier to represent this as
28+ # and work with Vector{Any} on the C side.
29+ matches:: Vector{Any}
30+ valid_worlds:: WorldRange
31+ ambig:: Bool
32+ end
33+ length (result:: MethodLookupResult ) = length (result. matches)
34+ function iterate (result:: MethodLookupResult , args... )
35+ r = iterate (result. matches, args... )
36+ r === nothing && return nothing
37+ match, state = r
38+ return (match:: MethodMatch , state)
5139end
52- CachedMethodTable (table:: T ) where T =
53- CachedMethodTable {T} (IdDict {Any, Union{Missing, MethodLookupResult}} (),
54- table)
40+ getindex (result:: MethodLookupResult , idx:: Int ) = getindex (result. matches, idx):: MethodMatch
5541
5642"""
5743 findall(sig::Type, view::MethodTableView; limit=typemax(Int))
@@ -91,13 +77,6 @@ function findall(@nospecialize(sig::Type), table::OverlayMethodTable; limit::Int
9177 return MethodLookupResult (ms:: Vector{Any} , WorldRange (_min_val[], _max_val[]), _ambig[] != 0 )
9278end
9379
94- function findall (@nospecialize (sig:: Type ), table:: CachedMethodTable ; limit:: Int = typemax (Int))
95- box = Core. Box (sig)
96- return get! (table. cache, sig) do
97- findall (box. contents, table. table; limit= limit)
98- end
99- end
100-
10180"""
10281 findsup(sig::Type, view::MethodTableView)::Union{Tuple{MethodMatch, WorldRange}, Nothing}
10382
@@ -121,10 +100,6 @@ function findsup(@nospecialize(sig::Type), table::InternalMethodTable)
121100 (result. method, WorldRange (min_valid[], max_valid[]))
122101end
123102
124- # This query is not cached
125- findsup (@nospecialize (sig:: Type ), table:: CachedMethodTable ) = findsup (sig, table. table)
126-
127103isoverlayed (:: MethodTableView ) = error (" unsatisfied MethodTableView interface" )
128104isoverlayed (:: InternalMethodTable ) = false
129105isoverlayed (:: OverlayMethodTable ) = true
130- isoverlayed (mt:: CachedMethodTable ) = isoverlayed (mt. table)
0 commit comments