Skip to content

Commit

Permalink
refine effects of some reflection queries (#51235)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash authored Sep 8, 2023
1 parent a7697fd commit 8e77b63
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,20 +383,23 @@ 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
return a
end

function rewrap_unionall(@nospecialize(t), @nospecialize(u))
@_foldable_meta
if !isa(u, UnionAll)
return t
end
return UnionAll(u.var, rewrap_unionall(t, u.body))
end

function rewrap_unionall(t::Core.TypeofVararg, @nospecialize(u))
@_foldable_meta
isdefined(t, :T) || return t
if !isa(u, UnionAll)
return t
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
)
Expand Down

2 comments on commit 8e77b63

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.