@@ -24,7 +24,7 @@ function explain_eltype(@nospecialize(T), depth=0; maxdepth=10)
2424 msg *= explain_eltype (U, depth+ 1 )
2525 end
2626 end
27- elseif Base. ismutabletype (T)
27+ elseif Base. ismutabletype (T) && Base . datatype_fieldcount (T) != 0
2828 msg = " " ^ depth * " $T is a mutable type\n "
2929 elseif hasfieldcount (T)
3030 msg = " " ^ depth * " $T is a struct that's not allocated inline\n "
4747# these are stored with a selector at the end (handled by Julia).
4848# 3. bitstype unions (`Union{Int, Float32}`, etc)
4949# these are stored contiguously and require a selector array (handled by us)
50+ # As well as "mutable singleton" types like `Symbol` that use pointer-identity
5051@inline function check_eltype (name, T)
51- eltype_is_invalid = ! Base. allocatedinline (T) || (hasfieldcount (T) && any (! Base. allocatedinline, fieldtypes (T)))
52+ eltype_is_invalid = ! Base. allocatedinline (T) ||
53+ (hasfieldcount (T) && any (! Base. allocatedinline, fieldtypes (T)))
54+
5255 if eltype_is_invalid
5356 explanation = explain_eltype (T)
5457 error ("""
234237function Base. unsafe_wrap (:: Type{CuArray{T,N,M}} ,
235238 ptr:: CuPtr{T} , dims:: NTuple{N,Int} ;
236239 own:: Bool = false , ctx:: CuContext = context ()) where {T,N,M}
237- isbitstype (T) || throw ( ArgumentError ( " Can only unsafe_wrap a pointer to a bits type " ) )
240+ check_eltype ( " unsafe_wrap(CuArray, ...) " , T )
238241 sz = prod (dims) * aligned_sizeof (T)
239242
240243 # create a memory object
0 commit comments