From 8e77b63fa7636f84767329dd298817d0a36b5ae3 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 8 Sep 2023 10:59:21 -0400 Subject: [PATCH] refine effects of some reflection queries (#51235) --- base/essentials.jl | 4 ++++ base/reflection.jl | 4 ++++ src/jltypes.c | 2 +- test/core.jl | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/base/essentials.jl b/base/essentials.jl index db47f1ee7f2c1..4323052d540da 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -383,6 +383,7 @@ tail(x::Tuple) = argtail(x...) tail(::Tuple{}) = throw(ArgumentError("Cannot call tail on an empty tuple.")) function unwrap_unionall(@nospecialize(a)) + @_foldable_meta while isa(a,UnionAll) a = a.body end @@ -390,6 +391,7 @@ function unwrap_unionall(@nospecialize(a)) end function rewrap_unionall(@nospecialize(t), @nospecialize(u)) + @_foldable_meta if !isa(u, UnionAll) return t end @@ -397,6 +399,7 @@ function rewrap_unionall(@nospecialize(t), @nospecialize(u)) end function rewrap_unionall(t::Core.TypeofVararg, @nospecialize(u)) + @_foldable_meta isdefined(t, :T) || return t if !isa(u, UnionAll) return t @@ -424,6 +427,7 @@ function isvarargtype(@nospecialize(t)) end function isvatuple(@nospecialize(t)) + @_foldable_meta t = unwrap_unionall(t) if isa(t, DataType) n = length(t.parameters) diff --git a/base/reflection.jl b/base/reflection.jl index 242d628161928..8a74099039da5 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -257,11 +257,13 @@ end Determine whether a field `s` is declared `const` in a given type `t`. """ function isconst(@nospecialize(t::Type), s::Symbol) + @_foldable_meta t = unwrap_unionall(t) isa(t, DataType) || return false return isconst(t, fieldindex(t, s, false)) end function isconst(@nospecialize(t::Type), s::Int) + @_foldable_meta t = unwrap_unionall(t) # TODO: what to do for `Union`? isa(t, DataType) || return false # uncertain @@ -279,11 +281,13 @@ end Determine whether a field `s` is declared `@atomic` in a given type `t`. """ function isfieldatomic(@nospecialize(t::Type), s::Symbol) + @_foldable_meta t = unwrap_unionall(t) isa(t, DataType) || return false return isfieldatomic(t, fieldindex(t, s, false)) end function isfieldatomic(@nospecialize(t::Type), s::Int) + @_foldable_meta t = unwrap_unionall(t) # TODO: what to do for `Union`? isa(t, DataType) || return false # uncertain diff --git a/src/jltypes.c b/src/jltypes.c index 15da9448fa3e1..4e566339e3014 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -2610,7 +2610,7 @@ void jl_init_types(void) JL_GC_DISABLED "hash", "n_uninitialized", "flags", // "abstract", "mutable", "mayinlinealloc", "max_methods"); - const static uint32_t typename_constfields[1] = { 0x00003a3f }; // (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<9)|(1<<11)|(1<<12)|(1<<13) + const static uint32_t typename_constfields[1] = { 0x00003a27 }; // (1<<0)|(1<<1)|(1<<2)|(1<<5)|(1<<9)|(1<<11)|(1<<12)|(1<<13) ; TODO: put back (1<<3)|(1<<4) in this list const static uint32_t typename_atomicfields[1] = { 0x00000180 }; // (1<<7)|(1<<8) jl_typename_type->name->constfields = typename_constfields; jl_typename_type->name->atomicfields = typename_atomicfields; diff --git a/test/core.jl b/test/core.jl index e65cf08be9e15..658cbd63da181 100644 --- a/test/core.jl +++ b/test/core.jl @@ -20,7 +20,7 @@ for (T, c) in ( (Core.MethodTable, [:module]), (Core.TypeMapEntry, [:sig, :simplesig, :guardsigs, :min_world, :max_world, :func, :isleafsig, :issimplesig, :va]), (Core.TypeMapLevel, []), - (Core.TypeName, [:name, :module, :names, :atomicfields, :constfields, :wrapper, :mt, :hash, :n_uninitialized, :flags]), + (Core.TypeName, [:name, :module, :names, :wrapper, :mt, :hash, :n_uninitialized, :flags]), (DataType, [:name, :super, :parameters, :instance, :hash]), (TypeVar, [:name, :ub, :lb]), )