Skip to content

Add default --warn-overwrite=default for cross-module warnings#61430

Open
PatrickHaecker wants to merge 3 commits into
JuliaLang:masterfrom
PatrickHaecker:warn_overwrite_cross_modules
Open

Add default --warn-overwrite=default for cross-module warnings#61430
PatrickHaecker wants to merge 3 commits into
JuliaLang:masterfrom
PatrickHaecker:warn_overwrite_cross_modules

Conversation

@PatrickHaecker
Copy link
Copy Markdown
Contributor

@PatrickHaecker PatrickHaecker commented Mar 29, 2026

Add a third mode autodefault to --warn-overwrite and make it the default. In default mode, method overwrite warnings are only shown when they are likely a problem. Currently this means they are shown when the new definition comes from a different module than the original. In this situation, precompilation would error, so warning about it in interactive use gives users early feedback. Precompilation also errors when the redefinition is in the same module, but warning on this, too (as in --warn-overwrite=yes), is noisy for the common case of re-evaluating code within the same module.

--warn-overwrite=yes and --warn-overwrite=no retain their existing behavior (warn on all overwrites or none, respectively). Anonymous function overwrites continue to always warn regardless of the setting. We keep --warn-overwrite=yes for cases where it is clearly beneficial like creating the sysimage.

Previous work with discussions: #23002 and #23030.

This implements the idea first proposed by @martinholters in the discussion and uses default as defined by triage.

Partly fixes #61388

This PR was created with support from Claude Opus 4.6 and 4.7.

Comment thread doc/man/julia.1 Outdated
.TP
--warn-overwrite={yes|no*}
Enable or disable method overwrite warnings
--warn-overwrite={yes|no|auto*}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

auto doesn't strike me as particularly descriptive

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for having a look.
This is a compromise I wasn't too happy with, too. It follows the symmetry with --check-bounds, --color and the like and would have the advantage (with a proper wording, which I probably don't have here), that we could adjust the rules slightly when we learn something while keeping the CLI value being auto.

What about crossmod? Would that work for you, @Keno?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe foreign? external? outside?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I think all (now 5) proposals are good if you know what what they are doing, but I fear none of them are self-explanatory. I do not have any preference here. If anyone has a favorite, please tell me, so I'll change to it.
Or is triage interested in bikeshedding naming? :-)

@Keno Keno added the triage This should be discussed on a triage call label Mar 30, 2026
Comment thread NEWS.md Outdated
@JeffBezanson
Copy link
Copy Markdown
Member

👍 From triage. We think auto suggests that it automatically picks either yes or no, which is not what it does. We think it can be called default, suitably vague so that we can possibly change the heuristic used in the future.

@JeffBezanson JeffBezanson removed the triage This should be discussed on a triage call label May 7, 2026
@JeffBezanson
Copy link
Copy Markdown
Member

We should also make sure this is not causing tons of spurious warnings in CI or elsewhere.

@JeffBezanson
Copy link
Copy Markdown
Member

OK this does surface a couple warnings in CI, some of which are intentional overwrites, so we will need to silence some cases and maybe fix others.

Patrick Häcker and others added 2 commits May 10, 2026 08:35
Add a third mode `auto` to --warn-overwrite={yes|no|auto} and make it the
default. In `auto` mode, method overwrite warnings are shown only when the
new definition comes from a different module than the original. This is the
case that would error during precompilation, so warning about it in
interactive use gives users early feedback without being noisy for the
common case of re-evaluating code within the same module.

`--warn-overwrite=yes` and `--warn-overwrite=no` retain their existing
behavior (warn on all overwrites or none, respectively). Anonymous
function overwrites continue to always warn regardless of the setting.

We keep `--warn-overwrite=yes` for cases where it is clearly beneficial
like creating the sysimage.

Previous work with discussions: JuliaLang#23002, JuliaLang#23030

This implements the idea first proposed by @martinholters in the discussion.

Partly fixes JuliaLang#61388

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
- Switch to `default` as defined by triage
- Use a more vague wording in documentation to indicate that the implementation can evolve in the future
- Fix the at least misleading if not incorrect wording in NEWS.

Co-authored-by: Copilot <copilot@github.com>
@PatrickHaecker PatrickHaecker force-pushed the warn_overwrite_cross_modules branch from 57022ed to a6809ed Compare May 10, 2026 06:36
@giordano giordano changed the title Add default --warn-overwrite=auto for cross-module warnings Add default --warn-overwrite=default for cross-module warnings May 11, 2026
The original idea was to always warn when redefining a method except when it happens in the same module to avoid warnings when using the REPL.

However, this produces a lot of warnings, especially when redefining a module, e.g. by `include`ing a file with a module definition. The reason is that
```julia
module A end; a = A; module A end; a == A
```
returns `false` as the module identity changes when redefining a module. Therefore, the modules' name should be compared. However, as two submodules can have totally different parent modules, the fully qualified name of the modules should actually be compared.

Except that we have some possibly questionable use of some macros like `@deprecate` or where the same file is included in a module and its submodule. You can argue that overwriting a method from a submodule or from a parent module is at least something where the author is in full control similar to overwrites in a module. Therefore, at least to limit the number of warnings this change will generate, but possibly because it makes sense, do not warn in these cases.

Combining everything means we should only warn if the FQN of one module is not a prefix of the other's module.

Co-authored-by: Copilot <copilot@github.com>
@PatrickHaecker
Copy link
Copy Markdown
Contributor Author

PatrickHaecker commented May 14, 2026

OK this does surface a couple warnings in CI, some of which are intentional overwrites, so we will need to silence some cases and maybe fix others.

I am on a voyage to silence the CI warnings.

The original idea was to always warn when redefining a method except when it happens in the same module to avoid warnings when using the REPL.

However, this produces a lot of warnings, especially when redefining a module, e.g. by reincludeing a file with a module definition. The reason is that

module A end; a = A; module A end; a == A

returns false as the module identity changes when redefining a module. Therefore, the modules' name should be compared. However, as two identically named submodules can have totally different parent modules, the fully qualified name of the modules should actually be compared.

Except that we have some possibly questionable use of some macros like @deprecate or repositories where the same file is included in a module and its submodule. You can argue that overwriting a method from a submodule or from a parent module is at least something where the author is in full control similar to overwrites in a module. Therefore, at least to limit the number of warnings this change will generate, but possibly because it makes sense, do not warn in these cases.

Combining everything means we should only warn if the FQN of one module is not a prefix of the other's module.

Now we still have some issues in Julia itself and then it would be interesting to see what Pkgeval brings up. I am still pretty sure that something like this is a good idea. I am less convinced that we can activate it as default without creating too much effort in the ecosystem. But we'll see.

@PatrickHaecker
Copy link
Copy Markdown
Contributor Author

With the PR for SparseArrays.jl I think Julia itself does not have additional warnings due to this PR (but I am not sure, so if anyone knows a method where the result is a reliable number of overall warnings during building and testing, I am all ear).

As you @fingolfin seem to be interested in this feature, could you please trigger @nanosoldier runtests() and @nanosoldier runbenchmarks() on this PR? It would be interesting to see how many additional warnings this will produce in the ecosystem and whether the additional logic in method_overwrite makes something slower.

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.

Identical method definition in different packages should not error

4 participants