@@ -60,7 +60,10 @@ Base.elsize(::Type{<:MemoryView{T}}) where {T} = Base.elsize(Memory{T})
6060Base. sizeof (x:: MemoryView ) = Base. elsize (typeof (x)) * length (x)
6161Base. strides (:: MemoryView ) = (1 ,)
6262
63- function Base. mightalias (a:: MemoryView , b:: MemoryView )
63+ # For two distinct element types, they can't alias
64+ Base. mightalias (:: MemoryView , :: MemoryView ) = false
65+
66+ function Base. mightalias (a:: MemoryView{T} , b:: MemoryView{T} ) where {T}
6467 (isempty (a) | isempty (b)) && return false
6568 parent (a) === parent (b) || return false
6669 (p1, p2) = (pointer (a), pointer (b))
@@ -72,6 +75,19 @@ function Base.mightalias(a::MemoryView, b::MemoryView)
7275 end
7376end
7477
78+ # We don't include strings here because this union is used for mightalias
79+ # checks, which are done implicitly, and we don't want to construct memory
80+ # views from strings implicitly, since that currently allocates.
81+ const KNOWN_MEM_BACKED = Union{Array, Memory, ContiguousSubArray}
82+
83+ function Base. mightalias (a:: MemoryView , b:: KNOWN_MEM_BACKED )
84+ Base. mightalias (a, ImmutableMemoryView (b))
85+ end
86+
87+ function Base. mightalias (a:: KNOWN_MEM_BACKED , b:: MemoryView )
88+ Base. mightalias (ImmutableMemoryView (a), b)
89+ end
90+
7591function Base. getindex (v:: MemoryView , idx:: AbstractUnitRange )
7692 # This branch is necessary, because the memoryref can't point out of bounds.
7793 # So if the user gives an empty slice that is out of bounds, the boundscheck
0 commit comments