Skip to content

Commit

Permalink
Don't accidentally skip over pointers in count_const_size
Browse files Browse the repository at this point in the history
Since we can inline pointer-containing structs into other structs now,
an `isptr` check is insufficient to determine whether or not we need
to recurse here. Also check the actual type of the field in addition.

(cherry picked from commit 793f875)
  • Loading branch information
Keno authored and KristofferC committed Dec 11, 2020
1 parent fbd4fc3 commit 40af668
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ function quoted(@nospecialize(x))
return is_self_quoting(x) ? x : QuoteNode(x)
end

function count_const_size(@nospecialize(x))
function count_const_size(@nospecialize(x), count_self::Bool = true)
(x isa Type || x isa Symbol) && return 0
ismutable(x) && return MAX_INLINE_CONST_SIZE + 1
isbits(x) && return Core.sizeof(x)
dt = typeof(x)
sz = sizeof(dt)
sz = count_self ? sizeof(dt) : 0
sz > MAX_INLINE_CONST_SIZE && return MAX_INLINE_CONST_SIZE + 1
dtfd = DataTypeFieldDesc(dt)
for i = 1:nfields(x)
dtfd[i].isptr || continue
isdefined(x, i) || continue
sz += count_const_size(getfield(x, i))
f = getfield(x, i)
if !dtfd[i].isptr && datatype_pointerfree(typeof(f))
continue
end
sz += count_const_size(f, dtfd[i].isptr)
sz > MAX_INLINE_CONST_SIZE && return MAX_INLINE_CONST_SIZE + 1
end
return sz
Expand Down
1 change: 1 addition & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,4 @@ struct NonIsBitsDimsUndef
NonIsBitsDimsUndef() = new()
end
@test Core.Compiler.is_inlineable_constant(NonIsBitsDimsUndef())
@test !Core.Compiler.is_inlineable_constant((("a"^1000, "b"^1000), nothing))

0 comments on commit 40af668

Please sign in to comment.