Skip to content

Commit

Permalink
Add precompiled tags if backedge is missing
Browse files Browse the repository at this point in the history
In JuliaLang/julia#49617 it was found that
not all callees have backedges to callers. There is some speculation
that rather than adding the backedge to those cases, we may in fact
be able to prune the backedge graph more substantially in cases where
it may be safe to avoid propagating invalidation.

Consequently, to enforce the guarantees made by `@compile_workload`,
PrecompileTools should check the inference graph and add tags in cases
where a backedge is missing.
  • Loading branch information
timholy committed May 3, 2023
1 parent e1fa6e2 commit d527a47
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/PrecompileTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@ function workload_enabled(mod::Module)
end
end

"""
check_edges(node)
Recursively ensure that all callees of `node` are precompiled. This is (rarely) necessary
because sometimes there is no backedge from callee to caller (xref https://github.com/JuliaLang/julia/issues/49617),
and `staticdata.c` relies on the backedge to trace back to a MethodInstance that is tagged `mi.precompiled`.
"""
function check_edges(node)
parentmi = node.mi_info.mi
for child in node.children
childmi = child.mi_info.mi
if !(isdefined(childmi, :backedges) && parentmi childmi.backedges)
precompile(childmi.specTypes)

Check warning on line 32 in src/PrecompileTools.jl

View check run for this annotation

Codecov / codecov/patch

src/PrecompileTools.jl#L32

Added line #L32 was not covered by tests
end
check_edges(child)
end
end

function precompile_roots(roots)
@assert have_inference_tracking
for child in roots
mi = child.mi_info.mi
precompile(mi.specTypes) # TODO: Julia should allow one to pass `mi` directly (would handle `invoke` properly)
verbose[] && println(mi)
check_edges(child)
end
end

Expand Down

0 comments on commit d527a47

Please sign in to comment.