From 94341804923c08fcfdd9e3bb19867feeb2e7af76 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 6 Jul 2021 18:20:28 -0400 Subject: [PATCH] fix #40773, bug in `summarysize` on arrays of inlined structs with pointers --- base/summarysize.jl | 5 +++-- test/misc.jl | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/base/summarysize.jl b/base/summarysize.jl index 8c0a38d5116484..1aa8a7803e0624 100644 --- a/base/summarysize.jl +++ b/base/summarysize.jl @@ -134,12 +134,13 @@ function (ss::SummarySize)(obj::Array) if !haskey(ss.seen, datakey) ss.seen[datakey] = true dsize = Core.sizeof(obj) - if isbitsunion(eltype(obj)) + T = eltype(obj) + if isbitsunion(T) # add 1 union selector byte for each element dsize += length(obj) end size += dsize - if !isempty(obj) && !Base.allocatedinline(eltype(obj)) + if !isempty(obj) && (!Base.allocatedinline(T) || (T isa DataType && !Base.datatype_pointerfree(T))) push!(ss.frontier_x, obj) push!(ss.frontier_i, 1) end diff --git a/test/misc.jl b/test/misc.jl index 37c5397b4948f4..e765dc9279b86d 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -302,6 +302,11 @@ let vec = vcat(missing, ones(100000)) @test length(unique(summarysize(vec) for i = 1:20)) == 1 end +# issue #40773 +let s = Set(1:100) + @test summarysize([s]) > summarysize(s) +end + # issue #13021 let ex = try Main.x13021 = 0