From 40af668dd33cfba05ca41832bac8cd963e1d4ab0 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 8 Dec 2020 23:37:39 -0500 Subject: [PATCH] Don't accidentally skip over pointers in count_const_size 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 793f8756a094b0451a5211f4d199a0ddbaa814c9) --- base/compiler/utilities.jl | 11 +++++++---- test/compiler/inline.jl | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl index 37f4ce2f09340..60038cad7675d 100644 --- a/base/compiler/utilities.jl +++ b/base/compiler/utilities.jl @@ -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 diff --git a/test/compiler/inline.jl b/test/compiler/inline.jl index ee01feba3a1ff..e8b4c4f4cc77e 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -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))