-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
ImmutableArrays #42465
Commits on Aug 4, 2021
-
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.
Configuration menu - View commit details
-
Copy full SHA for fcbafaa - Browse repository at this point
Copy the full SHA fcbafaaView commit details
Commits on Oct 29, 2021
-
Implement maybecopy in BoundsError, start optimization, refactor memo…
…ry_opt!
Ian Atol authored and Ian Atol committedOct 29, 2021 Configuration menu - View commit details
-
Copy full SHA for 233bb0c - Browse repository at this point
Copy the full SHA 233bb0cView commit details
Commits on Nov 9, 2021
-
Ian Atol committed
Nov 9, 2021 Configuration menu - View commit details
-
Copy full SHA for 424232a - Browse repository at this point
Copy the full SHA 424232aView commit details
Commits on Dec 21, 2021
-
Update memory_opt! for usage with EscapeState, begin port of EA.jl in…
…to Core
Ian Atol committedDec 21, 2021 Configuration menu - View commit details
-
Copy full SHA for e031da8 - Browse repository at this point
Copy the full SHA e031da8View commit details -
Configuration menu - View commit details
-
Copy full SHA for c2ca5c5 - Browse repository at this point
Copy the full SHA c2ca5c5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 49f9337 - Browse repository at this point
Copy the full SHA 49f9337View commit details -
Configuration menu - View commit details
-
Copy full SHA for b02e7c0 - Browse repository at this point
Copy the full SHA b02e7c0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2a52e3d - Browse repository at this point
Copy the full SHA 2a52e3dView commit details -
Configuration menu - View commit details
-
Copy full SHA for bd0bdb7 - Browse repository at this point
Copy the full SHA bd0bdb7View commit details
Commits on Dec 23, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 51120cf - Browse repository at this point
Copy the full SHA 51120cfView commit details -
add simple
all
/any
definitions to make::BitSet ⊆ ::BitSet
work…… inside `Core.Compiler`
Configuration menu - View commit details
-
Copy full SHA for 4b33fc7 - Browse repository at this point
Copy the full SHA 4b33fc7View commit details -
Configuration menu - View commit details
-
Copy full SHA for cb4b1b8 - Browse repository at this point
Copy the full SHA cb4b1b8View commit details
Commits on Dec 25, 2021
-
Configuration menu - View commit details
-
Copy full SHA for f59d58b - Browse repository at this point
Copy the full SHA f59d58bView commit details -
Configuration menu - View commit details
-
Copy full SHA for bca3078 - Browse repository at this point
Copy the full SHA bca3078View commit details
Commits on Dec 26, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 2c466e1 - Browse repository at this point
Copy the full SHA 2c466e1View commit details
Commits on Dec 28, 2021
-
Restrict arrayfreeze/thaw arg # in base/compiler/tfuncs.jl
Co-authored-by: Shuhei Kadowaki <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 235ab84 - Browse repository at this point
Copy the full SHA 235ab84View commit details -
Restrict nargs of arrayfreeze/thaw to 1 in builtins.c
Ian Atol committedDec 28, 2021 Configuration menu - View commit details
-
Copy full SHA for 0e5833b - Browse repository at this point
Copy the full SHA 0e5833bView commit details
Commits on Jan 4, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 4a57838 - Browse repository at this point
Copy the full SHA 4a57838View commit details -
Configuration menu - View commit details
-
Copy full SHA for de437d4 - Browse repository at this point
Copy the full SHA de437d4View commit details -
Configuration menu - View commit details
-
Copy full SHA for a34166c - Browse repository at this point
Copy the full SHA a34166cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1b1babf - Browse repository at this point
Copy the full SHA 1b1babfView commit details -
Configuration menu - View commit details
-
Copy full SHA for eee43bd - Browse repository at this point
Copy the full SHA eee43bdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9b8233a - Browse repository at this point
Copy the full SHA 9b8233aView commit details
Commits on Jan 8, 2022
-
Correct maybecopy and begin implementing its optimization. Also some …
…test cleanup
Ian Atol committedJan 8, 2022 Configuration menu - View commit details
-
Copy full SHA for 6fad97d - Browse repository at this point
Copy the full SHA 6fad97dView commit details -
Configuration menu - View commit details
-
Copy full SHA for e1a1dc5 - Browse repository at this point
Copy the full SHA e1a1dc5View commit details -
Configuration menu - View commit details
-
Copy full SHA for dd77189 - Browse repository at this point
Copy the full SHA dd77189View commit details -
Configuration menu - View commit details
-
Copy full SHA for 39c925b - Browse repository at this point
Copy the full SHA 39c925bView commit details
Commits on Jan 9, 2022
-
Configuration menu - View commit details
-
Copy full SHA for fbc2c20 - Browse repository at this point
Copy the full SHA fbc2c20View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5d93701 - Browse repository at this point
Copy the full SHA 5d93701View commit details -
Configuration menu - View commit details
-
Copy full SHA for 19d5d20 - Browse repository at this point
Copy the full SHA 19d5d20View commit details
Commits on Jan 10, 2022
-
Configuration menu - View commit details
-
Copy full SHA for b16190e - Browse repository at this point
Copy the full SHA b16190eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 697b6f1 - Browse repository at this point
Copy the full SHA 697b6f1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0403a04 - Browse repository at this point
Copy the full SHA 0403a04View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8507643 - Browse repository at this point
Copy the full SHA 8507643View commit details -
Ian Atol committed
Jan 10, 2022 Configuration menu - View commit details
-
Copy full SHA for 77eec88 - Browse repository at this point
Copy the full SHA 77eec88View commit details
Commits on Jan 11, 2022
-
Cleanup memory_opt, add some tests
Ian Atol committedJan 11, 2022 Configuration menu - View commit details
-
Copy full SHA for c958ac9 - Browse repository at this point
Copy the full SHA c958ac9View commit details -
Configuration menu - View commit details
-
Copy full SHA for c718fb9 - Browse repository at this point
Copy the full SHA c718fb9View commit details
Commits on Jan 12, 2022
-
Add some basic tests and move non-compiler tests
Ian Atol committedJan 12, 2022 Configuration menu - View commit details
-
Copy full SHA for c4c7acf - Browse repository at this point
Copy the full SHA c4c7acfView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2438fd4 - Browse repository at this point
Copy the full SHA 2438fd4View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0d7d81a - Browse repository at this point
Copy the full SHA 0d7d81aView commit details
Commits on Jan 13, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 765f59c - Browse repository at this point
Copy the full SHA 765f59cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 150c490 - Browse repository at this point
Copy the full SHA 150c490View commit details -
Configuration menu - View commit details
-
Copy full SHA for eaf5005 - Browse repository at this point
Copy the full SHA eaf5005View commit details
Commits on Jan 14, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 1dcfa1b - Browse repository at this point
Copy the full SHA 1dcfa1bView commit details
Commits on Jan 15, 2022
-
Configuration menu - View commit details
-
Copy full SHA for eb519c8 - Browse repository at this point
Copy the full SHA eb519c8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8110fad - Browse repository at this point
Copy the full SHA 8110fadView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7b3c099 - Browse repository at this point
Copy the full SHA 7b3c099View commit details -
Configuration menu - View commit details
-
Copy full SHA for d494cf2 - Browse repository at this point
Copy the full SHA d494cf2View commit details -
Configuration menu - View commit details
-
Copy full SHA for de410f1 - Browse repository at this point
Copy the full SHA de410f1View commit details
Commits on Jan 17, 2022
-
Configuration menu - View commit details
-
Copy full SHA for d3c21bd - Browse repository at this point
Copy the full SHA d3c21bdView commit details
Commits on Jan 18, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 283c36b - Browse repository at this point
Copy the full SHA 283c36bView commit details -
Configuration menu - View commit details
-
Copy full SHA for eb221f6 - Browse repository at this point
Copy the full SHA eb221f6View commit details
Commits on Jan 19, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 10c161f - Browse repository at this point
Copy the full SHA 10c161fView commit details
Commits on Jan 20, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 2560b73 - Browse repository at this point
Copy the full SHA 2560b73View commit details
Commits on Jan 21, 2022
-
Configuration menu - View commit details
-
Copy full SHA for fe3717a - Browse repository at this point
Copy the full SHA fe3717aView commit details
Commits on Jan 25, 2022
-
Configuration menu - View commit details
-
Copy full SHA for bbe8b3d - Browse repository at this point
Copy the full SHA bbe8b3dView commit details
Commits on Jan 27, 2022
-
Ian Atol committed
Jan 27, 2022 Configuration menu - View commit details
-
Copy full SHA for bca548f - Browse repository at this point
Copy the full SHA bca548fView commit details
Commits on Jan 28, 2022
-
Ian Atol committed
Jan 28, 2022 Configuration menu - View commit details
-
Copy full SHA for df8bccc - Browse repository at this point
Copy the full SHA df8bcccView commit details