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

RFC: always warn on overwritten methods #14759

Merged
merged 4 commits into from
Jan 26, 2016
Merged

RFC: always warn on overwritten methods #14759

merged 4 commits into from
Jan 26, 2016

Conversation

JeffBezanson
Copy link
Sponsor Member

Currently we only warn if a method is overwritten in a different module. I now believe we should always print this warning.

First, I was amazed to discover how often this happens in Base. Nearly all cases seem to be mistakes. Bizarrely, several definitions were literally copy & pasted one after the other. It's possible those were rebase artifacts of some kind. This also revealed that when doc strings are applied to @enums, the entire definition (type and all methods) is repeated twice. I have not fixed this yet.

Second, jb/functions makes overwriting methods worse, since code can be specialized on function arguments. A few packages are failing because their tests repeatedly write f(x) = ..., intending to create a different function each time. These should be written as f = x-> ... instead. This warning will help find such cases. (This is an especially bad manifestation of #265.)

The first commit removes many overwritten definitions from Base. The second commit changes the warning to print in all cases.

@yuyichao
Copy link
Contributor

👍 Maybe we could even make it an error? There's at least one test in core.jl that deliberately override method definition to check for segfault. Maybe we can just remove that...

@johnmyleswhite
Copy link
Member

+100

@mauro3
Copy link
Contributor

mauro3 commented Jan 22, 2016

+1 if it can be disable in the REPL as that would add a lot of noise.

@toivoh
Copy link
Contributor

toivoh commented Jan 22, 2016

  • a lot

@kmsquire
Copy link
Member

+1 if it can be disable in the REPL as that would add a lot of noise.

+1 to the idea, but also to this statement. I find myself redefining functions at the REPL frequently during development, and this would get annoying.

(Also would be nice to disable warnings on calls to workspace().)

@StefanKarpinski
Copy link
Sponsor Member

Wouldn't making overwriting a method always warning be sufficient? That would allow redefining things / reloading code, but would make it clear when library code was doing it and shouldn't.

@JeffBezanson JeffBezanson force-pushed the jb/overwritten branch 2 times, most recently from 9d47019 to 85d8d2b Compare January 22, 2016 20:06
MichaelHatherly added a commit to MichaelHatherly/julia that referenced this pull request Jan 22, 2016
Fixes issue mentioned in JuliaLang#14759. Both `multidoc` and `__doc__!` did
not take into account the `define` flag which results in them overwriting
definitions during base image generation.
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 24, 2016

+1

@@ -183,7 +183,7 @@ function reset!(repo::GitRepo, obj::GitObject, mode::Cint;
end

function clone(repo_url::AbstractString, repo_path::AbstractString,
clone_opts::CloneOptions = CloneOptions())
clone_opts::CloneOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

where's the duplicate here?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

It's in libgit2.jl, where there is a 2-argument clone method that collides due to this argument being optional.

JeffBezanson added a commit that referenced this pull request Jan 26, 2016
RFC: always warn on overwritten methods
@JeffBezanson JeffBezanson merged commit 84c06b1 into master Jan 26, 2016
@tkelman
Copy link
Contributor

tkelman commented Jan 26, 2016

Looks like a few more have slipped onto master were not remedied here

@JeffBezanson JeffBezanson deleted the jb/overwritten branch January 26, 2016 04:19
@eschnett
Copy link
Contributor

I see warnings regarding checked_add being overwritten in coreimg. This looks as if it should indeed be overwritten. If so, can the warning be omitted? Or would a comment in the code suffice?

@NickMcNutt
Copy link

+1 if it can be disable in the REPL as that would add a lot of noise.

+1 to the idea, but also to this statement. I find myself redefining functions at the REPL frequently during development, and this would get annoying.

+1 to this as well. Now that it issues a warning, my Jupyter notebooks are full of red boxes taking up the entire page. I've resorted to this hack to get rid of them:

macro nowarn(expr)
    quote
        stderr = STDERR
        stream = open("/dev/null", "a")
        redirect_stderr(stream)
        result = $(esc(expr))
        redirect_stderr(stderr)
        close(stream)
        result
    end
end
@nowarn function myfunc()
    ...
end

@timholy
Copy link
Sponsor Member

timholy commented Apr 29, 2016

While on the topic of making TL;DR posts (#11242 (comment)), I've suddenly developed an interest in adding an @overwrite macro that allows one to choose to suppress the warning added here. To clarify, I like the warning as the default behavior, but I've discovered a situation in which I would also like the option of avoiding it.

Background: without dragging everyone through the details, suffice it to say that a real implementation (ArrayIteration.jl) of the ideas discussed in #15648 seems to be coming along quite well: there's still lots to do, but a lot is in place. The best way to think about it is as a set of run-time and compile-time "hooks" (based on a traits-system) for customizing behavior of functions that handle arrays. (At the current time it remains largely undocumented, unfortunately.)

Given the interest in finalizing julia-0.5 soon, deciding what to do with it is a little bit tricky. On one hand, ArrayIteration.jl is still young and inexperienced, and certainly shouldn't be allowed to wander around town (Base) on its own. On the other hand, the way for it to gain experience is for people to use it to achieve new functionality. The problem is that some of its generalizations violate deeply baked-in assumptions in Base; many methods will produce bugs or segfaults if called on new array types. This situation makes it hard to imagine there being a great deal of adoption, even if it has advantages.

Aside from doing nothing and seeing what happens, there seem to be two "active" decisions we could make:

  • Despite ArrayIteration's youth, merge at least some of it into Base, so methods can be generalized during 0.5.x.
  • Leave it in a package, and create a second package (Base-ng.jl?) that introduces more generic implementations of the necessary methods.

I suspect the second option is by far the better choice. I am uncertain how many methods from Base would need replacing; it could be anywhere from a couple dozen to possibly well over a hundred. To avoid a long scroll of "Method definition...overwritten" warnings, I propose we introduce an @overwrite macro to make it possible to suppress those warnings.

Thoughts? If you're willing, I can put this together.

@Keno
Copy link
Member

Keno commented Apr 29, 2016

FWIW, I've also wanted an @overwrite macro for JuliaParser, which can optionally replace base parse/include. For now I simply redirect STDERR while that's happening, so the user doesn't see the warnings ;).

@timholy
Copy link
Sponsor Member

timholy commented Apr 29, 2016

I thought about that, but what I don't like is the fact that other more serious problems might be hidden.

@tkelman
Copy link
Contributor

tkelman commented Apr 29, 2016

The potential for abuse here is really high, but I guess that's not a new or unique concern.

Is there a minimum level of indirection where some initial things could be stubbed out? Or a temporary new level in the abstract type hierarchy you could leverage? Actually making use of a heavily Base-overwriting package is just asking for #265 problems, isn't it?

@Keno
Copy link
Member

Keno commented Apr 29, 2016

Actually making use of a heavily Base-overwriting package is just asking for #265 problems, isn't it?

Yes, you have to be very careful.

@timholy
Copy link
Sponsor Member

timholy commented Apr 29, 2016

One possibility is to merge just types.jl and core.jl. That might be good enough. It won't give you much in the way of an implementation of, e.g., sparse-array handling, but that could come later (that's the main/only part that's largely unfinished). It does seem to mostly solve the main corner case for ReshapedArray performance, but until we can "allocate" immutables with references on the stack, ArrayIteration will never reach its real potential (and would likely make things much worse for small arrays). That, plus the fact that it hasn't been put to a serious test yet, makes it seem a little premature, esp. just before a release.

With regards to #265, it's hard to say, but I think it might work out. The problems arise only for array types that aren't in Base; presumably that means the only concerns are methods that explicitly disable specialization (ANY arguments). I haven't looked, but I bet we have relatively few of those that do much in the way of array computation.

@nalimilan
Copy link
Member

We could have an unexported macro, so that you would write Base.@overwrite, making it obvious this isn't supposed to be used in general.

@kmsquire
Copy link
Member

Also would like the @overwrite macro for kmsquire/Logging.jl#27.

@StefanKarpinski
Copy link
Sponsor Member

Wouldn't it make sense to be able to generally turn off/on warnings? This ties into needing the ability to have more sophisticated control of what to do with debug messages, warnings and errors.

@StefanKarpinski
Copy link
Sponsor Member

Of course, you don't want to miss other warnings that might occurs during the overwrite.

@timholy
Copy link
Sponsor Member

timholy commented May 1, 2016

Yes, I agree that we need some kind of general mechanism for this.

@ymer
Copy link

ymer commented Aug 17, 2016

These warnings are really bothersome with Jupyter notebook. It would be nice with an easy way to turn them off.

@KristofferC
Copy link
Sponsor Member

I agree. The reason for something being a warning and not an error is because there is legitimate use for it. And then it should be possible to do it silently. Like everyone else I have been solving this by temporarily redirect stderr but that hides other stuff so it isn't very good.

I thought about adding another field to JLOptions but that is immutable and you generally want to just disable this for a while and not for the whole session.

@XilinJia
Copy link

Allow me to easily turn off these redefinition warnings please! A zillion warning messages at REPL after the inclusion of a file the second time serves no help to anyone. They serve only on hiding meaningful warnings from the user. Please, let me be able to turn them off!

@ghost
Copy link

ghost commented Apr 28, 2017

I also would like to be able to turn off warnings. Mostly because I am writing extensive unit-tests and by the nature of unit-tests all kinds of warnings are triggered ( For example hints for the user that some of his input has been altered, because it was not in the right form ). All these warnings now appear in my unit-test output and it is all just noise to me, because these warnings are not for me.

@StefanKarpinski
Copy link
Sponsor Member

Not really the right place for that request – see the Julia discourse discussion forum or somewhere there's an issue about redirecting error output in general.

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.

None yet