-
Notifications
You must be signed in to change notification settings - Fork 82
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
docs: explain what world-age issue is #362
Conversation
Codecov Report
@@ Coverage Diff @@
## master #362 +/- ##
=======================================
Coverage 87.50% 87.50%
=======================================
Files 10 10
Lines 696 696
=======================================
Hits 609 609
Misses 87 87 Continue to review full report at Codecov.
|
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.
Sorry for the "long latency" 😉 here! And thanks for doing this.
docs/src/world_age_issue.md
Outdated
The second `f()` works because this time you're running a recompiled version of `f()` in the latest | ||
world age with the necessary `size(::IndirectArray)` defined. | ||
|
||
## Solution |
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.
## Solution | |
## Solutions | |
### `Base.invokelatest` | |
One solution is to make the call to `size` via `Base.invokelatest`, | |
which exists explicitly to work around this world-age dispatch problem. Literally, `invokelatest` | |
dispatches the supplied call using the latest world age (which may be newer than when you | |
typed `f()` at the REPL). **In a fresh Julia session**, | |
``julia | |
julia> using FileIO | |
julia> f() = Base.invokelatest(size, load("indexed_image.png")) | |
f (generic function with 1 method) | |
julia> f() | |
(4, 4) | |
`` | |
!!! note | |
In step 3 above ("FileIO calls the appropriate PNG-specific `load` function in PNGFiles"), | |
the call to the `load` function defined in PNGFiles is made via `invokelatest`. | |
Otherwise, even ordinary interactive usage of FileIO (without burying `load` inside a function) | |
would cause world-age errors. | |
!!! warning | |
Using `invokelatest` slows your code considerably. Use it only when absolutely necessary. | |
### Eagerly load the required packages first |
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.
You're going to have to change double-backticks to triple-backticks; unfortunately GitHub terminates the suggestion on the first triple-backticks it finds.
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.
Co-Authored-by: Tim Holy <tim.holy@gmail.com>
@timholy thanks for the heavy rewrite, much clearer! |
No description provided.