Skip to content

Commit

Permalink
Move gc and gc_enable to their own unexported module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ararslan committed Jan 17, 2018
1 parent 26a2ea2 commit 95f8175
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,8 @@ Deprecated or removed
* `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`;
`rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]).

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


Command-line option changes
---------------------------
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2794,6 +2794,9 @@ end
@deprecate findn(x::AbstractMatrix) (I = findall(!iszero, x); (getindex.(I, 1), getindex.(I, 2)))
@deprecate findn(x::AbstractArray{T, N}) where {T, N} (I = findall(!iszero, x); ntuple(i -> getindex.(I, i), N))

@deprecate gc Base.GCUtils.gc
@deprecate gc_enable Base.GCUtils.gc_enable

# issue #9053
if Sys.iswindows()
function Filesystem.tempname(uunique::UInt32)
Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,6 @@ export
# RTS internals
finalizer,
finalize,
gc,
gc_enable,
precompile,

# misc
Expand Down
18 changes: 15 additions & 3 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,30 @@ Immediately run finalizers registered for object `x`.
finalize(@nospecialize(o)) = ccall(:jl_finalize_th, Cvoid, (Ptr{Cvoid}, Any,),
Core.getptls(), o)

module GCUtils

export gc, gc_enable

"""
gc()
Perform garbage collection. This should not generally be used.
Perform garbage collection.
!!! warning
This should not generally be used.
"""
gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Int32,), full)

"""
gc_enable(on::Bool)
Control whether garbage collection is enabled using a boolean argument (`true` for enabled,
`false` for disabled). Return previous GC state. Disabling garbage collection should be
used only with extreme caution, as it can cause memory use to grow without bound.
`false` for disabled). Return previous GC state.
!!! warning
Disabling garbage collection should be used only with extreme caution, as it can cause
memory use to grow without bound.
"""
gc_enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0

end # module GCUtils
4 changes: 2 additions & 2 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ Base.@functionloc
## Internals

```@docs
Base.gc
Base.gc_enable
Base.GCUtils.gc
Base.GCUtils.gc_enable
Meta.lower
Meta.@lower
Meta.parse(::AbstractString, ::Int)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/FileWatching/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test, FileWatching
using Test, FileWatching, Base.GCUtils

# This script does the following
# Sets up n unix pipes
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Mmap/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test, Mmap, Random
using Test, Mmap, Random, Base.GCUtils

file = tempname()
write(file, "Hello World\n")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/SharedArrays/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(joinpath(Sys.BINDIR, "..", "share", "julia", "test", "testenv.jl"))
addprocs_with_testenv(4)
@test nprocs() == 5

@everywhere using Test, SharedArrays
@everywhere using Test, SharedArrays, Base.GCUtils

id_me = myid()
id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]
Expand Down
1 change: 1 addition & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Base.LinAlg: mul!, ldiv!, rdiv!
using Base.Printf: @printf
using Base.GCUtils
using Random

@testset "issparse" begin
Expand Down
1 change: 1 addition & 0 deletions stdlib/SuiteSparse/test/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SuiteSparse.CHOLMOD
using DelimitedFiles
using Test
using Base.GCUtils

# CHOLMOD tests
srand(123)
Expand Down
1 change: 1 addition & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Base.copy, Base.==
using Random
using Base.GCUtils

import Libdl

Expand Down
1 change: 1 addition & 0 deletions test/channels.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Random
using Base.GCUtils

# Test various constructors
let c = Channel(1)
Expand Down
1 change: 1 addition & 0 deletions test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# tests for codegen and optimizations

using Random
using Base.GCUtils

const opt_level = Base.JLOptions().opt_level
const coverage = (Base.JLOptions().code_coverage > 0) || (Base.JLOptions().malloc_log > 0)
Expand Down
3 changes: 2 additions & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

# test core language features

using Base.GCUtils
using Random
using SparseArrays

const Bottom = Union{}

using SparseArrays

# For curmod_*
include("testenv.jl")
Expand Down
4 changes: 3 additions & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base.GCUtils

# Tests that do not really go anywhere else

# test assert() method
Expand Down Expand Up @@ -646,4 +648,4 @@ end
module A
export missing
varinfo(A)
end
end
2 changes: 2 additions & 0 deletions test/netload/memtest.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base.GCUtils

struct RUsage
ru_utime_sec::Clong # user CPU time used
ru_utime_usec::Clong # user CPU time used
Expand Down
2 changes: 2 additions & 0 deletions test/perf/kernel/perf.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base.GCUtils

include("../perfutil.jl")

abstract type List{T} end
Expand Down
2 changes: 1 addition & 1 deletion test/perf/perfutil.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Printf, Random
using Printf, Random, Base.GCUtils

const mintrials = 5
const mintime = 2000.0
Expand Down
1 change: 1 addition & 0 deletions test/perf/sort/perf.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Base.GCUtils
import Base.Sort: QuickSort, MergeSort, InsertionSort

Pkg.add("SortingAlgorithms")
Expand Down
1 change: 1 addition & 0 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Test
using Base.Threads
using Base.GCUtils

# threading constructs

Expand Down

0 comments on commit 95f8175

Please sign in to comment.