Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get kwfuncs with Core.kwftype #47

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ os:
julia:
- 0.7
- 1.0
- 1.2 # first version supporting @snoopi
- 1.3
- nightly
notifications:
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1.0
- julia_version: 1.2 # first version supporting @snoopi
- julia_version: 1
- julia_version: nightly

Expand Down
17 changes: 14 additions & 3 deletions src/SnoopCompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ function extract_topmod(e)
return :unknown
end

const anonrex = r"#{1,2}\d+#{1,2}\d+" # detect anonymous functions
const anonrex = r"#{1,2}\d+#{1,2}\d+" # detect anonymous functions
const kwrex = r"^#kw##(.*)$|#([^#]*)##kw$" # detect keyword-supplying functions

function parse_call(line; subst=Vector{Pair{String, String}}(), blacklist=String[])
match(anonrex, line) === nothing || return false, line, :unknown, ""
Expand Down Expand Up @@ -294,7 +295,17 @@ function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=
ok || continue
topmod = topmodule(mods)
topmod === nothing && continue
ttrepr = repr(tt)
paramrepr = map(tt.parameters) do p
mkw = match(kwrex, String(p.name.name))
if mkw !== nothing
fname = mkw.captures[1] === nothing ? mkw.captures[2] : mkw.captures[1]
thismod = p.name.module
"Core.kwftype(typeof($thismod.$fname))"
else
repr(p)
end
end
ttrepr = "Tuple{" * join(paramrepr, ',') * '}'
ttexpr = Meta.parse(ttrepr)
try
Core.eval(topmod, ttexpr)
Expand All @@ -305,7 +316,7 @@ function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=
if !haskey(pc, topmodname)
pc[topmodname] = String[]
end
push!(pc[topmodname], "precompile(" * repr(tt) * ')')
push!(pc[topmodname], "precompile(" * ttrepr * ')')
end
return pc
end
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ if VERSION >= v"1.2.0-DEV.573"
directive = pc[:A][1]
@test occursin("C.CT", directive)
@test !occursin("E.ET", directive)

# Identify kwfuncs, whose naming depends on the Julia version (issue #46)
tinf = @snoopi sortperm(rand(5); rev=true)
pc = SnoopCompile.parcel(tinf)
@test any(str->occursin("kwftype", str), pc[:Base])
end
""")

Expand Down