Skip to content

Commit

Permalink
implement Memory{T} as a new backend for Array{T}
Browse files Browse the repository at this point in the history
TODO: add more tests for Memory specifically
TODO: add to julia-licm the gc_loaded
TODO: make sure all tests are passing (updated as needed)
TODO: write API documentation for Memory (as needed) and devdoc updates (as needed)
TODO: test Memory owner relationship (avoid implied unalias copy) of Memory in staticdata
TODO: can we detect ownership for dataids for more accurate range checking?
TODO: add memoryowner intrinsic (since this is a hidden field)
TODO: add memoryoffset intrinsic (since this is computed better with exact idiv)
TODO: implement dataids for Memory aliasing check and fix dataids for Array

also makes memory allocation ccalls safer, for catching Serialization
and deepcopy bugs in packages.

more things to do

TODO: don't mutate Memory length when making a String, but set Array ref field to empty Memory
TODO: add alias `AtomicMemory{T} = GenericMemory{:atomic,T}`
TODO: document jl_memoryt_slice
TODO: add AddrSpace::Int parameter to GenericMemory

Future possible kinds of possible Memories:
GenericMemory{:atomic, 0, Int}
GenericMemory{:not_atomic, 0, Int}
GenericMemory{:unsync, 0, Int}
GenericMemory{:normal, 0, Int}
GenericMemory{:default, 0, Int}
GenericMemory{:racy, 0, Int}
GenericMemory{:local, 0, Int}
GenericMemory{:const, 0, Int}
GenericMemory{:ntuple, 0, Int}
GenericMemory{:value, 0, Int}

cleanups

finish sizehint! implimentation and cleanups

cleanup

remove arrayref and arrayset from julia side (still need to remove the C side), and impliment  in julia

remove arrayref, arrayset, arraysize, arraylen from backend

cleanups

fix

fix

fixes

fixes

fixes

fixes
  • Loading branch information
vtjnash authored and oscardssmith committed Sep 18, 2023
1 parent 28d0e1e commit 72f67ce
Show file tree
Hide file tree
Showing 106 changed files with 4,593 additions and 4,018 deletions.
16 changes: 13 additions & 3 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ using Core.Intrinsics, Core.IR

# to start, we're going to use a very simple definition of `include`
# that doesn't require any function (except what we can get from the `Core` top-module)
const _included_files = Array{Tuple{Module,String},1}(Core.undef, 1)
# start this big so that we don't have to resize before we have defined how to grow an array
const _included_files = Array{Tuple{Module,String},1}(Core.undef, 50)
_included_files.size = (1,)
function include(mod::Module, path::String)
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), _included_files, UInt(1))
Core.arrayset(true, _included_files, (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)), arraylen(_included_files))
len = getfield(_included_files.size, 1)
memlen = _included_files.ref.mem.length
lenp1 = Core.add_int(len, 1)
if len === memlen # by the time this is true we hopefully will have defined _growend!
_growend!(_included_files, UInt(1))
else
_included_files.size = (lenp1,)
end
Core.memoryrefset(Core.memoryref(_included_files.ref, lenp1), (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)), :not_atomic, true)
Core.println(path)
ccall(:jl_uv_flush, Nothing, (Ptr{Nothing},), Core.io_pointer(Core.stdout))
Core.include(mod, path)
Expand Down Expand Up @@ -186,6 +195,7 @@ include("strings/lazy.jl")

# array structures
include("indices.jl")
include("genericmemory.jl")
include("array.jl")
include("abstractarray.jl")
include("subarray.jl")
Expand Down
5 changes: 2 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,6 @@ function getindex(A::AbstractArray, I...)
error_if_canonical_getindex(IndexStyle(A), A, I...)
_getindex(IndexStyle(A), A, to_indices(A, I)...)
end
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
@propagate_inbounds getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]

@inline unsafe_getindex(A::AbstractArray, I...) = @inbounds getindex(A, I...)

Expand Down Expand Up @@ -1531,7 +1529,8 @@ their component parts. A typical definition for an array that wraps a parent is
`Base.dataids(C::CustomArray) = dataids(C.parent)`.
"""
dataids(A::AbstractArray) = (UInt(objectid(A)),)
dataids(A::Array) = (UInt(pointer(A)),)
dataids(A::Memory) = (UInt(pointer(A)),)
dataids(A::Array) = dataids(A.ref.mem)
dataids(::AbstractRange) = ()
dataids(x) = ()

Expand Down
Loading

0 comments on commit 72f67ce

Please sign in to comment.