Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix world age warnings from accessing binding before definiton #108

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

nickrobinson251
Copy link
Collaborator

Close #107

This warning is only present starting in Julia 1.12

Presumably the issue is with the docstring resolving the binding fnname before it's actually been defined. I don't fully understand the problem but this fixes it 🤷‍♂️

Comment on lines -54 to +55
$($fnname)(I, x, y) :: I
$($fnname_str)(I, x, y) :: I
Copy link
Member

Choose a reason for hiding this comment

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

Ah, nice, thanks! Good find! It took me a minute of staring, but i think i've got an explanation:
It's easy to forget, but interpolating a symbol into an expression creates an identifier, not a symbol.
So this was generating the following string code:

"  $(trunc_mul)(I, x, y) :: I "

and as you point out, the trunc_mul function doesn't exist yet, so this should fail.

What we meant to be putting in there was the name of the function, as you've done, so your change looks great. 👍
The other thing we could have done is to generate what this code meant to be generating, which is this:

julia> "$(:foo)(I, x, y) :: I"
"foo(I, x, y) :: I"

That is, putting the symbol itself into the code, rather than using the symbol to put an identifier in the code.

The syntax to do that is to wrap the value in a QuoteNode, whose sole purpose it to allow putting symbols or expressions as values into generated code:

            $($(Meta.quot(fnname)))(I, x, y) :: I
            $($(QuoteNode(fnname)))(I, x, y) :: I

(either of those options are identical)

Copy link
Member

Choose a reason for hiding this comment

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

but anyway, i like what you've done - it's very straightforward.

Copy link
Member

Choose a reason for hiding this comment

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

in particular, the quote suggestion raises the question "how does a symbol stringify in interpolation? Does it print as foo or :foo?" so converting to a string is more clear 👍

@nickrobinson251 nickrobinson251 merged commit 0b5d756 into master Jan 31, 2025
8 of 12 checks passed
@nickrobinson251 nickrobinson251 deleted the npr-fix-world-age-warnings branch January 31, 2025 23:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warnings in Julia v1.12.0-DEV Detected access to binding in a world prior to its definition world
2 participants