-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: Change lowering of destructuring to avoid const prop dependence
I'm currently doing some work with inference passes that have const prop (temporarily) disabled and I noticed we actually rely on it quite a bit for basic things. That's not terrible - const prop works pretty well after all, but it still imposes a cost and while I want to support it in my AD use case also, it makes destructuring quite expensive, because everything needs to be inferred twice. This PR is an experiment in changing the lowering to avoid having to const prop the index. Rather than lowering `(a,b,c) = foo()` as: ``` it = foo() a, s = indexed_iterate(it, 1) b, s = indexed_iterate(it, 2) c, s = indexed_iterate(it, 3) ``` we lower as: ``` it = foo() iterate, index = index_and_itereate(it) x = iterate(it) a = index(x, 1) y = iterate(it, y) b = index(y, 2) z = iterate(it, z) c = index(z, 3) ``` For tuples `iterate` would simply return the first argument and `index` would be `getfield`. That way, there is no const prop, since `getfield` is called directly and inference can directly use its tfunc. For the fallback case `iterate` is basically just `Base.iterate`, with just a slight tweak to give an intelligent error for short iterables. On simple functions, there isn't much of a difference in execution time, but benchmarking something more complicated like: ``` function g() a, = getfield(((1,),(2.0,3),("x",),(:x,)), Base.inferencebarrier(1)) nothing end ``` shows about a 20% improvement in end-to-end inference/optimize time, which is substantial.
- Loading branch information
Showing
10 changed files
with
64 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters