timholy / SnoopCompile.jl

Provide insights about latency (TTFX) for Julia packages
https://timholy.github.io/SnoopCompile.jl/dev/
Other
309 stars 48 forks source link

Evaluation of the precompile signatures in `Core` #76

Closed aminya closed 4 years ago

aminya commented 4 years ago

I solved the issue of precompiling the Pkg sentences by using Base.precompile. However, running the snoopi_bot with the exhaustive feature enabled on Zygote generates some strange errors that: Base not defined.

https://github.com/aminya/SnoopCompile.jl/blob/a8854d2a33ecaa280a3b6f78cd4d02ee9b77c233/src/parcel_snoopi.jl#L345-L357

This happens when if I copy-paste the sentence in REPL (without Meta.parse) it works fine. For example:

# Works:
Base.precompile(Tuple{Type{NamedTuple{(:bc,),T} where T<:Tuple},Tuple{NamedTuple{(:f, :args, :axes),Tuple{Nothing,Tuple{Nothing,Tuple{Nothing,Float64,Float64,Float64,Float64,Float64},Nothing},Nothing}}}})

# Errors:
Core.eval(Core, Meta.parse("Base.precompile(Tuple{Type{NamedTuple{(:bc,),T} where T<:Tuple},Tuple{NamedTuple{(:f, :args, :axes),Tuple{Nothing,Tuple{Nothing,Tuple{Nothing,Float64,Float64,Float64,Float64,Float64},Nothing},Nothing}}}})")  )
Some of the warnings: ```jl ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:bc,),T} where T<:Tuple},Tuple{NamedTuple{(:f, :args, :axes),Tuple{Nothing,Tuple{Nothing,Tuple{Nothing,Float64,Float64,Float64,Float64,Float64},Nothing},Nothing}}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:f, :iter),T} where T<:Tuple},Tuple{NamedTuple{(:t,),Tuple{Tuple{Int64,Int64,Nothing}}},Array{Nothing,1}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:condition, :args),T} where T<:Tuple},Tuple{Nothing,Array{Nothing,1}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:x, :y),T} where T<:Tuple},Tuple{Int64,Float64}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:condition, :args),T} where T<:Tuple},Tuple{Nothing,Array{Float64,1}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{typeof(Core.Compiler.eltype),Type{Array{Int64,0}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{Array{Tuple{Function,Array{T,2} where T,Array{T,2} where T,Any,Int64,Array{T,2} where T},1}},UndefInitializer,Int64}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{typeof(Core.Compiler.eltype),Type{Array{Int64,2}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{typeof(Core.Compiler.eltype),Type{Array{Float64,2}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{typeof(Core.Compiler.eltype),Type{Array{Array{Float64,2},1}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{typeof(Core.Compiler.eltype),Type{Array{Array{Float64,1},1}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:bc,),T} where T<:Tuple},Tuple{NamedTuple{(:f, :args, :axes),Tuple{Nothing,Tuple{Tuple{Array{Float64,2},Array{Float64,2}}},Nothing}}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:f, :args, :axes),T} where T<:Tuple},Tuple{Nothing,Tuple{Tuple{Array{Float64,2},Array{Float64,2}}},Nothing}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:diag,),T} where T<:Tuple},Tuple{Array{Float64,1}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:factors,),T} where T<:Tuple},Tuple{Array{Float64,2}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ┌ Warning: Faulty precompile sentence: Base.precompile(Tuple{Type{NamedTuple{(:expr,),T} where T<:Tuple},Tuple{Tuple{Symbol,Symbol,Symbol}}}) │ exception = UndefVarError: Base not defined └ @ Core precompile_Core.jl:1 ```
aminya commented 4 years ago

I realized that evaluating the sentences in some other module like Main or Base doesn't generate the error.

# works
Core.eval(Main, Meta.parse("Base.precompile(Tuple{Type{NamedTuple{(:bc,),T} where T<:Tuple},Tuple{NamedTuple{(:f, :args, :axes),Tuple{Nothing,Tuple{Nothing,Tuple{Nothing,Float64,Float64,Float64,Float64,Float64},Nothing},Nothing}}}})")  )

Does this mean that we should evaluate Core precompile signatures in Main instead?

aminya commented 4 years ago

84 Now adds this to can_eval