Skip to content

Commit

Permalink
Give a deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Dec 4, 2023
1 parent b9f4db6 commit b038633
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
4 changes: 0 additions & 4 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,6 @@ export
unsafe_store!,
unsafe_swap!,

# implemented in Random module
rand,
randn,

# Macros
# parser internal
@__FILE__,
Expand Down
29 changes: 17 additions & 12 deletions base/stubs.jl
Original file line number Diff line number Diff line change
@@ -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}()

Expand All @@ -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
Expand Down

0 comments on commit b038633

Please sign in to comment.