From b038633dfa056c71c38d0ef319a5761caafa7c15 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Mon, 4 Dec 2023 16:08:12 -0500 Subject: [PATCH] Give a deprecation warning --- base/Base.jl | 4 ---- base/deprecated.jl | 5 +++++ base/exports.jl | 4 ---- base/stubs.jl | 29 +++++++++++++++++------------ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/base/Base.jl b/base/Base.jl index 4d3f24751709c..1d5a497df5987 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -377,10 +377,6 @@ using .CoreLogging include("env.jl") -# functions defined in Random -function rand end -function randn end - # I/O include("libuv.jl") include("asyncevent.jl") diff --git a/base/deprecated.jl b/base/deprecated.jl index cfccb35d98bad..0939140f043d8 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -392,4 +392,9 @@ end @deprecate permute!!(a, p::AbstractVector{<:Integer}) permute!(a, p) false @deprecate invpermute!!(a, p::AbstractVector{<:Integer}) invpermute!(a, p) false +# functions defined in Random +function rand end +function randn end +export rand, randn + # END 1.11 deprecations diff --git a/base/exports.jl b/base/exports.jl index 398d828f9cf19..f05647a2597dd 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -994,10 +994,6 @@ export unsafe_store!, unsafe_swap!, -# implemented in Random module - rand, - randn, - # Macros # parser internal @__FILE__, diff --git a/base/stubs.jl b/base/stubs.jl index baaf1f72fef73..f3c74ddda7e08 100644 --- a/base/stubs.jl +++ b/base/stubs.jl @@ -1,6 +1,21 @@ module Stubs +macro stub(old, mod) + dep_message = """: `$old` has been moved to the standard library package `$mod`. + Add `using $mod` to your imports.""" + return Expr(:toplevel, + quote + import Base: $old + function $(esc(old))(args...) + Base.depwarn($dep_message, $(QuoteNode(old))) + Base.invoke_in_world($(esc(:delay_initialize))(), $(esc(old)), args...) + end + Base.Docs.getdoc(::typeof($(esc(old)))) = ($(esc(:delay_initialize))(); nothing) + end) +end + module Random + import ..Stubs: @stub let Random_PkgID = Base.PkgId(Base.UUID(0x9a3f8284_a2c9_5f02_9a11_845980a1fd5c), "Random") RANDOM_MODULE_REF = Ref{Module}() @@ -12,20 +27,10 @@ module Random return ccall(:jl_module_world, Csize_t, (Any,), RANDOM_MODULE_REF[]) end end - - import Base: rand, randn - function rand(args...) - Base.invoke_in_world(delay_initialize(), rand, args...) - end - - function randn(args...) - Base.invoke_in_world(delay_initialize(), randn, args...) - end + @stub rand Random + @stub randn Random end -Base.Docs.getdoc(::typeof(Base.rand)) = (Random.delay_initialize(); nothing) -Base.Docs.getdoc(::typeof(Base.randn)) = (Random.delay_initialize(); nothing) - function delete_stubs(mod) for name in names(mod, imported=true) if name == :delay_initialize