Skip to content

gf.c: include const-return methods in --trace-compile #237

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

Merged
merged 2 commits into from
Jun 6, 2025

Conversation

kpamnany
Copy link
Collaborator

@kpamnany kpamnany commented May 22, 2025

PR Description

This is a quick-fix for an issue where methods that are inferred to return a Const do not emit compilation traces. Although they are never compiled by LLVM, we want to log them since they are inferred / compiled by Julia. As with #236, it isn't yet clear what the actual upstream fix will look like on 1.12+.

Checklist

Requirements for merging:

@kpamnany kpamnany force-pushed the kp-backport-trace-const-return-methods branch from 4533648 to ba3cfb0 Compare May 23, 2025 13:15
@kpamnany kpamnany force-pushed the kp-backport-trace-const-return-methods branch from ba3cfb0 to fa0f780 Compare June 4, 2025 20:37
@kpamnany kpamnany marked this pull request as ready for review June 4, 2025 21:50
@kpamnany kpamnany requested a review from a team June 5, 2025 13:28
src/gf.c Outdated
@@ -2420,7 +2426,10 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila
jl_printf(s_precompile, "#= %6.1f =# ", compilation_time / 1e6);
jl_printf(s_precompile, "precompile(");
jl_static_show(s_precompile, mi->specTypes);
jl_printf(s_precompile, ")\n");
if (is_const_return_abi)
jl_printf(s_precompile, ") #= const-return =#\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to negatively interact with any trace-processing tools we have?

why do we want this in the output?

Copy link
Collaborator Author

@kpamnany kpamnany Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great observation. I think I did see some CI errors due to this comment when I had added the TPC-H trace (before I removed that trace from testing). Those should be easily fixable; I'll check.

Upstream, they are (for now) maintaining the idea that compilation traces are human-readable, which is why this is in the output. We could remove it locally if we're okay with diverging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compilation traces are human-readable, which is why this is in the output

i wonder in what situations seeing the #= const-return =# comment is helpful?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to handle these trailing comments, but it's definitely a good idea to check 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> RAI_CompilationsCache.PrecompileStatementParsing.is_precompileable(Base, "#= 1.0 =# precompile(Tuple{typeof(Base.:+), Int, Int}) #= const-return =#")
pr_success::PrecompilationResult = 1

julia> RAI_CompilationsCache.PrecompileStatementParsing.run_precompile(Base, "#= 1.0 =# precompile(Tuple{typeof(Base.:+), Int, Int}) #= const-return =#")
pr_success::PrecompilationResult = 1

We could end up with duplicate traces though -- if on engine 1 we produced

#= 1.0 =# precompile(Tuple{typeof(Base.:+), Int, Int}) #= const-return =#

and on engine 2, which called the function in a different context, we'd get

#= 1.0 =# precompile(Tuple{typeof(Base.:+), Int, Int})

That could cause the precompile to take up 2 spots in the cache, so we probably need to augment the cache to strip any trailing comments.

topolarity and others added 2 commits June 5, 2025 17:43
These are never compiled by LLVM, but we want to log them since they are
inferred / compiled by our own compiler.
@kpamnany kpamnany force-pushed the kp-backport-trace-const-return-methods branch from fa0f780 to 9202e9c Compare June 5, 2025 21:43
Copy link
Member

@Drvi Drvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kpamnany kpamnany merged commit 11292a9 into v1.10.2+RAI Jun 6, 2025
1 check passed
@kpamnany kpamnany deleted the kp-backport-trace-const-return-methods branch June 6, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants