Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[RFC-ish][MIR] Add a pass manager #31448
Conversation
rust-highfive
assigned
nikomatsakis
Feb 6, 2016
nagisa
force-pushed the
nagisa:mir-tiered-passes
branch
2 times, most recently
from
665e9a0
to
530beae
Feb 7, 2016
nagisa
force-pushed the
nagisa:mir-tiered-passes
branch
2 times, most recently
from
c2cc646
to
b1d9e88
Feb 9, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @rust-lang/compiler -- I'd be curious to get others' take here. |
This comment has been minimized.
This comment has been minimized.
|
I'm somewhat aghast that mir pass plugins have sneaked into the compiler with no discussion, I think that is a bit premature. Anyway, looking at this PR, I'm in favour of reducing the ad-hoc calling of passes, but this feels like unnecessary flexibility and complexity. |
oli-obk
reviewed
Feb 10, 2016
|
|
||
| /// Pass which only inspects basic blocks in MIR. | ||
| /// | ||
| /// Invariant: The blocks are considered to be fully self-contained for the purposes of this pass – |
This comment has been minimized.
This comment has been minimized.
oli-obk
Feb 10, 2016
Contributor
Why do we need this invariant? For the MirPass implementor it's irrelevant, as it's the same as making sure that the visitor and the run_pass method don't modify the Mir object. For the compiler there's no advantage to knowing this as I see it.
oli-obk
reviewed
Feb 10, 2016
| /// | ||
| /// Invariant: The blocks are considered to be fully self-contained for the purposes of this pass – | ||
| /// the pass may not change the list of successors of the block or apply any transformations to | ||
| /// blocks based on the information collected during earlier runs of the pass. |
This comment has been minimized.
This comment has been minimized.
oli-obk
Feb 10, 2016
Contributor
The pass can easily hold information. It's not very useful, but it can do it.
This comment has been minimized.
This comment has been minimized.
nagisa
Feb 10, 2016
Author
Contributor
The point of this invariant is that the pass should not store such information. Primarily because I expect these passes to be pipelined, parallelized, etc in the future. The pass must not rely on getting blocks in any deterministic order. (I realise I also forgot to add a similar invariant for the MirPass)
This comment has been minimized.
This comment has been minimized.
I’ve modelled the passes to match the LLVM’s pass structure somewhat closely – namely their What I’m currently worried about the most, after sleeping on it for a while, is that the passes might not be flexible enough yet (for e.g. @arielb1’s typeck pass). |
This comment has been minimized.
This comment has been minimized.
|
On Tue, Feb 09, 2016 at 06:54:29PM -0800, Nick Cameron wrote:
I was also surprised. |
This comment has been minimized.
This comment has been minimized.
|
Are there any users for |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I mean, what would you use it for? |
This comment has been minimized.
This comment has been minimized.
|
@arielb1 I was initially considering it to be a good fit for:
The drop removal pass, however, would rely on passes being able to share the analysis results with other passes, namely the liveness checker. I think typeck pass could also use it, provided we happen to grow support for something similar to EDIT: to summarize, I, myself, think that in current state, the |
nagisa
changed the title
[MIR] Add a pass manager
[RFC-ish][MIR] Add a pass manager
Feb 10, 2016
nagisa
reviewed
Feb 10, 2016
| } | ||
|
|
||
| /// Pass which only inspects MIR of distinct functions. | ||
| pub trait MirPass: Pass { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I was kind-of working on an unnecessary drop removal as a part of non-zeroing drop, but I think that work is going to be stuck for a while. Of course, that would probably want to be a full function pass because of the dataflow/analysis. |
This comment has been minimized.
This comment has been minimized.
|
OK so I think these are my overall thoughts:
(It may be worth writing an RFC on this, but it also feels like overkill.) |
This comment has been minimized.
This comment has been minimized.
Only the pass hierarchy ( |
This comment has been minimized.
This comment has been minimized.
|
I’m fine with stripping this PR to a bare minimum so only the barebones pass manager (executes pass in order they’ve been pushed), |
nagisa
added some commits
Jan 31, 2016
nagisa
force-pushed the
nagisa:mir-tiered-passes
branch
from
b1d9e88
to
bd4ddf3
Feb 15, 2016
This comment has been minimized.
This comment has been minimized.
|
The simplified version looks nice @nagisa! I see though that travis fails with the following:
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
This will be a pain to rebase. I’ll submit a new one later. |
nagisa commentedFeb 6, 2016
Previously we would run MIR passes in a very ad-hoc way by calling passses directly everywhere across the compiler. This PR adds a proper pass manager which will run all the passes in some order (decided by the
prioritymethod inPass) right after the MIR is constructed. I believe the pass manager should be general enough to be able to accommodate passes as complex as MIR-based borrowck.The next step here would be to add something like
-Z mir-opt-level=[0..]defaulting to1 + -C opt-leveland afn should_run(&Session)so the passes could decide whether they want to run under a given optimisation level or not.Depends on #31425 landing first.
r? @nikomatsakis