Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,6 @@ end

asize_from(a::Array, n) = n > ndims(a) ? () : (size(a,n), asize_from(a, n+1)...)

allocatedinline(@nospecialize T::Type) = (@_total_meta; ccall(:jl_stored_inline, Cint, (Any,), T) != Cint(0))

"""
Base.isbitsunion(::Type{T})

Return whether a type is an "is-bits" Union type, meaning each type included in a Union is [`isbitstype`](@ref).

# Examples
```jldoctest
julia> Base.isbitsunion(Union{Float64, UInt8})
true

julia> Base.isbitsunion(Union{Float64, String})
false
```
"""
isbitsunion(u::Type) = u isa Union && allocatedinline(u)

function _unsetindex!(A::Array, i::Int)
@inline
@boundscheck checkbounds(A, i)
Expand Down
62 changes: 62 additions & 0 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,65 @@ function replaceindex_atomic!(
@_boundscheck,
)
end

"""
allocatedinline(::Type{T}) :: Bool

Returns whether an object of type `T` is able to be inline allocated inside of enclosing structs or arrays,
of if it must be allocated as a reference. Generally, types which are immutable and whose instances have a
finite, statically determinable size can be allocated inline, whereas everything else is allocated using
reference pointers.

# Examples
```jldoctest
julia> Base.allocatedinline(Int)
true

julia> Base.allocatedinline(Union{Int, Float64})
true

julia> Base.allocatedinline(Complex)
false

julia> Base.allocatedinline(Complex{Int})
true
```

Whether or not a type is `allocatedinline` determines whether or not objects of that type can be undefined
in arrays or as fields of enclosing types, or if it will be replaced with garbage bits read from memory.
```
julia> Vector{Int}(undef, 1)
1-element Vector{Int64}:
8

julia> Vector{Union{Int, Float64}}(undef, 1)
1-element Vector{Union{Float64, Int64}}:
0.0

julia> Vector{Complex}(undef, 1)
1-element Vector{Complex}:
#undef

julia> Vector{Complex{Int}}(undef, 1)
1-element Vector{Complex{Int64}}:
139934851180016 + 7957332965790215680im
```
See also [`isdefined`](@ref), [`isassigned`](@ref)
"""
allocatedinline(@nospecialize T::Type) = (@_total_meta; ccall(:jl_stored_inline, Cint, (Any,), T) != Cint(0))

"""
Base.isbitsunion(::Type{T})

Return whether a type is an "is-bits" Union type, meaning each type included in a Union is [`isbitstype`](@ref).

# Examples
```jldoctest
julia> Base.isbitsunion(Union{Float64, UInt8})
true

julia> Base.isbitsunion(Union{Float64, String})
false
```
"""
isbitsunion(u::Type) = u isa Union && allocatedinline(u)
1 change: 1 addition & 0 deletions base/public.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public
isexported,
ispublic,
remove_linenums!,
allocatedinline,

# AST handling
IR,
Expand Down