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

ImmutableArrays #42465

Closed
wants to merge 58 commits into from
Closed

ImmutableArrays #42465

wants to merge 58 commits into from

Commits on Aug 4, 2021

  1. Implement ImmutableArray

    This rebases JuliaLang#31630 with several fixed and modifications.
    After JuliaLang#31630, we had originally decided to hold off on said
    PR in favor of implementing either more efficient layouts for
    tuples or some sort of variable-sized struct type. However, in
    the two years since, neither of those have happened (I had a go
    at improving tuples and made some progress, but there is much
    still to be done there). In the meantime, all across the package
    ecosystem, we've seen an increasing creep of pre-allocation and
    mutating operations, primarily caused by our lack of sufficiently
    powerful immutable array abstractions and array optimizations.
    
    This works fine for the individual packages in question, but it
    causes a fair bit of trouble when trying to compose these packages
    with transformation passes such as AD or domain specific optimizations,
    since many of those passes do not play well with mutation. More
    generally, we would like to avoid people needing to pierce
    abstractions for performance reasons.
    
    Given these developments, I think it's getting quite important
    that we start to seriously look at arrays and try to provide
    performant and well-optimized arrays in the language. More
    importantly, I think this is somewhat independent from the
    actual implementation details. To be sure, it would be nice
    to move more of the array implementation into Julia by making
    use of one of the abovementioned langugage features, but that
    is a bit of an orthogonal concern and not absolutely required.
    
    This PR provides an `ImmutableArray` type that is identical
    in functionality and implementation to `Array`, except that
    it is immutable. Two new intrinsics `Core.arrayfreeze` and
    `Core.arraythaw` are provided which are semantically copies
    and turn a mutable array into an immutable array and vice
    versa.
    
    In the original PR, I additionally provided generic functions
    `freeze` and `thaw` that would simply forward to these
    intrinsics. However, said generic functions have been omitted
    from this PR in favor of simply using constructors to go
    between mutable and immutable arrays at the high level.
    Generic `freeze`/`thaw` functions can always be added later,
    once we have a more complete picture of how these functions
    would work on non-Array datatypes.
    
    Some basic compiler support is provided to elide these copies
    when the compiler can prove that the original object is
    dead after the copy. For instance, in the following example:
    ```
    function simple()
        a = Vector{Float64}(undef, 5)
        for i = 1:5
            a[i] = i
        end
        ImmutableArray(a)
    end
    ```
    
    the compiler will recognize that the array `a` is dead after
    its use in `ImmutableArray` and the optimized implementation
    will simply rewrite the type tag in the originally allocated
    array to now mark it as immutable. It should be pointed out
    however, that *semantically* there is still no mutation of the
    original array, this is simply an optimization.
    
    At the moment this compiler transform is rather limited, since
    the analysis requires escape information in order to compute
    whether or not the copy may be elided. However, more complete
    escape analysis is being worked on at the moment, so hopefully
    this analysis should become more powerful in the very near future.
    
    I would like to get this cleaned up and merged resonably quickly,
    and then crowdsource some improvements to the Array APIs more
    generally. There are still a number of APIs that are quite bound
    to the notion of mutable `Array`s. StaticArrays and other packages
    have been inventing conventions for how to generalize those, but
    we should form a view in Base what those APIs should look like and
    harmonize them. Having the `ImmutableArray` in Base should help
    with that.
    Keno committed Aug 4, 2021
    Configuration menu
    Copy the full SHA
    fcbafaa View commit details
    Browse the repository at this point in the history

Commits on Oct 29, 2021

  1. Implement maybecopy in BoundsError, start optimization, refactor memo…

    …ry_opt!
    Ian Atol authored and Ian Atol committed Oct 29, 2021
    Configuration menu
    Copy the full SHA
    233bb0c View commit details
    Browse the repository at this point in the history

Commits on Nov 9, 2021

  1. Begin EscapeAnalysis.jl port

    Ian Atol committed Nov 9, 2021
    Configuration menu
    Copy the full SHA
    424232a View commit details
    Browse the repository at this point in the history

Commits on Dec 21, 2021

  1. Update memory_opt! for usage with EscapeState, begin port of EA.jl in…

    …to Core
    Ian Atol committed Dec 21, 2021
    Configuration menu
    Copy the full SHA
    e031da8 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c2ca5c5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    49f9337 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b02e7c0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    2a52e3d View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    bd0bdb7 View commit details
    Browse the repository at this point in the history

Commits on Dec 23, 2021

  1. Configuration menu
    Copy the full SHA
    51120cf View commit details
    Browse the repository at this point in the history
  2. add simple all/any definitions to make ::BitSet ⊆ ::BitSet work…

    … inside `Core.Compiler`
    aviatesk committed Dec 23, 2021
    Configuration menu
    Copy the full SHA
    4b33fc7 View commit details
    Browse the repository at this point in the history
  3. comment dead code for now

    aviatesk committed Dec 23, 2021
    Configuration menu
    Copy the full SHA
    cb4b1b8 View commit details
    Browse the repository at this point in the history

Commits on Dec 25, 2021

  1. Configuration menu
    Copy the full SHA
    f59d58b View commit details
    Browse the repository at this point in the history
  2. update to latest EA

    aviatesk committed Dec 25, 2021
    Configuration menu
    Copy the full SHA
    bca3078 View commit details
    Browse the repository at this point in the history

Commits on Dec 26, 2021

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

Commits on Dec 28, 2021

  1. Restrict arrayfreeze/thaw arg # in base/compiler/tfuncs.jl

    Co-authored-by: Shuhei Kadowaki <[email protected]>
    ianatol and aviatesk authored Dec 28, 2021
    Configuration menu
    Copy the full SHA
    235ab84 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0e5833b View commit details
    Browse the repository at this point in the history

Commits on Jan 4, 2022

  1. Configuration menu
    Copy the full SHA
    4a57838 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    de437d4 View commit details
    Browse the repository at this point in the history
  3. fixup memory_opt!

    aviatesk committed Jan 4, 2022
    Configuration menu
    Copy the full SHA
    a34166c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1b1babf View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    eee43bd View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    9b8233a View commit details
    Browse the repository at this point in the history

Commits on Jan 8, 2022

  1. Correct maybecopy and begin implementing its optimization. Also some …

    …test cleanup
    Ian Atol committed Jan 8, 2022
    Configuration menu
    Copy the full SHA
    6fad97d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e1a1dc5 View commit details
    Browse the repository at this point in the history
  3. update to latest EA

    aviatesk committed Jan 8, 2022
    Configuration menu
    Copy the full SHA
    dd77189 View commit details
    Browse the repository at this point in the history
  4. fixup memory_opt!

    aviatesk committed Jan 8, 2022
    Configuration menu
    Copy the full SHA
    39c925b View commit details
    Browse the repository at this point in the history

Commits on Jan 9, 2022

  1. Configuration menu
    Copy the full SHA
    fbc2c20 View commit details
    Browse the repository at this point in the history
  2. simplify memory_opt!

    aviatesk committed Jan 9, 2022
    Configuration menu
    Copy the full SHA
    5d93701 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    19d5d20 View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2022

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

    aviatesk committed Jan 10, 2022
    Configuration menu
    Copy the full SHA
    697b6f1 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0403a04 View commit details
    Browse the repository at this point in the history
  4. improve test implementations

    aviatesk committed Jan 10, 2022
    Configuration menu
    Copy the full SHA
    8507643 View commit details
    Browse the repository at this point in the history
  5. Fixup unescaped1_1 test

    Ian Atol committed Jan 10, 2022
    Configuration menu
    Copy the full SHA
    77eec88 View commit details
    Browse the repository at this point in the history

Commits on Jan 11, 2022

  1. Cleanup memory_opt, add some tests

    Ian Atol committed Jan 11, 2022
    Configuration menu
    Copy the full SHA
    c958ac9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c718fb9 View commit details
    Browse the repository at this point in the history

Commits on Jan 12, 2022

  1. Add some basic tests and move non-compiler tests

    Ian Atol committed Jan 12, 2022
    Configuration menu
    Copy the full SHA
    c4c7acf View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2438fd4 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0d7d81a View commit details
    Browse the repository at this point in the history

Commits on Jan 13, 2022

  1. Configuration menu
    Copy the full SHA
    765f59c View commit details
    Browse the repository at this point in the history
  2. update EA

    aviatesk committed Jan 13, 2022
    Configuration menu
    Copy the full SHA
    150c490 View commit details
    Browse the repository at this point in the history
  3. no broken tests now

    aviatesk committed Jan 13, 2022
    Configuration menu
    Copy the full SHA
    eaf5005 View commit details
    Browse the repository at this point in the history

Commits on Jan 14, 2022

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

Commits on Jan 15, 2022

  1. Configuration menu
    Copy the full SHA
    eb519c8 View commit details
    Browse the repository at this point in the history
  2. update EA

    aviatesk committed Jan 15, 2022
    Configuration menu
    Copy the full SHA
    8110fad View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    7b3c099 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    d494cf2 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    de410f1 View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2022

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

Commits on Jan 18, 2022

  1. fix tests

    aviatesk committed Jan 18, 2022
    Configuration menu
    Copy the full SHA
    283c36b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    eb221f6 View commit details
    Browse the repository at this point in the history

Commits on Jan 19, 2022

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

Commits on Jan 20, 2022

  1. update EA

    aviatesk committed Jan 20, 2022
    Configuration menu
    Copy the full SHA
    2560b73 View commit details
    Browse the repository at this point in the history

Commits on Jan 21, 2022

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

Commits on Jan 25, 2022

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

Commits on Jan 27, 2022

  1. Remove maybecopy code

    Ian Atol committed Jan 27, 2022
    Configuration menu
    Copy the full SHA
    bca548f View commit details
    Browse the repository at this point in the history

Commits on Jan 28, 2022

  1. Add tests

    Ian Atol committed Jan 28, 2022
    Configuration menu
    Copy the full SHA
    df8bccc View commit details
    Browse the repository at this point in the history