Skip to content

Simplify the GC.gc interface #34303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,20 @@ Module with garbage collection utilities.
"""
module GC

# @enum-like structure
struct CollectionType
x::Int
end
Base.cconvert(::Type{Cint}, collection::CollectionType) = Cint(collection.x)

const Auto = CollectionType(0)
const Full = CollectionType(1)
const Incremental = CollectionType(2)

"""
GC.gc(full::Bool=true)
GC.gc(collection::CollectionType)
GC.gc()
GC.gc(full::Bool)

Perform garbage collection. The argument `full` determines whether a full, but more costly
collection is performed. Otherwise, heuristics are used to determine which type of
collection is needed. For exact control, pass an argument of type `CollectionType`.
Perform garbage collection. The argument `full` determines the kind of collection: A full
collection scans all objects, while an incremental collection only scans so-called young
objects and is much quicker. If called without an argument, heuristics are used to determine
which type of collection is needed.

!!! warning
Excessive use will likely lead to poor performance.
"""
gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Cint,), full)
gc(collection::CollectionType) = ccall(:jl_gc_collect, Cvoid, (Cint,), collection)
gc() = ccall(:jl_gc_collect, Cvoid, (Cint,), 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, read this too quickly since it was supposed to be not a breaking change. This was a breaking change (as in CI has been broken for a week now because of this PR):

Suggested change
gc() = ccall(:jl_gc_collect, Cvoid, (Cint,), 0)
gc() = ccall(:jl_gc_collect, Cvoid, (Cint,), 1)

Please, please, please be careful about merging PRs that fail on CI (as this one did).

Copy link
Member

@StefanKarpinski StefanKarpinski Jan 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if they are not wrapped in a type or user-facing, it might be good for this code to use locally-defined constants to make the code easier to read. My understanding is that these are the values:

const GC_AUTO = 0
const GC_FULL = 1
const GC_INCR = 2

Is that correct? If so, it would be good to define these constants and then use them in the method definitions. I guess the issue is that the default previously was GC_FULL rather than GC_AUTO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crap, sorry for that, I had been too accustomed to win32 failing recently...

Even if they are not wrapped in a type or user-facing, it might be good for this code to use locally-defined constants to make the code easier to read.

Agreed, I'll see about improving that next week.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crap, sorry for that, I had been too accustomed to win32 failing recently...

💯 I wouldn't blame you here. CI needs to be fixed. The situation is atrocious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I rather regret not merging #33741 to fix a major contributor months ago, but we really need to prioritize getting the other known fixes merged (#34336, #33785, and #34242 at least) too.

gc(full::Bool) = ccall(:jl_gc_collect, Cvoid, (Cint,), full ? 1 : 2)

"""
GC.enable(on::Bool)
Expand Down
1 change: 0 additions & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ end
@testset "GC utilities" begin
GC.gc()
GC.gc(true); GC.gc(false)
GC.gc(GC.Auto); GC.gc(GC.Full); GC.gc(GC.Incremental)

GC.safepoint()
end