Skip to content

@compile_workload does not include compilation for macro expansion of body #65

@topolarity

Description

@topolarity

Consider a package like:

module DroppedPrecompile

using PrecompileTools
macro fancy_macro()
    f = Core.compilerbarrier(:type, length)
    return f(Tuple{Int64,Int32,Int16,Int8}[]) # this does not end up pre-compiled
end

@compile_workload begin
    @fancy_macro
end

end # module DroppedPrecompile

The dynamically called Base.length(::Tuple{Int64,Int32,Int16,Int8}) does not end up pre-compiled:

julia> using DroppedPrecompile
julia> Base.method_instance(Base.length, (Vector{Tuple{Int64,Int32,Int16,Int8}},)).cache
ERROR: UndefRefError: access to undefined reference

Logically, this makes sense - the macro expansion happens before the begin ... end block actually starts to execute.

Nonetheless, I wanted to file an issue, since it is a practical issue for libraries like ModelingToolkit.jl, which hit this use case (https://github.com/SciML/ModelingToolkit.jl/blob/3f965be3d256412844f7d43262d75fb48657c2df/src/ModelingToolkit.jl#L245-L278) and probably do intend to pre-compile the macros themselves, so that these are fast for future users.

Is there any good option for MTK to "opt-in" to including macro expansion in the workload?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions