Does Revise/CodeTracking work with PrecompileTools

I can’t seem to get things to precompile for my package when I try to use CodeTracking.

@setup_workload begin
    # Putting some things in `@setup_workload` instead of `@compile_workload` can reduce the size of the
    # precompile file and potentially make loading faster.
    using Revise
    using CodeTracking
    using TestHandcalcFunctions

    @compile_workload begin
        
        f = @code_expr calc_Ix(5, 15)
        println(f)

        @handcalcs begin
            I_x = calc_Ix(5,15)
        end

    end
end

So the f = @code_expr calc_Ix(5, 15) should return the function. However, it returns nothing when under precompile workload. I assume there are some tricky things going on in PrecompileTools but I am not really sure what I can do to get CodeTracking to work inside of a precompile workload.

Any thoughts?

Does that not error? I’d expect the other macro calls in the @setup_workload expression to expand before the final expression evaluates to import all the prerequisite packages.

Only that @handcalcs part errors I think (due to it getting nothing found for calc_Ix). @code_expr doesn’t error. It just returns nothing

Do you have the error message, or the wider printout of your precompilation attempt? Setting PrecompileTools.verbose[] = true might help.

julia> using Handcalcs
Precompiling Handcalcs...
Info Given Handcalcs was explicitly requested, output will be shown live
ERROR: LoadError: type Nothing has no field args
Stacktrace:
  [1] getproperty
    @ .\Base.jl:49 [inlined]
  [2] handfunc(found_module::Module, found_func::Nothing, func_args::Expr, kwargs::Tuple{Expr})
    @ Handcalcs C:\Users\c-mil\.julia\dev\Handcalcs\src\handfunc_macro.jl:54
  [3] macro expansion
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\handfunc_macro.jl:36 [inlined]
  [4] macro expansion
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:42 [inlined]
  [5] macro expansion
    @ C:\Users\c-mil\.julia\packages\PrecompileTools\L8A3n\src\workloads.jl:78 [inlined]
  [6] macro expansion
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:16 [inlined]
  [7] macro expansion
    @ C:\Users\c-mil\.julia\packages\PrecompileTools\L8A3n\src\workloads.jl:140 [inlined]
  [8] top-level scope
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:139
  [9] include(mod::Module, _path::String)
    @ Base .\Base.jl:562
 [10] include(x::String)
    @ Handcalcs C:\Users\c-mil\.julia\dev\Handcalcs\src\Handcalcs.jl:1
 [11] top-level scope
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\Handcalcs.jl:52
 [12] include
    @ .\Base.jl:562 [inlined]
 [13] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base .\loading.jl:2881
 [14] top-level scope
    @ stdin:6
in expression starting at C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:4
in expression starting at C:\Users\c-mil\.julia\dev\Handcalcs\src\Handcalcs.jl:1
in expression starting at stdin:6
  ✗ Handcalcs
  0 dependencies successfully precompiled in 6 seconds. 29 already precompiled.

ERROR: The following 1 direct dependency failed to precompile:

Handcalcs

Failed to precompile Handcalcs [e8a07092-c156-4455-ab8e-ed8bc81edefb] to "C:\\Users\\c-mil\\.julia\\compiled\\v1.11\\Handcalcs\\jl_B47C.tmp".
ERROR: LoadError: type Nothing has no field args
Stacktrace:
  [1] getproperty
    @ .\Base.jl:49 [inlined]
  [2] handfunc(found_module::Module, found_func::Nothing, func_args::Expr, kwargs::Tuple{Expr})
    @ Handcalcs C:\Users\c-mil\.julia\dev\Handcalcs\src\handfunc_macro.jl:54
  [3] macro expansion
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\handfunc_macro.jl:36 [inlined]
  [4] macro expansion
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:42 [inlined]
  [5] macro expansion
    @ C:\Users\c-mil\.julia\packages\PrecompileTools\L8A3n\src\workloads.jl:78 [inlined]
  [6] macro expansion
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:16 [inlined]
  [7] macro expansion
    @ C:\Users\c-mil\.julia\packages\PrecompileTools\L8A3n\src\workloads.jl:140 [inlined]
  [8] top-level scope
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:139
  [9] include(mod::Module, _path::String)
    @ Base .\Base.jl:562
 [10] include(x::String)
    @ Handcalcs C:\Users\c-mil\.julia\dev\Handcalcs\src\Handcalcs.jl:1
 [11] top-level scope
    @ C:\Users\c-mil\.julia\dev\Handcalcs\src\Handcalcs.jl:52
 [12] include
    @ .\Base.jl:562 [inlined]
 [13] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base .\loading.jl:2881
 [14] top-level scope
    @ stdin:6
in expression starting at C:\Users\c-mil\.julia\dev\Handcalcs\src\precompile.jl:4
in expression starting at C:\Users\c-mil\.julia\dev\Handcalcs\src\Handcalcs.jl:1
in expression starting at stdin:

Not sure if this helps. The ERROR: LoadError: type Nothing has no field args just means @code_expr found nothing and @handcalcs will error as a result. Nothing is really wrong, it is just code_expr isn’t finding anything.

I will get that error if a function I am trying to find isn’t able to be tracked by revise. So if I define a function that isn’t in a module for instance (if a function is defined in the repl it works since I guess there is a history revise can look at), code_expr wont find it and I will get that error in the @handcalcs macro.

It at least helped me know it was Handcalcs.jl so I could look at the source code. It also cleared up my confusion over the macro calls: 1) using CodeTracking, Revise already ran in the Handcalcs module by the time you try precompiling at the end so the macro calls do exist, 2) @handcalcs itself calls @code_expr for the problematic found_func::Nothing argument of the handfunc call; the visibly unrelated f = @code_expr ... is actually unrelated to the error. You really shouldn’t rely on import statements like using TestHandcalcFunctions only being in @setup_workload, though you might get away with it because code_expr only handles calc_Ix at execution.

This CodeTracking.definition(::Type{Expr},...) method seems to be the source of the nothing, if I’m following the @code_expr macro right. The failure would likely be Base.invokelatest(f, method), which is intended to call Revise.get_def(method) on the calc_Ix(b, h) method to populate a CodeTracking.method_info cache. f would be nothing if Revise.__init__ didn’t run, which would make invokelatest error, so it’s likely get_def did exist and failed. Not sure where the failure occurs though, it doesn’t happen in the REPL so I can’t (or rather don’t know how to) step through it.

julia> using PrecompileTools, Revise, CodeTracking, Handcalcs, TestHandcalcFunctions

julia> PrecompileTools.verbose[]=true #=outside precompilation=#; @setup_workload begin
           # Putting some things in `@setup_workload` instead of `@compile_workload` can reduce the size of the
           # precompile file and potentially make loading faster.
           using Revise
           using CodeTracking
           using TestHandcalcFunctions

           @compile_workload begin

               f = @code_expr calc_Ix(5, 15)
               println(f)

               @handcalcs begin
                   I_x = calc_Ix(5,15)
               end

           end
       end
function calc_Ix(b, h)
    #= C:\Users\Benny\.julia\packages\TestHandcalcFunctions\uROfE\src\TestHandcalcFunctions.jl:6 =#
    #= C:\Users\Benny\.julia\packages\TestHandcalcFunctions\uROfE\src\TestHandcalcFunctions.jl:7 =#
    Ix = (b * h ^ 3) / 12
    #= C:\Users\Benny\.julia\packages\TestHandcalcFunctions\uROfE\src\TestHandcalcFunctions.jl:8 =#
    return Ix
end
MethodInstance for code_expr(::Function, ::Type)
MethodInstance for Revise.get_def(::Method)
MethodInstance for BoundsError(::Any, ::Int64)
MethodInstance for BoundsError(::Any, ::Int64)
MethodInstance for append!(::Vector{JuliaInterpreter.BreakpointRef}, ::Union{Tuple, AbstractVector{<:JuliaInterpreter.BreakpointRef}})
MethodInstance for append!(::Vector{JuliaInterpreter.BreakpointRef}, ::Any)
MethodInstance for match(::Regex, ::Base.AnnotatedString)
MethodInstance for match(::Regex, ::AbstractString)
MethodInstance for getproperty(::Core.SSAValue, ::Symbol)
MethodInstance for getproperty(::Core.SlotNumber, ::Symbol)
MethodInstance for getproperty(::JuliaInterpreter.SSAValue, ::Symbol)
MethodInstance for getproperty(::JuliaInterpreter.SlotNumber, ::Symbol)
MethodInstance for (::Colon)(::Int64, ::Int64)
MethodInstance for (::Colon)(::Int64, ::Int64)
MethodInstance for getproperty(::GlobalRef, ::Symbol)
MethodInstance for (NamedTuple{(:mode,)})(::Tuple{Symbol})
MethodInstance for setindex!(::Dict{Base.PkgId, CodeTracking.PkgFiles}, ::Any, ::Base.PkgId)
MethodInstance for isequal(::QuoteNode, ::QuoteNode)
MethodInstance for hash(::QuoteNode, ::UInt64)
MethodInstance for Base.typename(::DataType)
MethodInstance for Revise.var"#_methods_by_execution!#24"(::Symbol, ::Bool, ::typeof(Revise._methods_by_execution!), ::JuliaInterpreter.NonRecursiveInterpreter, ::Revise.CodeTrackingMethodInfo, ::JuliaInterpreter.Frame, ::Vector{Bool})
MethodInstance for get!(::Type{Vector{Tuple{LineNumberNode, Expr}}}, ::IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}, ::Any)
MethodInstance for LoweredCodeUtils.set_to_running_name!(::JuliaInterpreter.NonRecursiveInterpreter, ::Dict{GlobalRef, GlobalRef}, ::JuliaInterpreter.Frame, ::Dict{GlobalRef, LoweredCodeUtils.MethodInfo}, ::LoweredCodeUtils.SelfCall, ::Dict{GlobalRef, Union{Nothing, Bool, GlobalRef}}, ::GlobalRef, ::Any)
MethodInstance for println(::Expr)
MethodInstance for print(::IO, ::Expr)
MethodInstance for Base.show_unquoted(::IOContext, ::Expr, ::Int64, ::Int64)
MethodInstance for print(::IOContext, ::String, ::Any, ::String)
MethodInstance for Base.show_enclosed_list(::IOContext, ::Char, ::Vector{Any}, ::String, ::Char, ::Int64, ::Int64, ::Int64, ::Bool)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::String, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool)
MethodInstance for Base.show_unquoted_expr_fallback(::IOContext, ::Expr, ::Int64, ::Int64)
MethodInstance for show(::IOContext, ::Symbol)
MethodInstance for Base.show_enclosed_list(::IOContext, ::Char, ::Vector{Any}, ::Symbol, ::Char, ::Int64, ::Int64, ::Int64, ::Bool)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::Symbol, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::String, ::Int64, ::Int64, ::Int64, ::Bool)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::Symbol, ::Int64, ::Int64, ::Int64, ::Bool)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::String, ::Int64, ::Int64, ::Int64)
MethodInstance for BoundsError(::Any, ::Int64)
MethodInstance for Base.show_enclosed_list(::IOContext, ::Char, ::Vector{Expr}, ::String, ::Char, ::Int64, ::Int64)
MethodInstance for Base.show_list(::IOContext, ::Vector{Expr}, ::String, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool)
MethodInstance for Base.show_enclosed_list(::IOContext, ::Char, ::Vector{Symbol}, ::String, ::Char, ::Int64, ::Int64)
MethodInstance for Base.show_list(::IOContext, ::Vector{Symbol}, ::String, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool)
MethodInstance for Base.show_unquoted(::IOContext, ::Symbol, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_call(::IOContext, ::Symbol, ::Any, ::Vector{Any}, ::Int64, ::Int64, ::Bool)
MethodInstance for BoundsError(::Any, ::Int64)
MethodInstance for Base.show_enclosed_list(::IOContext, ::Char, ::Vector{Any}, ::String, ::Char, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_enclosed_list(::IOContext, ::Char, ::Vector{Any}, ::String, ::Char, ::Int64, ::Int64)
MethodInstance for Base.show_call(::IOContext, ::Symbol, ::Symbol, ::Vector{Any}, ::Int64, ::Int64, ::Bool)
MethodInstance for Base.show_enclosed_list(::IOContext, ::String, ::Vector{Any}, ::String, ::String, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_generator(::IOContext, ::Expr, ::Int64, ::Int64)
MethodInstance for Base.show_list(::IOContext, ::Any, ::String, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::Symbol, ::Expr, ::Any, ::Int64, ::Int64)
MethodInstance for print(::IOContext, ::Symbol, ::Char)
MethodInstance for Base.show_unquoted(::IOContext, ::Any)
MethodInstance for Base.show_block(::IOContext, ::Symbol, ::Vector, ::Any, ::Int64, ::Int64)
MethodInstance for Base.show_list(::IOContext, ::Vector, ::String, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::Symbol, ::Any, ::Any, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::Symbol, ::Vector, ::Expr, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::Symbol, ::Any, ::Expr, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::String, ::Any, ::Int64, ::Int64)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::Char, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_list(::IOContext, ::Vector{Any}, ::String, ::Int64)
MethodInstance for BoundsError(::Any, ::Int64)
MethodInstance for Base.escape_raw_string(::IOContext, ::AbstractString)
MethodInstance for print(::IOContext, ::Any, ::Char)
MethodInstance for Core.kwcall(::@NamedTuple{allow_macroname::Bool}, ::typeof(Base.show_globalref), ::IOContext, ::GlobalRef)
MethodInstance for Base.show_unquoted(::IOContext, ::GlobalRef)
MethodInstance for Base.show_unquoted(::IOContext, ::Symbol)
MethodInstance for Base.show_linenumber(::IOContext, ::Any, ::Nothing)
MethodInstance for Base.show_linenumber(::IOContext, ::Any, ::Any)
MethodInstance for Base.show_block(::IOContext, ::String, ::Vector, ::Expr, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::String, ::Any, ::Expr, ::Int64, ::Int64)
MethodInstance for Base.show_block(::IOContext, ::String, ::Expr, ::Int64, ::Int64)
MethodInstance for print(::IOContext, ::Int64)
MethodInstance for show(::IOContext, ::Int64)
MethodInstance for escape_string(::IOContext, ::String, ::String)
MethodInstance for print(::IOContext, ::Char, ::Char)
MethodInstance for Base.show_import_path(::IOContext, ::Any, ::Int64)
MethodInstance for println(::Base.TTY, ::Expr)
MethodInstance for Base.show_block(::IOContext{Base.TTY}, ::Symbol, ::Expr, ::Expr, ::Int64, ::Int64)
MethodInstance for Base.show_unquoted(::IOContext{Base.TTY}, ::LineNumberNode, ::Int64, ::Int64, ::Int64)
MethodInstance for Base.show_unquoted(::IOContext{Base.TTY}, ::Int64, ::Int64, ::Int64, ::Int64)
MethodInstance for Handcalcs.is_show_funcs_on(::Tuple{Expr})
MethodInstance for Handcalcs.handfunc(::Module, ::Expr, ::Expr, ::Tuple{Expr})
MethodInstance for Base._any_tuple(::Function, ::Bool)
MethodInstance for print(::IOContext{IOBuffer}, ::Base.AnnotatedChar)
MethodInstance for write(::IOContext{IOBuffer}, ::Base.AnnotatedChar)
MethodInstance for print(::IOContext{IOBuffer}, ::Union{Base.AnnotatedString, SubString{<:Base.AnnotatedString}})
MethodInstance for StyledStrings._ansi_writer(::IOContext{IOBuffer}, ::Base.AnnotatedString, ::typeof(print))
MethodInstance for getproperty(::Base.AnnotatedString, ::Symbol)
MethodInstance for print(::IOContext{IOBuffer}, ::SubString{<:Base.AnnotatedString})
MethodInstance for StyledStrings._ansi_writer(::IOContext{IOBuffer}, ::SubString{<:Base.AnnotatedString}, ::typeof(print))
MethodInstance for getproperty(::SubString{<:Base.AnnotatedString}, ::Symbol)
MethodInstance for getproperty(::Base.AnnotatedString, ::Symbol)
MethodInstance for getproperty(::SubString{<:Base.AnnotatedString}, ::Symbol)
MethodInstance for getproperty(::SubString{<:Base.AnnotatedString}, ::Symbol)
MethodInstance for print(::IOBuffer, ::Union{Base.AnnotatedString, SubString{<:Base.AnnotatedString}})
MethodInstance for StyledStrings._ansi_writer(::IOBuffer, ::Base.AnnotatedString, ::typeof(print))
MethodInstance for getproperty(::Base.AnnotatedString, ::Symbol)
MethodInstance for Base.Broadcast.materialize(::Base.Broadcast.Broadcasted{Style, Nothing, typeof(Base.wrap_string)} where Style<:Union{Nothing, Base.Broadcast.BroadcastStyle})
MethodInstance for AbstractTrees.TreeCursor(::Any)
MethodInstance for descendleft(::Any)
MethodInstance for unsafe_copyto!(::GenericMemoryRef{:not_atomic, AbstractTrees.StableNode{_A}, Core.AddrSpace{Core}(0x00)}, ::GenericMemoryRef{:not_atomic, AbstractTrees.StableNode{_A}, Core.AddrSpace{Core}(0x00)}, ::Int64) where _A
MethodInstance for unsafe_copyto!(::GenericMemoryRef, ::GenericMemoryRef{:not_atomic, AbstractTrees.StableNode{_A}, Core.AddrSpace{Core}(0x00)} where _A, ::Int64)
MethodInstance for unsafe_copyto!(::GenericMemory{:not_atomic, AbstractTrees.StableNode{_A}, Core.AddrSpace{Core}(0x00)}, ::Int64, ::GenericMemory{:not_atomic, AbstractTrees.StableNode{_A}, Core.AddrSpace{Core}(0x00)}, ::Int64, ::Int64) where _A
MethodInstance for unsafe_copyto!(::Memory, ::Int64, ::GenericMemory{:not_atomic, AbstractTrees.StableNode{_A}, Core.AddrSpace{Core}(0x00)} where _A, ::Int64, ::Int64)
MethodInstance for setindex!(::Memory, ::AbstractTrees.StableNode, ::Int64)
MethodInstance for (::Handcalcs.var"#21#22"{String})(::Any)
MethodInstance for setindex!(::Dict{Any, Any}, ::Any, ::Any)
MethodInstance for count(::Function, ::Tuple{Bool, Bool})
MethodInstance for Base.mapfoldl_impl(::Base.var"#363#364"{<:Function}, ::typeof(Base.add_sum), ::Int64, ::Tuple{Bool, Bool})
MethodInstance for Base.foldl_impl(::Any, ::Int64, ::Tuple{Bool, Bool})
MethodInstance for Base._foldl_impl(::Any, ::Int64, ::Tuple{Bool, Bool})
MethodInstance for Base.afoldl(::Any, ::Int64, ::Bool, ::Bool)
MethodInstance for Base.var"#mapfoldl#337"(::Int64, ::typeof(mapfoldl), ::Function, ::Function, ::Tuple{Bool, Bool})
MethodInstance for Base.mapfoldl_impl(::Function, ::Function, ::Int64, ::Tuple{Bool, Bool})
MethodInstance for Base.typed_hcat(::Type{Any}, ::Any, ::Nothing)
MethodInstance for Base._cat_t(::Val{2}, ::Type{Any}, ::Any, ::Nothing)
MethodInstance for Base.__cat(::Any, ::Tuple{Any, Any}, ::Tuple{Bool, Bool}, ::Any, ::Nothing)
MethodInstance for Base.__cat_offset!(::Any, ::Tuple{Any, Any}, ::Tuple{Bool, Bool}, ::Tuple{Int64, Int64}, ::Any, ::Nothing)
MethodInstance for (::Base.var"#181#183"{<:Tuple{Any, Any}, Tuple{Bool, Bool}, Tuple{Int64, Int64}})(::Int64)
MethodInstance for (::Base.var"#254#255"{Base.var"#181#183"{var"#s182", Tuple{Bool, Bool}, Tuple{Int64, Int64}, _A}} where {var"#s182"<:Tuple{Any, Any}, _A})(::Int64)
MethodInstance for Base._copy_or_fill!(::Any, ::Tuple{Any, Any}, ::LinearAlgebra.AbstractQ)
MethodInstance for (::Base.var"#182#184"{Tuple{Bool, Bool}, Tuple{Int64, Int64}})(::Int64)
MethodInstance for (::Base.var"#254#255"{Base.var"#182#184"{Tuple{Bool, Bool}, Tuple{Int64, Int64}, _A}} where _A)(::Int64)
MethodInstance for Base.__cat_offset!(::Any, ::Tuple{Any, Any}, ::Tuple{Bool, Bool}, ::Tuple{Any, Any}, ::Nothing)
MethodInstance for (::Base.var"#181#183"{<:Tuple{Any, Any}, Tuple{Bool, Bool}, <:Tuple{Any, Any}, Nothing})(::Int64)
MethodInstance for Base.Broadcast.broadcasted(::typeof(+), ::Any, ::Base.OneTo{Int64})
MethodInstance for (::Base.var"#254#255"{Base.var"#181#183"{var"#s182", Tuple{Bool, Bool}, var"#s1821", Nothing}} where {var"#s182"<:Tuple{Any, Any}, var"#s1821"<:Tuple{Any, Any}})(::Int64)
MethodInstance for Base._copy_or_fill!(::Any, ::Tuple{Any, Any}, ::Nothing)
MethodInstance for view(::LinearAlgebra.AbstractQ, ::Any, ::Any)
MethodInstance for copy(::LinearAlgebra.AbstractQ)
MethodInstance for Base.copymutable(::LinearAlgebra.AbstractQ)
MethodInstance for fill!(::Union{Matrix{Int8}, Matrix{UInt8}}, ::Integer)
MethodInstance for fill!(::Matrix, ::Any)
MethodInstance for (::Base.var"#182#184"{Tuple{Bool, Bool}, <:Tuple{Any, Any}, Nothing})(::Int64)
MethodInstance for (::Base.var"#254#255"{Base.var"#182#184"{Tuple{Bool, Bool}, var"#s182", Nothing}} where var"#s182"<:Tuple{Any, Any})(::Int64)
MethodInstance for getindex(::Dict{Any, Any}, ::Any)
MethodInstance for (::MacroTools.var"#27#28"{Handcalcs.var"#21#22"{String}})(::Symbol)
MethodInstance for MacroTools.match_inner(::Expr, ::Symbol, ::Dict{Any, Any})
MethodInstance for Base.collect_to_with_first!(::Vector{Symbol}, ::Symbol, ::Base.Generator{Vector{Any}, MacroTools.var"#27#28"{Handcalcs.var"#21#22"{String}}}, ::Int64)
MethodInstance for (::MacroTools.var"#27#28"{Handcalcs.var"#21#22"{String}})(::Expr)
MethodInstance for AbstractTrees.Leaves(::Symbol)
MethodInstance for collect(::AbstractTrees.Leaves{Symbol})
MethodInstance for nextsibling(::AbstractTrees.ImplicitCursor{Symbol, Nothing, Any})
MethodInstance for (::MacroTools.var"#27#28"{Handcalcs.var"#21#22"{String}})(::Int64)
MethodInstance for MacroTools.match_inner(::Expr, ::Int64, ::Dict{Any, Any})
MethodInstance for Base.setindex_widen_up_to(::Vector{Symbol}, ::Int64, ::Int64)
MethodInstance for Base.collect_to!(::Vector{Any}, ::Base.Generator{Vector{Any}, MacroTools.var"#27#28"{Handcalcs.var"#21#22"{String}}}, ::Int64, ::Int64)
MethodInstance for Base.setindex_widen_up_to(::Vector{Symbol}, ::Expr, ::Int64)
MethodInstance for Handcalcs._extract_arg(::Symbol)
MethodInstance for Handcalcs._extract_arg(::Int64)
MethodInstance for getindex(::Matrix{Any}, ::Int64)
MethodInstance for Base.indexed_iterate(::Matrix{Any}, ::Int64)
MethodInstance for Handcalcs.clean_kwargs(::Tuple{Expr})
MethodInstance for Handcalcs._handcalcs_recursive(::Vector{Any})
MethodInstance for get(::Dict{Symbol, Any}, ::Symbol, ::Symbol)
MethodInstance for collect_exprs(::LaTeXStrings.LaTeXString)
MethodInstance for calc_Ix(::Int64, ::Int64)
MethodInstance for multiline_latex(::Vector{Any})
MethodInstance for Base._iterator_upper_bound(::AbstractTrees.Leaves{Tuple{Vector{Any}}})
MethodInstance for BoundsError(::Any, ::Int64)
MethodInstance for descendleft(::AbstractTrees.ImplicitCursor{Vector{Any}, Tuple{Vector{Any}}, Any})
MethodInstance for AbstractTrees.ImplicitCursor(::AbstractTrees.ImplicitCursor{Vector{Any}, Tuple{Vector{Any}}, Any}, ::LaTeXStrings.LaTeXString, ::Nothing)
MethodInstance for descendleft(::AbstractTrees.ImplicitCursor{LaTeXStrings.LaTeXString, Vector{Any}, Union{Nothing, Tuple{Any, Int64}}})
MethodInstance for AbstractTrees.LeavesState(::AbstractTrees.ImplicitCursor{LaTeXStrings.LaTeXString, Vector{Any}, Union{Nothing, Tuple{Any, Int64}}})
MethodInstance for iterate(::AbstractTrees.Leaves{Tuple{Vector{Any}}}, ::AbstractTrees.LeavesState{AbstractTrees.ImplicitCursor{LaTeXStrings.LaTeXString, Vector{Any}, Union{Nothing, Tuple{Any, Int64}}}})
MethodInstance for isnothing(::AbstractTrees.ImplicitCursor{LaTeXStrings.LaTeXString, Vector{Any}, Union{Nothing, Tuple{Any, Int64}}})
MethodInstance for isroot(::AbstractTrees.ImplicitCursor{LaTeXStrings.LaTeXString, Vector{Any}, Union{Nothing, Tuple{Any, Int64}}})
MethodInstance for nextsibling(::AbstractTrees.ImplicitCursor{LaTeXStrings.LaTeXString, Vector{Any}, Union{Nothing, Tuple{Any, Int64}}})
MethodInstance for nextsibling(::AbstractTrees.ImplicitCursor{Vector{Any}, Tuple{Vector{Any}}, Any})
MethodInstance for Base.grow_to!(::Vector{LaTeXStrings.LaTeXString}, ::AbstractTrees.Leaves{Tuple{Vector{Any}}}, ::Nothing)

Interesting. Thanks for looking into it. I tried doing that

And I didn’t see any difference when doing it inside my package.

At least precompiling did work in the REPL so there might be a solution out there.

@setup_workload and @compile_workload puts the input expression in a big

if ccall(:jl_generating_output, PrecompileTools.Cint, ()) == 1 && (PrecompileTools).workload_enabled(__module__) || (PrecompileTools).verbose[]

I don’t know exactly what it means, but the A && B part basically means whether precompilation is happening, and || verbose[] is a setting that prints calls that get precompiled and runs the block even if we’re not precompiling right now, just normal compiling (pretty sure the printed MethodInstances aren’t being cached).

julia> helloworld() = println("hello world")
helloworld (generic function with 1 method)

julia> using PrecompileTools

julia> PrecompileTools.verbose[] = false # default
false

julia> @compile_workload helloworld()

julia> PrecompileTools.verbose[] = true
true

julia> @compile_workload helloworld()
hello world
MethodInstance for println(::Base.TTY, ::String, ::Vararg{String})

@compile_workload adds timing(?) calls to the expression, but I don’t understand how it distinguishes its contents as cache-worthy during precompilation. Outside of precompilation, @setup_workload can contribute global variables and “steal” compilation printouts from @compile_workload because evaluation and JIT are happening normally.