Skip to content

Commit

Permalink
define isType in Base (JuliaLang#46326)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 13, 2022
1 parent 0e3e00d commit d2aedf4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 0 additions & 2 deletions base/compiler/typeutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# lattice utilities #
#####################

isType(@nospecialize t) = isa(t, DataType) && t.name === _TYPE_NAME

# true if Type{T} is inlineable as constant T
# requires that T is a singleton, s.t. T == S implies T === S
isconstType(@nospecialize t) = isType(t) && hasuniquerep(t.parameters[1])
Expand Down
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function firstcaller(bt::Vector, funcsyms)
li = lkup.linfo
if li isa Core.MethodInstance
ft = ccall(:jl_first_argument_datatype, Any, (Any,), (li.def::Method).sig)
if isa(ft, DataType) && ft.name === Type.body.name
if isType(ft)
ft = unwrap_unionall(ft.parameters[1])
found = (isa(ft, DataType) && ft.name.name in funcsyms)
end
Expand Down
2 changes: 1 addition & 1 deletion base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
# pool MethodErrors for these two functions.
if f === convert && !isempty(arg_types_param)
at1 = arg_types_param[1]
if isa(at1,DataType) && (at1::DataType).name === Type.body.name && !Core.Compiler.has_free_typevars(at1)
if isType(at1) && !Core.Compiler.has_free_typevars(at1)
push!(funcs, (at1.parameters[1], arg_types_param[2:end]))
end
end
Expand Down
6 changes: 4 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,14 @@ has_free_typevars(@nospecialize(t)) = ccall(:jl_has_free_typevars, Cint, (Any,),

# equivalent to isa(v, Type) && isdispatchtuple(Tuple{v}) || v === Union{}
# and is thus perhaps most similar to the old (pre-1.0) `isleaftype` query
const _TYPE_NAME = Type.body.name
function isdispatchelem(@nospecialize v)
return (v === Bottom) || (v === typeof(Bottom)) || isconcretedispatch(v) ||
(isa(v, DataType) && v.name === _TYPE_NAME && !has_free_typevars(v)) # isType(v)
(isType(v) && !has_free_typevars(v))
end

const _TYPE_NAME = Type.body.name
isType(@nospecialize t) = isa(t, DataType) && t.name === _TYPE_NAME

"""
isconcretetype(T)
Expand Down
3 changes: 1 addition & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2392,8 +2392,7 @@ function show_signature_function(io::IO, @nospecialize(ft), demangle=false, farg
end
s = sprint(show_sym, (demangle ? demangle_function_name : identity)(uw.name.mt.name), context=io)
print_within_stacktrace(io, s, bold=true)
elseif isa(ft, DataType) && ft.name === Type.body.name &&
(f = ft.parameters[1]; !isa(f, TypeVar))
elseif isType(ft) && (f = ft.parameters[1]; !isa(f, TypeVar))
uwf = unwrap_unionall(f)
parens = isa(f, UnionAll) && !(isa(uwf, DataType) && f === uwf.name.wrapper)
parens && print(io, "(")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function complete_symbol(sym::String, @nospecialize(ffunc), context_module::Modu
# Looking for a member of a type
if t isa DataType && t != Any
# Check for cases like Type{typeof(+)}
if t isa DataType && t.name === Base._TYPE_NAME
if Base.isType(t)
t = typeof(t.parameters[1])
end
# Only look for fields if this is a concrete type
Expand Down

0 comments on commit d2aedf4

Please sign in to comment.