Skip to content

Commit 95f8175

Browse files
committed
Move gc and gc_enable to their own unexported module
We document that these functions should not generally be used, and yet they're exported from Base. This moves the two functions into their own submodule, Base.GCUtils.
1 parent 26a2ea2 commit 95f8175

File tree

20 files changed

+42
-13
lines changed

20 files changed

+42
-13
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ Deprecated or removed
948948
* `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`;
949949
`rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]).
950950

951+
* `gc` and `gc_enable` now live in the unexported module `Base.GCUtils` ([#TODO]).
952+
951953

952954
Command-line option changes
953955
---------------------------

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,9 @@ end
27942794
@deprecate findn(x::AbstractMatrix) (I = findall(!iszero, x); (getindex.(I, 1), getindex.(I, 2)))
27952795
@deprecate findn(x::AbstractArray{T, N}) where {T, N} (I = findall(!iszero, x); ntuple(i -> getindex.(I, i), N))
27962796

2797+
@deprecate gc Base.GCUtils.gc
2798+
@deprecate gc_enable Base.GCUtils.gc_enable
2799+
27972800
# issue #9053
27982801
if Sys.iswindows()
27992802
function Filesystem.tempname(uunique::UInt32)

base/exports.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,6 @@ export
904904
# RTS internals
905905
finalizer,
906906
finalize,
907-
gc,
908-
gc_enable,
909907
precompile,
910908

911909
# misc

base/gcutils.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,30 @@ Immediately run finalizers registered for object `x`.
3838
finalize(@nospecialize(o)) = ccall(:jl_finalize_th, Cvoid, (Ptr{Cvoid}, Any,),
3939
Core.getptls(), o)
4040

41+
module GCUtils
42+
43+
export gc, gc_enable
44+
4145
"""
4246
gc()
4347
44-
Perform garbage collection. This should not generally be used.
48+
Perform garbage collection.
49+
50+
!!! warning
51+
This should not generally be used.
4552
"""
4653
gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Int32,), full)
4754

4855
"""
4956
gc_enable(on::Bool)
5057
5158
Control whether garbage collection is enabled using a boolean argument (`true` for enabled,
52-
`false` for disabled). Return previous GC state. Disabling garbage collection should be
53-
used only with extreme caution, as it can cause memory use to grow without bound.
59+
`false` for disabled). Return previous GC state.
60+
61+
!!! warning
62+
Disabling garbage collection should be used only with extreme caution, as it can cause
63+
memory use to grow without bound.
5464
"""
5565
gc_enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0
66+
67+
end # module GCUtils

doc/src/base/base.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ Base.@functionloc
331331
## Internals
332332

333333
```@docs
334-
Base.gc
335-
Base.gc_enable
334+
Base.GCUtils.gc
335+
Base.GCUtils.gc_enable
336336
Meta.lower
337337
Meta.@lower
338338
Meta.parse(::AbstractString, ::Int)

stdlib/FileWatching/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Test, FileWatching
3+
using Test, FileWatching, Base.GCUtils
44

55
# This script does the following
66
# Sets up n unix pipes

stdlib/Mmap/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Test, Mmap, Random
3+
using Test, Mmap, Random, Base.GCUtils
44

55
file = tempname()
66
write(file, "Hello World\n")

stdlib/SharedArrays/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl"))
66
addprocs_with_testenv(4)
77
@test nprocs() == 5
88

9-
@everywhere using Test, SharedArrays
9+
@everywhere using Test, SharedArrays, Base.GCUtils
1010

1111
id_me = myid()
1212
id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]

stdlib/SparseArrays/test/sparse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Base.LinAlg: mul!, ldiv!, rdiv!
44
using Base.Printf: @printf
5+
using Base.GCUtils
56
using Random
67

78
@testset "issparse" begin

stdlib/SuiteSparse/test/cholmod.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SuiteSparse.CHOLMOD
44
using DelimitedFiles
55
using Test
6+
using Base.GCUtils
67

78
# CHOLMOD tests
89
srand(123)

0 commit comments

Comments
 (0)