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

Revise and DispatchDoctor #820

Open
thofma opened this issue Jun 1, 2024 · 5 comments
Open

Revise and DispatchDoctor #820

thofma opened this issue Jun 1, 2024 · 5 comments

Comments

@thofma
Copy link

thofma commented Jun 1, 2024

I have been playing around with https://github.com/MilesCranmer/DispatchDoctor.jl/ (v0.4.2) and found it quite useful. It also seems to work well with Revise.includet:

shell> cat test.jl
@stable f(x) = x == 1 ? 1 : 1.0

julia> Revise.includet("/Users/thofma/test2.jl")

julia> f(1)
ERROR: TypeInstabilityError: Instability detected in `f` defined at test.jl:1 with arguments `(Int64,)`. Inferred to be `Union{Float64, Int64}`, which is not a concrete type.

If I then change test.jl, i.e. change f from unstable -> stable, things are properly revised (even changing f from unstable -> unstable works.)

But it does not seem to work well within a module. If I have a module with the following content:

module A
using DispatchDoctor
include("test.jl")
end

Now if I do using Revise, A etc, and change f from unstable -> unstable, the error is not reported anymore.

As far as I understand, DispatchDoctor.jl replaces A.include with https://github.com/MilesCranmer/DispatchDoctor.jl/blob/569aac2fc3a904aa6e499a6a0b406aaa3a3ed849/src/stabilization.jl#L196-L205, and it seems this does not work properly in connection with Revise.

I am not sure how realistic it is to have both packages work nicely together. So feel free to close this issue, if it is technically not possible.

CC: @MilesCranmer

@MilesCranmer
Copy link

@timholy does Revise work by mapping include to includet? I don’t really have a good feel for where the interaction is coming from. If it’s just something like that I guess I could add a Revise extension to map A.include in the generated code to [something analogous to] A.includet?

@MilesCranmer
Copy link

MilesCranmer commented Jun 1, 2024

I think it's due to #634?

Roughly, @stable include("file.jl") will create the following function:

function inner(ex)
    new_ex, _ = _stabilize_all(ex, DownwardMetadata(); kws...)
    return new_ex
end

and insert

include($(inner), "file.jl")

This recursively applies _stabilize_all to all included code – basically the same as if you had put @stable on every single function definition.

@MilesCranmer
Copy link

@timholy friendly ping :)

@MilesCranmer
Copy link

@thofma see #634 (comment).

I feel like Revise.jl needs very deep changes for this to happen. Therefore I think it would be better we just find a way to work around this limitation rather than fix it at the source.

@MilesCranmer
Copy link

MilesCranmer commented Jun 13, 2024

I think perhaps a simpler option would be to allow per-file mapexpr to be added manually, similar to the callbacks interface –
Screenshot 2024-06-13 at 19 38 06

Then I could do the rest on DispatchDoctor.jl side (adding the right functions to it).

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

No branches or pull requests

2 participants