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 overwrite warning when building sysimg #27053

Closed
KristofferC opened this issue May 9, 2018 · 4 comments
Closed

Method overwrite warning when building sysimg #27053

KristofferC opened this issue May 9, 2018 · 4 comments

Comments

@KristofferC
Copy link
Sponsor Member

WARNING: Method definition round(Real, Base.Rounding.RoundingMode{T} where T) in module Base at floatfuncs.jl:127 overwritten at floatfuncs.jl:135.

Touched in #26670 cc @simonbyrne

@simonbyrne simonbyrne reopened this May 9, 2018
@simonbyrne
Copy link
Contributor

The background is that we're exploiting #9498 to do dispatch on keyword arguments: the "user-facing" method is

julia/base/floatfuncs.jl

Lines 125 to 126 in a0b1e98

function round(x::Real, r::RoundingMode=RoundNearest;
digits::Union{Nothing,Integer}=nothing, sigdigits::Union{Nothing,Integer}=nothing, base=10)

which, depending on the arguments, will eventually call round(x,r) without keyword arguments.

To avoid recursive calls we also define a generic error:

round(x::Real, r::RoundingMode) = throw(MethodError(round, (x,r)))

which triggers the redefinition warning.

Unfortunately, I don't see a nice way to do it that doesn't trigger it. Any ideas?

@JeffBezanson
Copy link
Sponsor Member

Since we have

_round(x, r::RoundingMode, digits::Nothing, sigdigits::Nothing, base) = round(x, r)

it looks to me like it's never valid to be in the keyword arg definition with digits and sigdigits set to nothing. So an error could be thrown in that case, instead of defining the external error method?

@simonbyrne
Copy link
Contributor

No that is valid: the intention is that each number type defines their own round(x,r) method, e.g.

julia/base/float.jl

Lines 358 to 365 in a0b1e98

round(x::Float64, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float32, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float64, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float32, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float64, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float32, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float64, r::RoundingMode{:Nearest}) = rint_llvm(x)
round(x::Float32, r::RoundingMode{:Nearest}) = rint_llvm(x)

@simonbyrne
Copy link
Contributor

Ah, I misunderstood what you meant. That should work, thanks!

simonbyrne added a commit that referenced this issue May 9, 2018
JeffBezanson pushed a commit that referenced this issue May 11, 2018
Fix method overwrite warning in `round`

Fixes #27053
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

3 participants