Skip to content

Commit

Permalink
Add isdefined check count_const_size
Browse files Browse the repository at this point in the history
This doesn't do much currently, because we only call this function
on `Const` objects which we don't currently create if the initialization
of the object is incomplete, but we may want to do so in the future,
so might as well be defensive about it.

(cherry picked from commit 1327b5c)
  • Loading branch information
Keno authored and KristofferC committed Dec 11, 2020
1 parent c9c8ffd commit fbd4fc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function count_const_size(@nospecialize(x))
dtfd = DataTypeFieldDesc(dt)
for i = 1:nfields(x)
dtfd[i].isptr || continue
isdefined(x, i) || continue
sz += count_const_size(getfield(x, i))
sz > MAX_INLINE_CONST_SIZE && return MAX_INLINE_CONST_SIZE + 1
end
Expand Down
6 changes: 6 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,9 @@ let ci = code_typed(NonIsBitsDims, Tuple{})[1].first
@test length(ci.code) == 1 && isa(ci.code[1], ReturnNode) &&
ci.code[1].val.value == NonIsBitsDims()
end

struct NonIsBitsDimsUndef
dims::NTuple{N, Int} where N
NonIsBitsDimsUndef() = new()
end
@test Core.Compiler.is_inlineable_constant(NonIsBitsDimsUndef())

0 comments on commit fbd4fc3

Please sign in to comment.