Skip to content

Commit de8b0d6

Browse files
authored
Merge pull request #212 from timholy/teh/various_fixes
A grabbag of random fixes
2 parents 1851f20 + fb4c0aa commit de8b0d6

5 files changed

Lines changed: 20 additions & 13 deletions

File tree

examples/OptimizeMe.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module OptimizeMe
88
struct Container{T}
99
value::T
1010
end
11+
1112
concat_string(c1::Container, c2::Container) = string(c1.value) * ' ' * string(c2.value)
1213

1314
function contain_concrete(item1, item2)
@@ -31,7 +32,6 @@ end
3132
struct Object
3233
x::Int
3334
end
34-
Base.show(io::IO, o::Object) = print(io, "Object x: ", o.x)
3535

3636
function makeobjects()
3737
xs = [1:5; 7]

src/parcel_snoopi.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ let known_type_cache = IdDict{Tuple{Module,Tuple{Vararg{Symbol}},Symbol},Bool}()
214214
strippedname(tn::Core.TypeName) = Symbol(string(tn.name)[2:end])
215215

216216
T === Union{} && return true
217+
T = Base.unwrap_unionall(T)
217218
if isa(T, Union)
218219
return known_type(mod, T.a) & known_type(mod, T.b)
219220
end
220-
T = Base.unwrap_unionall(T)::DataType
221+
T = T::DataType
221222
tn = T.name
222223
tpath = fullname(tn.module)
223224
key = (mod, tpath, tn.name)

src/parcel_snoopi_deep.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,11 @@ function maybe_internal(itrig::InferenceTrigger)
668668
if isa(linfo, MethodInstance)
669669
m = linfo.def
670670
if isa(m, Method)
671-
m.module === Base && m.name === :include_string && return false
671+
if m.module === Base
672+
m.name === :include_string && return false
673+
m.name === :_include_from_serialized && return false
674+
m.name === :return_types && return false # from `@inferred`
675+
end
672676
m.name === :eval && return false
673677
end
674678
end
@@ -747,9 +751,11 @@ function skiphigherorder(itrig::InferenceTrigger; exact::Bool=true)
747751
ft = Base.unwrap_unionall(Base.unwrap_unionall(MethodInstance(itrig.node).specTypes).parameters[1])
748752
sfs, idx = itrig.callerframes, itrig.btidx
749753
while idx < length(itrig.node.bt)
750-
callermi = sfs[end].linfo
751-
if !hasparameter(callermi.specTypes, ft, exact)
752-
return InferenceTrigger(itrig.node, sfs, idx)
754+
if !isempty(sfs)
755+
callermi = sfs[end].linfo
756+
if !hasparameter(callermi.specTypes, ft, exact)
757+
return InferenceTrigger(itrig.node, sfs, idx)
758+
end
753759
end
754760
ret = next_julia_frame(itrig.node.bt, idx)
755761
ret === nothing && return InferenceTrigger(itrig.node, sfs, idx)
@@ -905,8 +911,8 @@ The empty horizontal periods in the flamegraph correspond to times when somethin
905911
The total width of the flamegraph is set from the `ROOT` node.
906912
"""
907913
function FlameGraphs.flamegraph(tinf::InferenceTimingNode; tmin = 0.0, excluded_modules=Set([Main::Module]), mode=nothing)
914+
isROOT(tinf) && isempty(tinf.children) && error("root node has no children")
908915
io = IOBuffer()
909-
910916
# Compute a "root" frame for the top-level node, to cover the whole profile
911917
node_data, _ = _flamegraph_frame(io, tinf, tinf.start_time, true, excluded_modules, mode; toplevel=true)
912918
root = Node(node_data)

test/snoopi_deep.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ end
329329
tinf_spec = @snoopi_deep SnoopBench.mappushes(SnoopBench.spell_spec, Ts)
330330
tf_unspec = flatten(tinf_unspec)
331331
tf_spec = flatten(tinf_spec)
332-
@test length(tf_unspec) < 10
332+
@test length(tf_unspec) < length(Ts) ÷ 5
333333
@test any(tmi -> occursin("spell_unspec(::Any)", repr(MethodInstance(tmi))), tf_unspec)
334334
@test length(tf_spec) >= length(Ts)
335335
@test !any(tmi -> occursin("spell_spec(::Any)", repr(MethodInstance(tmi))), tf_unspec)
@@ -364,8 +364,8 @@ end
364364
@test tiunspec < tispec/10
365365
@test trunspec < 10*trspec
366366
@test nunspec == 1
367-
# Test that no runtime dispatch occurs in mappushes!
368-
trmp, trtdmp, _, _ = rit[findfirst(pr -> pr.first == mp, rit)].second
369-
@test trtdmp == 0
367+
# Test that little runtime dispatch occurs in mappushes!
368+
_, trtdmpu, _, _ = rit[findfirst(pr -> pr.first == mp, rit)].second
369+
@test trtdmpu < trtdmp/10
370370
# specialization_plot(axs[2], rit; bystr="Inclusive", consts=true, interactive=false)
371371
end

test/testmodules/SnoopBench.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ mappushes3(@nospecialize(f), src) = mappushes3!(f, [], src)
2626
function spell_spec(::Type{T}) where T
2727
name = Base.unwrap_unionall(T).name.name
2828
str = ""
29-
for c in str
29+
for c in string(name)
3030
str *= c
3131
end
3232
return str
3333
end
3434
function spell_unspec(@nospecialize(T))
3535
name = Base.unwrap_unionall(T).name.name
3636
str = ""
37-
for c in str
37+
for c in string(name)
3838
str *= c
3939
end
4040
return str

0 commit comments

Comments
 (0)