Skip to content

Commit 2c369bf

Browse files
authored
separate isbitstype(::Type) from isbits (#26850)
1 parent 6e05a48 commit 2c369bf

30 files changed

+81
-63
lines changed

base/Enums.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ macro enum(T, syms...)
7575
if isa(T, Expr) && T.head == :(::) && length(T.args) == 2 && isa(T.args[1], Symbol)
7676
typename = T.args[1]
7777
basetype = eval(__module__, T.args[2])
78-
if !isa(basetype, DataType) || !(basetype <: Integer) || !isbits(basetype)
78+
if !isa(basetype, DataType) || !(basetype <: Integer) || !isbitstype(basetype)
7979
throw(ArgumentError("invalid base type for Enum $typename, $T=::$basetype; base type must be an integer primitive type"))
8080
end
8181
elseif !isa(T, Symbol)

base/array.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ asize_from(a::Array, n) = n > ndims(a) ? () : (arraysize(a,n), asize_from(a, n+1
116116
"""
117117
Base.isbitsunion(::Type{T})
118118
119-
Return whether a type is an "is-bits" Union type, meaning each type included in a Union is `isbits`.
119+
Return whether a type is an "is-bits" Union type, meaning each type included in a Union is `isbitstype`.
120120
"""
121121
isbitsunion(u::Union) = ccall(:jl_array_store_unboxed, Cint, (Any,), u) == Cint(1)
122122
isbitsunion(x) = false
123123

124124
"""
125125
Base.bitsunionsize(U::Union)
126126
127-
For a Union of `isbits` types, return the size of the largest type; assumes `Base.isbitsunion(U) == true`
127+
For a Union of `isbitstype` types, return the size of the largest type; assumes `Base.isbitsunion(U) == true`
128128
"""
129129
function bitsunionsize(u::Union)
130130
sz = Ref{Csize_t}(0)
@@ -134,7 +134,7 @@ function bitsunionsize(u::Union)
134134
end
135135

136136
length(a::Array) = arraylen(a)
137-
elsize(::Type{<:Array{T}}) where {T} = isbits(T) ? sizeof(T) : (isbitsunion(T) ? bitsunionsize(T) : sizeof(Ptr))
137+
elsize(::Type{<:Array{T}}) where {T} = isbitstype(T) ? sizeof(T) : (isbitsunion(T) ? bitsunionsize(T) : sizeof(Ptr))
138138
sizeof(a::Array) = Core.sizeof(a)
139139

140140
function isassigned(a::Array, i::Int...)
@@ -177,7 +177,7 @@ the same manner as C.
177177
function unsafe_copyto!(dest::Array{T}, doffs, src::Array{T}, soffs, n) where T
178178
t1 = @_gc_preserve_begin dest
179179
t2 = @_gc_preserve_begin src
180-
if isbits(T)
180+
if isbitstype(T)
181181
unsafe_copyto!(pointer(dest, doffs), pointer(src, soffs), n)
182182
elseif isbitsunion(T)
183183
ccall(:memmove, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}, UInt),
@@ -1477,7 +1477,7 @@ function vcat(arrays::Vector{T}...) where T
14771477
end
14781478
arr = Vector{T}(undef, n)
14791479
ptr = pointer(arr)
1480-
if isbits(T)
1480+
if isbitstype(T)
14811481
elsz = Core.sizeof(T)
14821482
elseif isbitsunion(T)
14831483
elsz = bitsunionsize(T)
@@ -1489,7 +1489,7 @@ function vcat(arrays::Vector{T}...) where T
14891489
for a in arrays
14901490
na = length(a)
14911491
nba = na * elsz
1492-
if isbits(T)
1492+
if isbitstype(T)
14931493
ccall(:memcpy, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}, UInt),
14941494
ptr, a, nba)
14951495
elseif isbitsunion(T)

base/arraymath.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function reverse(A::Array{T}; dims::Integer) where T
9494
end
9595
end
9696
else
97-
if isbits(T) && M>200
97+
if isbitstype(T) && M>200
9898
for i = 1:sd
9999
ri = sd+1-i
100100
for j=0:stride:(N-stride)

base/compiler/optimize.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function optimize(me::InferenceState)
399399
me.src.inlineable = false
400400
elseif !me.src.inlineable && isa(def, Method)
401401
bonus = 0
402-
if me.bestguess Tuple && !isbits(widenconst(me.bestguess))
402+
if me.bestguess Tuple && !isbitstype(widenconst(me.bestguess))
403403
bonus = me.params.inline_tupleret_bonus
404404
end
405405
me.src.inlineable = isinlineable(def, me.src, me.mod, me.params, bonus)
@@ -709,7 +709,7 @@ end
709709
# since codegen optimizations of functions like `is` will depend on knowing it
710710
function widen_slot_type(@nospecialize(ty), untypedload::Bool)
711711
if isa(ty, DataType)
712-
if untypedload || isbits(ty) || isdefined(ty, :instance)
712+
if untypedload || isbitstype(ty) || isdefined(ty, :instance)
713713
return ty
714714
end
715715
elseif isa(ty, Union)
@@ -1157,6 +1157,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
11571157
f === Core.sizeof || f === isdefined ||
11581158
istopfunction(topmod, f, :typejoin) ||
11591159
istopfunction(topmod, f, :isbits) ||
1160+
istopfunction(topmod, f, :isbitstype) ||
11601161
istopfunction(topmod, f, :promote_type) ||
11611162
(f === Core.kwfunc && length(argexprs) == 2) ||
11621163
(is_inlineable_constant(val) &&
@@ -3096,7 +3097,7 @@ function structinfo_new(ctx::AllocOptContext, ex::Expr, vt::DataType)
30963097
si.defs[i] = ex.args[i + 1]
30973098
else
30983099
ft = fieldtype(vt, i)
3099-
if isbits(ft)
3100+
if isbitstype(ft)
31003101
ex = Expr(:new, ft)
31013102
ex.typ = ft
31023103
si.defs[i] = ex
@@ -3633,7 +3634,7 @@ function split_struct_alloc_single!(ctx::AllocOptContext, info, key, nf, has_pre
36333634
if !@isdefined(fld_name)
36343635
fld_name = :struct_field
36353636
end
3636-
need_preserved_root = has_preserve && !isbits(field_typ)
3637+
need_preserved_root = has_preserve && !isbitstype(field_typ)
36373638
local var_slot
36383639
if !has_def
36393640
# If there's no direct use of the field

base/compiler/ssair/inlining2.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ function early_inline_special_case(ir::IRCode, @nospecialize(f), @nospecialize(f
668668
f === Core.sizeof || f === isdefined ||
669669
istopfunction(topmod, f, :typejoin) ||
670670
istopfunction(topmod, f, :isbits) ||
671+
istopfunction(topmod, f, :isbitstype) ||
671672
istopfunction(topmod, f, :promote_type) ||
672673
(f === Core.kwfunc && length(atypes) == 2) ||
673674
(is_inlineable_constant(val) &&

base/compiler/ssair/passes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ is_tuple_call(ir, def) = isa(def, Expr) && is_known_call(def, tuple, ir, ir.mod)
189189

190190
function process_immutable_preserve(new_preserves::Vector{Any}, compact::IncrementalCompact, def::Expr)
191191
for arg in (isexpr(def, :new) ? def.args : def.args[2:end])
192-
if !isbits(compact_exprtype(compact, arg))
192+
if !isbitstype(compact_exprtype(compact, arg))
193193
push!(new_preserves, arg)
194194
end
195195
end
@@ -373,7 +373,7 @@ function getfield_elim_pass!(ir::IRCode, domtree::DomTree)
373373
for stmt in du.uses
374374
ir[SSAValue(stmt)] = compute_value_for_use(ir, domtree, allblocks, du, phinodes, fidx, stmt)
375375
end
376-
if !isbits(fieldtype(typ, fidx))
376+
if !isbitstype(fieldtype(typ, fidx))
377377
for (use, list) in preserve_uses
378378
push!(list, compute_value_for_use(ir, domtree, allblocks, du, phinodes, fidx, use))
379379
end

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function isdefined_tfunc(args...)
261261
end
262262
elseif idx <= 0 || (!isvatuple(a1) && idx > fieldcount(a1))
263263
return Const(false)
264-
elseif !isvatuple(a1) && isbits(fieldtype(a1, idx))
264+
elseif !isvatuple(a1) && isbitstype(fieldtype(a1, idx))
265265
return Const(true)
266266
elseif isa(arg1, Const) && isimmutable((arg1::Const).val)
267267
return Const(isdefined((arg1::Const).val, idx))

base/compiler/typelimits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function is_derived_type(@nospecialize(t), @nospecialize(c), mindepth::Int)
7373
for p in cP
7474
is_derived_type(t, p, mindepth) && return true
7575
end
76-
if isconcretetype(c) && isbits(c)
76+
if isconcretetype(c) && isbitstype(c)
7777
# see if it was extracted from a fieldtype
7878
# however, only look through types that can be inlined
7979
# to ensure monotonicity of derivation

base/compiler/typeutils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ end
5353
function valid_tparam(@nospecialize(x))
5454
if isa(x, Tuple)
5555
for t in x
56-
isa(t, Symbol) || isbits(typeof(t)) || return false
56+
isa(t, Symbol) || isbitstype(typeof(t)) || return false
5757
end
5858
return true
5959
end
60-
return isa(x, Symbol) || isbits(typeof(x))
60+
return isa(x, Symbol) || isbitstype(typeof(x))
6161
end
6262

6363
has_free_typevars(@nospecialize(t)) = ccall(:jl_has_free_typevars, Cint, (Any,), t) != 0

base/deepcopy.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ end
5454
function deepcopy_internal(@nospecialize(x), stackdict::IdDict)
5555
T = typeof(x)::DataType
5656
nf = nfields(x)
57-
(isbits(T) || nf == 0) && return x
57+
(isbitstype(T) || nf == 0) && return x
5858
if haskey(stackdict, x)
5959
return stackdict[x]
6060
end
@@ -79,15 +79,15 @@ function deepcopy_internal(x::Array, stackdict::IdDict)
7979
end
8080

8181
function _deepcopy_array_t(@nospecialize(x), T, stackdict::IdDict)
82-
if isbits(T)
82+
if isbitstype(T)
8383
return (stackdict[x]=copy(x))
8484
end
8585
dest = similar(x)
8686
stackdict[x] = dest
8787
for i = 1:(length(x)::Int)
8888
if ccall(:jl_array_isassigned, Cint, (Any, Csize_t), x, i-1) != 0
8989
xi = ccall(:jl_arrayref, Any, (Any, Csize_t), x, i-1)
90-
if !isbits(typeof(xi))
90+
if !isbitstype(typeof(xi))
9191
xi = deepcopy_internal(xi, stackdict)
9292
end
9393
ccall(:jl_arrayset, Cvoid, (Any, Any, Csize_t), dest, xi, i-1)
@@ -101,7 +101,7 @@ function deepcopy_internal(x::Union{Dict,IdDict}, stackdict::IdDict)
101101
return stackdict[x]::typeof(x)
102102
end
103103

104-
if isbits(eltype(x))
104+
if isbitstype(eltype(x))
105105
return (stackdict[x] = copy(x))
106106
end
107107

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,9 @@ end
16091609
# To remove this deprecation, remove the `keep` argument from the function signatures as well as
16101610
# the internal logic that deals with the renaming. These live in base/strings/util.jl.
16111611

1612+
# when this is removed, `isbitstype(typeof(x))` can be replaced with `isbits(x)`
1613+
@deprecate isbits(@nospecialize(t::Type)) isbitstype(t)
1614+
16121615
# END 0.7 deprecations
16131616

16141617
# BEGIN 1.0 deprecations

base/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ export
731731
fieldcount,
732732
# propertynames,
733733
isabstracttype,
734+
isbitstype,
734735
isprimitivetype,
735736
isstructtype,
736737
isconcretetype,

base/io.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ write(s::IO, x::Bool) = write(s, UInt8(x))
518518
write(to::IO, p::Ptr) = write(to, convert(UInt, p))
519519

520520
function write(s::IO, A::AbstractArray)
521-
if !isbits(eltype(A))
521+
if !isbitstype(eltype(A))
522522
depwarn("Calling `write` on non-isbits arrays is deprecated. Use a loop or `serialize` instead.", :write)
523523
end
524524
nb = 0
@@ -529,7 +529,7 @@ function write(s::IO, A::AbstractArray)
529529
end
530530

531531
function write(s::IO, a::Array)
532-
if isbits(eltype(a))
532+
if isbitstype(eltype(a))
533533
return GC.@preserve a unsafe_write(s, pointer(a), sizeof(a))
534534
else
535535
depwarn("Calling `write` on non-isbits arrays is deprecated. Use a loop or `serialize` instead.", :write)
@@ -542,7 +542,7 @@ function write(s::IO, a::Array)
542542
end
543543

544544
function write(s::IO, a::SubArray{T,N,<:Array}) where {T,N}
545-
if !isbits(T)
545+
if !isbitstype(T)
546546
return invoke(write, Tuple{IO, AbstractArray}, s, a)
547547
end
548548
elsz = sizeof(T)
@@ -605,7 +605,7 @@ function read!(s::IO, a::Array{UInt8})
605605
end
606606

607607
function read!(s::IO, a::Array{T}) where T
608-
if isbits(T)
608+
if isbitstype(T)
609609
GC.@preserve a unsafe_read(s, pointer(a), sizeof(a))
610610
else
611611
for i in eachindex(a)

base/iobuffer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function read_sub(from::GenericIOBuffer, a::AbstractArray{T}, offs, nel) where T
171171
if offs+nel-1 > length(a) || offs < 1 || nel < 0
172172
throw(BoundsError())
173173
end
174-
if isbits(T) && isa(a,Array)
174+
if isbitstype(T) && isa(a,Array)
175175
nb = UInt(nel * sizeof(T))
176176
GC.@preserve a unsafe_read(from, pointer(a, offs), nb)
177177
else

base/reducedim.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function _reducedim_init(f, op, fv, fop, A, region)
116116
if T !== Any && applicable(zero, T)
117117
x = f(zero(T))
118118
z = op(fv(x), fv(x))
119-
Tr = typeof(z) == typeof(x) && !isbits(T) ? T : typeof(z)
119+
Tr = typeof(z) == typeof(x) && !isbitstype(T) ? T : typeof(z)
120120
else
121121
z = fv(fop(f, A))
122122
Tr = typeof(z)

base/reflection.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ function isprimitivetype(@nospecialize(t::Type))
352352
end
353353

354354
"""
355-
isbits(T)
355+
isbitstype(T)
356356
357357
Return `true` if type `T` is a "plain data" type,
358358
meaning it is immutable and contains no references to other values,
359-
only `primitive` types and other `isbits` types.
359+
only `primitive` types and other `isbitstype` types.
360360
Typical examples are numeric types such as [`UInt8`](@ref),
361361
[`Float64`](@ref), and [`Complex{Float64}`](@ref).
362362
This category of types is significant since they are valid as type parameters,
@@ -365,14 +365,20 @@ and have a defined layout that is compatible with C.
365365
366366
# Examples
367367
```jldoctest
368-
julia> isbits(Complex{Float64})
368+
julia> isbitstype(Complex{Float64})
369369
true
370370
371-
julia> isbits(Complex)
371+
julia> isbitstype(Complex)
372372
false
373373
```
374374
"""
375-
isbits(@nospecialize(t::Type)) = (@_pure_meta; isa(t, DataType) && t.isbitstype)
375+
isbitstype(@nospecialize(t::Type)) = (@_pure_meta; isa(t, DataType) && t.isbitstype)
376+
377+
"""
378+
isbits(x)
379+
380+
Return `true` if `x` is an instance of an `isbitstype` type.
381+
"""
376382
isbits(@nospecialize x) = (@_pure_meta; typeof(x).isbitstype)
377383

378384
"""

base/refpointer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ if is_primary_base_module
8383
return RefArray(a) # effectively a no-op
8484
end
8585
function Ref{P}(a::Array{T}) where P<:Union{Ptr,Cwstring,Cstring} where T
86-
if (!isbits(T) && T <: eltype(P))
86+
if (!isbitstype(T) && T <: eltype(P))
8787
# this Array already has the right memory layout for the requested Ref
8888
return RefArray(a,1,false) # root something, so that this function is type-stable
8989
else

base/reinterpretarray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct ReinterpretArray{T,N,S,A<:AbstractArray{S, N}} <: AbstractArray{T, N}
2424
The resulting array would have non-integral first dimension.
2525
"""))
2626
end
27-
isbits(T) || throwbits(S, T, T)
28-
isbits(S) || throwbits(S, T, S)
27+
isbitstype(T) || throwbits(S, T, T)
28+
isbitstype(S) || throwbits(S, T, S)
2929
(N != 0 || sizeof(T) == sizeof(S)) || throwsize0(S, T)
3030
if N != 0 && sizeof(S) != sizeof(T)
3131
dim = size(a)[1]

base/summarysize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function summarysize(obj;
4545
else
4646
nf = _nfields(x)
4747
ft = typeof(x).types
48-
if !isbits(ft[i]) && isdefined(x, i)
48+
if !isbitstype(ft[i]) && isdefined(x, i)
4949
val = getfield(x, i)
5050
end
5151
end
@@ -108,7 +108,7 @@ function (ss::SummarySize)(obj::Array)
108108
if !haskey(ss.seen, datakey)
109109
ss.seen[datakey] = true
110110
size += Core.sizeof(obj)
111-
if !isbits(eltype(obj)) && !isempty(obj)
111+
if !isbitstype(eltype(obj)) && !isempty(obj)
112112
push!(ss.frontier_x, obj)
113113
push!(ss.frontier_i, 1)
114114
end

base/threadcall.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function do_threadcall(fun_ptr::Ptr{Cvoid}, rettype::Type, argtypes::Vector, arg
6868
args_arr = Vector{UInt8}(undef, args_size)
6969
ptr = pointer(args_arr)
7070
for (T, x) in zip(argtypes, argvals)
71-
isbits(T) || throw(ArgumentError("threadcall requires isbits argument types"))
71+
isbitstype(T) || throw(ArgumentError("threadcall requires isbits argument types"))
7272
y = cconvert(T, x)
7373
push!(roots, y)
7474
unsafe_store!(convert(Ptr{T}, ptr), unsafe_convert(T, y)::T)

doc/src/base/base.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Base.fieldname
146146
Base.sizeof(::Type)
147147
Base.isconcretetype
148148
Base.isbits
149+
Base.isbitstype
149150
Core.fieldtype
150151
Base.fieldcount
151152
Base.fieldoffset

stdlib/Distributed/src/clusterserialize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function syms_2b_sent(s::ClusterSerializer, identifier)
126126
for sym in check_syms
127127
v = getfield(Main, sym)
128128

129-
if isbits(v)
129+
if isbitstype(typeof(v))
130130
push!(lst, sym)
131131
else
132132
oid = objectid(v)
@@ -146,7 +146,7 @@ function serialize_global_from_main(s::ClusterSerializer, sym)
146146

147147
oid = objectid(v)
148148
record_v = true
149-
if isbits(v)
149+
if isbitstype(typeof(v))
150150
record_v = false
151151
elseif !haskey(s.glbs_sent, oid)
152152
# set up a finalizer the first time this object is sent

0 commit comments

Comments
 (0)