Skip to content

Add Base.is_serializing_code() for guarding precompilation code #45650

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

Closed

Conversation

IanButterworth
Copy link
Member

@IanButterworth IanButterworth commented Jun 12, 2022

ccall(:jl_generating_output, Cint, ()) == 1 is used in the ecosystem widely to guard precompilation code. It seems like it should be formally in the API.

A slack discussion with @timholy arrived at this name. is_precompiling seemed like a good name at first, but is confused by precompile calls, which precompile code at a time where jl_generating_output != 1. And is_generating_output seemed a bit vague.

@IanButterworth IanButterworth requested a review from timholy June 12, 2022 00:19
@IanButterworth IanButterworth force-pushed the ib/is_serializing_code branch from 2893728 to 07d0f8e Compare June 12, 2022 00:44
Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

@timholy
Copy link
Member

timholy commented Jun 17, 2022

Would it be worth including an example of why you might want this kind of guard? For example, suppose you start julia with --compiled-modules=no. Then there's no reason to pay the price of the package author's precompile directives: those directives are meant to do the work once and make it reusable across multiple sessions, but that doesn't apply if you're not going to be using the cache. And then you might as well pay only for the things you actually need in that session.

@JeffBezanson
Copy link
Member

How about is_saving_code? It's shorter, less jargon-y, and less tied to how the process is implemented.

@IanButterworth
Copy link
Member Author

Yeah I share similar reservations about serializing

What about is_caching_code?

"Saving" made me think of saving human-readable code, like .jl files.

@IanButterworth IanButterworth added the triage This should be discussed on a triage call label Jul 1, 2022
@ericphanson
Copy link
Contributor

is_precompile_time()? That’s how I think of it whenever I need this but maybe it’s not accurate

@mkitti
Copy link
Contributor

mkitti commented Jul 7, 2022

From triage:

Attending

Lasting thoughts:

Discussed names

  • Core.Compiler.is_saving_code - maybe it should not live in Base
  • Core.Compiler.is_outputting - maybe it should not live in Base
  • Core.Compiler.is_generating_output -matches the C function, but requires knowledge of compiler jargon
  • is_caching_code - for precompile caches, specifically for .ji (output-ji)
  • is_saving_compiled_code -
  • is_saving_compiler_output
  • is_caching_compiler_output
  • is_generating_compiled_output

Bad names

  • is_runtime -
  • is_generating_compiled_code - we are always generating code

@JeffBezanson
Copy link
Member

I will point out that this is really a question about what command-line options were passed, i.e. "is the julia runtime being run in a mode where what you do might be saved for later use?" so it is in fact system-global.

@IanButterworth
Copy link
Member Author

IanButterworth commented Jul 21, 2022

Triage decided that with the creation of timholy/SnoopCompile.jl#282 which wraps this ccall, the need for this to be formalized in the API isn't necessary

@IanButterworth IanButterworth removed the triage This should be discussed on a triage call label Jul 21, 2022
@IanButterworth IanButterworth deleted the ib/is_serializing_code branch July 21, 2022 18:48
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.

5 participants