Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More thorough aliasing detection in nonscalar copy, broadcast and assignment #25890

Merged
merged 17 commits into from
Feb 27, 2018

Commits on Feb 14, 2018

  1. More thorough aliasing detection in nonscalar copy, broadcast and ass…

    …ignment.
    
    This commit puts together the beginnings of an "interface" for detecting and avoiding aliasing between arrays before performing some mutating operation on one of them.
    
    `A′ = unalias(dest, A)` is the main entry point; it checks to see if `dest` and `A` might alias one another, and then either returns `A` or a copy of `A`. When it returns a copy of `A`, it absolutely must preserve the same type. As such, this function is designed to be specialized on `A`, typically like:
    
        Base.unalias(dest, A::T) = mightalias(dest, A) ? typeof(A)(unalias(dest, A.a), unalias(dest, A.b), ...) : A
    
    `mightalias(A, B)` is a quick and rough check to see if two arrays alias eachother.  Instead of requiring every array to know about every other array type, it simply asks both arrays for their `dataids` and then looks for an empty intersection between every pair.
    
    Finally, `dataids(A)` returns a tuple of ranges that describe something about the region of memory the array occupies. It could be simply `(objectid(A):objectid(A),)` or for an array with multiple fields, `(dataids(A.a)..., dataids(A.b)..., ...)`.
    mbauman committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    f24bc59 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1e8ac8f View commit details
    Browse the repository at this point in the history
  3. Fixup docstrings from review

    mbauman committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    901514b View commit details
    Browse the repository at this point in the history
  4. Add support for dealiasing Adjoint and Transpose

    And fixup the assumption that `broadcast!(f, C, A)` is safe
    mbauman committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    534bf91 View commit details
    Browse the repository at this point in the history
  5. Refactor API to use map(x->unalias(dest, x), xs) instead of...

    a builtin mapper method. Using varargs would require de-structuring the one arg case: `(a,) = unalias(dest, a)`.
    mbauman committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    0fde137 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    fa809cb View commit details
    Browse the repository at this point in the history
  7. Add support for BitArray

    mbauman committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    eeebbe7 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    2254dc5 View commit details
    Browse the repository at this point in the history
  9. Add default StridedArray dataids definition and constrain StridedSubA…

    …rray...
    
    to only look at the linear data segment of its parent that it can reach
    mbauman committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    d97d0c3 View commit details
    Browse the repository at this point in the history

Commits on Feb 15, 2018

  1. More refined aliasing detection for views into the same parent

    And a more accurate StridedArray dataids definition.
    mbauman committed Feb 15, 2018
    Configuration menu
    Copy the full SHA
    5410652 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c451ecc View commit details
    Browse the repository at this point in the history

Commits on Feb 20, 2018

  1. Major simplification: do not worry about array extents

    By defining `mightalias(::SubArray, ::SubArray)` we cover the vast majority of cases where extents are important. SubArrays are the basically only array in the standard library that "restrict" views into parents; all other wrappers largely re-shuffle the data. `dataids(::AbstractArray)` now just returns a tuple of `UInt`s that describe the identities of the mutable "blocks" that the array references.  By default, this is just `(objectid(A),)`, allowing all custom arrays to detect situations with two `===` arrays.  Anything more complicated requires them to define their component parts with a custom `dataids` method definition.
    mbauman committed Feb 20, 2018
    Configuration menu
    Copy the full SHA
    dd1588e View commit details
    Browse the repository at this point in the history

Commits on Feb 21, 2018

  1. Configuration menu
    Copy the full SHA
    e16c03e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2ba5688 View commit details
    Browse the repository at this point in the history

Commits on Feb 22, 2018

  1. Use copy with a method type assertion instead of deepcopy

    This will do what we want in almost all cases. We only hit this method if `A` is aliasing a mutable array... which means that `A` is mutable as well, and thus in many cases it has defined an appropriate `similar(A)` method that returns the same type.
    mbauman committed Feb 22, 2018
    Configuration menu
    Copy the full SHA
    636453d View commit details
    Browse the repository at this point in the history

Commits on Feb 23, 2018

  1. Configuration menu
    Copy the full SHA
    5caac48 View commit details
    Browse the repository at this point in the history

Commits on Feb 26, 2018

  1. Configuration menu
    Copy the full SHA
    1ffc135 View commit details
    Browse the repository at this point in the history