Skip to content

Commit 7cd11a6

Browse files
authored
Enable suppression of warnings from ambiguity & unbound tests (#43817)
* Revert "filesystem & binaryplatforms: remove undefined vars from exports (#43631)" This reverts commit a3c2798. * Enable suppression of warnings in ambiguity & undefined tests
1 parent 4842007 commit 7cd11a6

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

base/filesystem.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export File,
4343
JL_O_CREAT,
4444
JL_O_EXCL,
4545
JL_O_TRUNC,
46+
JL_O_TEMPORARY,
47+
JL_O_SHORT_LIVED,
48+
JL_O_SEQUENTIAL,
49+
JL_O_RANDOM,
4650
JL_O_NOCTTY,
4751
S_IRUSR, S_IWUSR, S_IXUSR, S_IRWXU,
4852
S_IRGRP, S_IWGRP, S_IXGRP, S_IRWXG,

stdlib/Test/src/Test.jl

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,9 @@ function is_in_mods(m::Module, recursive::Bool, mods)
16601660
end
16611661

16621662
"""
1663-
detect_ambiguities(mod1, mod2...; recursive=false, ambiguous_bottom=false)
1663+
detect_ambiguities(mod1, mod2...; recursive=false,
1664+
ambiguous_bottom=false,
1665+
allowed_undefineds=nothing)
16641666
16651667
Returns a vector of `(Method,Method)` pairs of ambiguous methods
16661668
defined in the specified modules.
@@ -1669,10 +1671,17 @@ Use `recursive=true` to test in all submodules.
16691671
`ambiguous_bottom` controls whether ambiguities triggered only by
16701672
`Union{}` type parameters are included; in most cases you probably
16711673
want to set this to `false`. See [`Base.isambiguous`](@ref).
1674+
1675+
See [`Test.detect_unbound_args`](@ref) for an explanation of
1676+
`allowed_undefineds`.
1677+
1678+
!!! compat "Julia 1.8"
1679+
`allowed_undefineds` requires at least Julia 1.8.
16721680
"""
16731681
function detect_ambiguities(mods::Module...;
16741682
recursive::Bool = false,
1675-
ambiguous_bottom::Bool = false)
1683+
ambiguous_bottom::Bool = false,
1684+
allowed_undefineds = nothing)
16761685
@nospecialize
16771686
ambs = Set{Tuple{Method,Method}}()
16781687
mods = collect(mods)::Vector{Module}
@@ -1709,7 +1718,11 @@ function detect_ambiguities(mods::Module...;
17091718
for n in names(mod, all = true)
17101719
Base.isdeprecated(mod, n) && continue
17111720
if !isdefined(mod, n)
1712-
is_in_mods(mod, recursive, mods) && println("Skipping ", mod, '.', n) # typically stale exports
1721+
if is_in_mods(mod, recursive, mods)
1722+
if allowed_undefineds === nothing || GlobalRef(mod, n) allowed_undefineds
1723+
println("Skipping ", mod, '.', n) # typically stale exports
1724+
end
1725+
end
17131726
continue
17141727
end
17151728
f = Base.unwrap_unionall(getfield(mod, n))
@@ -1726,13 +1739,29 @@ function detect_ambiguities(mods::Module...;
17261739
end
17271740

17281741
"""
1729-
detect_unbound_args(mod1, mod2...; recursive=false)
1742+
detect_unbound_args(mod1, mod2...; recursive=false, allowed_undefineds=nothing)
17301743
17311744
Returns a vector of `Method`s which may have unbound type parameters.
17321745
Use `recursive=true` to test in all submodules.
1746+
1747+
By default, any undefined symbols trigger a warning. This warning can
1748+
be suppressed by supplying a collection of `GlobalRef`s for which
1749+
the warning can be skipped. For example, setting
1750+
1751+
```
1752+
allow_undefineds = Set([GlobalRef(Base, :active_repl),
1753+
GlobalRef(Base, :active_repl_backend)])
1754+
```
1755+
1756+
would suppress warnings about `Base.active_repl` and
1757+
`Base.active_repl_backend`.
1758+
1759+
!!! compat "Julia 1.8"
1760+
`allowed_undefineds` requires at least Julia 1.8.
17331761
"""
17341762
function detect_unbound_args(mods...;
1735-
recursive::Bool = false)
1763+
recursive::Bool = false,
1764+
allowed_undefineds=nothing)
17361765
@nospecialize mods
17371766
ambs = Set{Method}()
17381767
mods = collect(mods)::Vector{Module}
@@ -1760,7 +1789,11 @@ function detect_unbound_args(mods...;
17601789
for n in names(mod, all = true)
17611790
Base.isdeprecated(mod, n) && continue
17621791
if !isdefined(mod, n)
1763-
is_in_mods(mod, recursive, mods) && println("Skipping ", mod, '.', n) # typically stale exports
1792+
if is_in_mods(mod, recursive, mods)
1793+
if allowed_undefineds === nothing || GlobalRef(mod, n) allowed_undefineds
1794+
println("Skipping ", mod, '.', n) # typically stale exports
1795+
end
1796+
end
17641797
continue
17651798
end
17661799
f = Base.unwrap_unionall(getfield(mod, n))

test/ambiguous.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ ambig(x::Union{Char, Int16}) = 's'
100100
@test ambig(Int16(1)) == 's'
101101

102102
# Automatic detection of ambiguities
103+
104+
const allowed_undefineds = Set([
105+
GlobalRef(Base, :active_repl),
106+
GlobalRef(Base, :active_repl_backend),
107+
GlobalRef(Base.Filesystem, :JL_O_TEMPORARY),
108+
GlobalRef(Base.Filesystem, :JL_O_SHORT_LIVED),
109+
GlobalRef(Base.Filesystem, :JL_O_SEQUENTIAL),
110+
GlobalRef(Base.Filesystem, :JL_O_RANDOM),
111+
])
112+
113+
let Distributed = get(Base.loaded_modules,
114+
Base.PkgId(Base.UUID("8ba89e20-285c-5b6f-9357-94700520ee1b"), "Distributed"),
115+
nothing)
116+
if Distributed !== nothing
117+
push!(allowed_undefineds, GlobalRef(Distributed, :cluster_manager))
118+
end
119+
end
120+
103121
module Ambig1
104122
ambig(x, y) = 1
105123
ambig(x::Integer, y) = 2
@@ -153,7 +171,7 @@ using LinearAlgebra, SparseArrays, SuiteSparse
153171
# Test that Core and Base are free of ambiguities
154172
# not using isempty so this prints more information when it fails
155173
@testset "detect_ambiguities" begin
156-
let ambig = Set{Any}(((m1.sig, m2.sig) for (m1, m2) in detect_ambiguities(Core, Base; recursive=true, ambiguous_bottom=false)))
174+
let ambig = Set{Any}(((m1.sig, m2.sig) for (m1, m2) in detect_ambiguities(Core, Base; recursive=true, ambiguous_bottom=false, allowed_undefineds)))
157175
@test isempty(ambig)
158176
expect = []
159177
good = true
@@ -183,7 +201,7 @@ using LinearAlgebra, SparseArrays, SuiteSparse
183201

184202
# List standard libraries. Exclude modules such as Main, Base, and Core.
185203
let modules = [mod for (pkg, mod) in Base.loaded_modules if pkg.uuid !== nothing && String(pkg.name) in STDLIBS]
186-
@test isempty(detect_ambiguities(modules...; recursive=true))
204+
@test isempty(detect_ambiguities(modules...; recursive=true, allowed_undefineds))
187205
end
188206
end
189207

@@ -313,7 +331,7 @@ end
313331
@test need_to_handle_undef_sparam == Set()
314332
end
315333
let need_to_handle_undef_sparam =
316-
Set{Method}(detect_unbound_args(Base; recursive=true))
334+
Set{Method}(detect_unbound_args(Base; recursive=true, allowed_undefineds))
317335
pop!(need_to_handle_undef_sparam, which(Base._totuple, (Type{Tuple{Vararg{E}}} where E, Any, Any)))
318336
pop!(need_to_handle_undef_sparam, which(Base.eltype, Tuple{Type{Tuple{Any}}}))
319337
pop!(need_to_handle_undef_sparam, first(methods(Base.same_names)))

0 commit comments

Comments
 (0)