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

Method redefinition does not take effect #26820

Closed
s-broda opened this issue Apr 16, 2018 · 5 comments
Closed

Method redefinition does not take effect #26820

s-broda opened this issue Apr 16, 2018 · 5 comments
Assignees
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@s-broda
Copy link

s-broda commented Apr 16, 2018

Reduced from here https://discourse.julialang.org/t/julia-calls-the-old-method-after-method-is-redefined/10327/7:

Setup:

abstract type VolatilitySpec end
struct GARCH{p,q} <: VolatilitySpec end
struct ARCHModel{VS<:VolatilitySpec}
    ARCHModel{VS}() where {VS}=new()
end
ARCHModel(VS::Type{T}) where {T<:VolatilitySpec} = ARCHModel{VS}()

loglikelihood(am::ARCHModel{T}) where{T} = arch_loglik!(T)

function arch_loglik!(M::Type{GARCH{p,q}}) where {p, q}
    return 5.
end

function selectmodel()
    res = Array{ARCHModel, 2}(4, 4)
    for p = 0:3, q = 0:3
        res[p+1, q+1] = ARCHModel(GARCH{p, q})
    end
    crits = loglikelihood.(res)
end

Calling the method works as expected:

julia> arch_loglik!(GARCH{1, 1})
5.0

Now, call the function selectmodel (this step is crucial for reproducing the issue) and redefine the method (note no warning about the method redefinition):

julia> selectmodel();

julia> arch_loglik!{p, q}(M::Type{GARCH{p,q}}) = 1
arch_loglik! (generic function with 1 method)

However, the new definition doesn't take effect, despite @code_llvm showing the updated definition:

julia> arch_loglik!(GARCH{1, 1})
5.0

julia> @code_llvm arch_loglik!(GARCH{1, 1})

; Function Attrs: uwtable
define i64 @"julia_arch_loglik!_63633"(i8**) #0 !dbg !5 {
top:
  ret i64 1
}
@s-broda
Copy link
Author

s-broda commented Apr 16, 2018

PS: This is on both 0.6.2 (Windows and Linux) and 0.7 latest nightly.

@RalphAS
Copy link

RalphAS commented Apr 16, 2018

FWIW, further experimentation shows that

  • there is a redefinition warning if the above is enclosed in a module other than Main.
  • invokelatest seems to call the expected method in 0.7 but not 0.6.2.
  • failure to get the updated method seems to depend on details of how the original was used in the selectmodel function: broadcast (as shown above), map, and certain loop expressions (even without hidden closures, AFAICT) show the problem, but scalar calls and some other loops do not.
  • the method tables seem to show sensible values for world age on the two versions.

@s-broda
Copy link
Author

s-broda commented Apr 24, 2018

Should this perhaps get a bug label? It seems that it may be related to #265 and its awesome fix by @vtjnash.

@StefanKarpinski StefanKarpinski added the kind:bug Indicates an unexpected problem or unintended behavior label Apr 24, 2018
@Keno
Copy link
Member

Keno commented Jul 29, 2018

I can no longer reproduce this. There've been a bunch of bug fixes in this area. Can you try your original problem and see if the bug persists?

@s-broda
Copy link
Author

s-broda commented Jul 30, 2018

My code is not compatible with 0.7 yet, so I can't test the original issue. I can confirm however that the MWE above is fixed on latest Windows nightly. Feel free to close.

@vtjnash vtjnash closed this as completed Oct 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants