diff --git a/src/utils.jl b/src/utils.jl index e23354743..77b19a073 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -223,3 +223,19 @@ function split2(str, on) return (SubString(str, firstindex(str), prevind(str, first(i))), SubString(str, nextind(str, last(i)))) end + +function methods_with_generators(m::Module) + meths = Method[] + for name in names(m; all=true) + isdefined(m, name) || continue + f = getfield(m, name) + if isa(f, Function) + for method in methods(f) + if isdefined(method, :generator) + push!(meths, method) + end + end + end + end + return meths +end diff --git a/test/snoop_inference.jl b/test/snoop_inference.jl index 356534f80..6df6a001b 100644 --- a/test/snoop_inference.jl +++ b/test/snoop_inference.jl @@ -705,6 +705,10 @@ end @test SnoopCompile.itrigs_higherorder_demo() isa SnoopCompile.InferenceTimingNode end +# must be outside @testset +@generated gen407(x) = x <: Integer ? :(x^2) : :(-x) +callgen407(x) = gen407(x) + include("testmodules/SnoopBench.jl") @testset "parcel" begin a = SnoopBench.A() @@ -784,6 +788,13 @@ include("testmodules/SnoopBench.jl") g197(@nospecialize(x::Vector{<:Number})) = f197(x) g197([1,2,3]) @test SnoopCompile.get_reprs([(rand(), mi) for mi in methodinstances(f197)])[1] isa AbstractSet + + # issue #407 + tinf = @snoop_inference callgen407(3) + tinft = flatten(tinf; tmin=0) + tmi = [(inclusive(inft), Core.MethodInstance(inft)) for inft in tinft] + strs, twritten = SnoopCompile.get_reprs(tmi; tmin=0) + @test any(str -> occursin("which(gen407,(Any,)).generator", str), strs) end @testset "Specialization" begin