-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Within-module eval can break precompile #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, I was quite literally on my way to this repo to address this exact issue.
This allows me to declare a top level const
within REPL.jl
, changing
const JULIA_PROMPT = "julia> "
to
const JULIA_PROMPT = styled"{repl_prompt_julia:julia> }"
Out of curiosity, is this interpolation mechanism similar to the way julia strings operate?
Glad this helped. I've been chatting with Kristoffer and I'm going to probably change the approach here in a sec to avoid conditioning on
What's "this" interpolation, I can't see any in the |
The use of eval makes precompilation funky due to the within-module eval during precompilation. Evaluation within the calling module doesn't work either because macro hygiene hasn't been applied yet. The solution: apply hygiene ourselves then eval within the calling module.
f7d6bdd
to
9f804f8
Compare
My apologies for the ambiguity. To clarify, my question regards the way in which |
Ah right, cool. Just wanted to make sure I answered the right question 🙂. I think just looking at the macroexpansion perhaps could help with this? To give a few simplified examples: julia> @macroexpand styled"hello $you"
:(annotatedstring("hello ", you)) So in this case, this should be pretty much equivalent to If we want to style an interpolated value, it's a little more complex. julia> @macroexpand styled"hello {bold:$you}"
:(annotatedstring("hello ", let str=string(you); AnnotatedString(str, [(1:ncodeunits(you), :face => :bold]) end)) The complication here is that we need to know how large The other way we can do interpolation is in the face/annotation itself, which looks like this: julia> @macroexpand styled"hello {$myface:you}"
:(annotatedstring(AnnotatedString("hello you", [(7:9, :face => myface)]))) In this case, since the content is static Hopefully that clears things up, if not I'm happy to answer any follow-up questions 🙂. |
Ok, so this PR makes it possible to precompile this stdlib into system image, which is eminently desirable. We may want to change the particular approach it takes from manually applied hygiene to interpolating every function/type of the eval'd expressions (though I'm worried this could make it easier to accidentally introduce subtle bugs). So, while perhaps not the final approach, this PR represents an improvement to the current situation, and so I'm going to go ahead and merge it. |
Thank you for your thoughtful answer. I'm curious, is the implementation side similar? I haven't fully grokked the I suppose this discussion may be beside the point of pre-compilation, but I can't help but be curious since I don't have enough familiarity with Julia's internals to have an understanding of how a string goes from, let's say, a string literal in a file, e.g. As a side note, I hope my intention comes across correctly. I'm naive about these inner workings and I'm trying to understand them, not critique this approach; I very much appreciate the strengths of macro-based "languages-within-a-language" solutions (and would be thrilled to see initiatives to make hygienic macros easier to write in Julia). |
I'm not fully aware of the internals of Julia string interpolation, but from my understanding — not at all. Julia string interpolation is handled at a parser level, and IIRC ends up being equivalent to a By contrast, here the string macro is given the already parsed string (just without interpreting From your thoughts, it sounds like your speculation and my current understanding of the situation mesh pretty cleanly?
The problem here is that As far as I'm aware, there aren't any other macros currently trying something similar. |
This seems like it might be necessary to avoid precompile problems otherwise seen in JuliaLang/julia#51811?
Thoughts on this would be welcome.