Skip to content
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

Merged
merged 2 commits into from
Jun 24, 2022
Merged

Conversation

johnnychen94
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented May 27, 2022

Codecov Report

Merging #362 (c8e2d2b) into master (f0e5b95) will not change coverage.
The diff coverage is n/a.

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0e5b95...c8e2d2b. Read the comment docs.

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.

Sorry for the "long latency" 😉 here! And thanks for doing this.

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## 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

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

A tip is to wrap the block with four backticks

image

Co-Authored-by: Tim Holy <tim.holy@gmail.com>
@johnnychen94 johnnychen94 merged commit 0ea2829 into master Jun 24, 2022
@johnnychen94 johnnychen94 deleted the jc/world_age_issue branch June 24, 2022 04:46
@johnnychen94
Copy link
Member Author

@timholy thanks for the heavy rewrite, much clearer!

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.

2 participants