Skip to content

Commit b5b2057

Browse files
committed
refine mir passes doc
1 parent 5f32dda commit b5b2057

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/mir/passes.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
If you would like to get the MIR:
44

5-
- for a function - you can use the `optimized_mir(def_id)` query;
6-
- for a promoted - you can use the `promoted_mir(def_id)` query.
5+
- for a function - you can use the `optimized_mir` query (typically used by codegen) or the `mir_for_ctfe` query (typically used by compile time function evaluation, i.e., *CTFE*);
6+
- for a promoted - you can use the `promoted_mir` query.
77

88
These will give you back the final, optimized MIR. For foreign def-ids, we simply read the MIR
99
from the other crate's metadata. But for local def-ids, the query will
@@ -13,8 +13,8 @@ This section describes how those queries and passes work and how you can extend
1313

1414
To produce the optimized MIR for a given def-id `D`, `optimized_mir(D)`
1515
goes through several suites of passes, each grouped by a
16-
query. Each suite consists of passes which perform analysis, transformation or optimization.
17-
Each query represent a useful intermediate point
16+
query. Each suite consists of passes which perform linting, analysis, transformation or
17+
optimization. Each query represent a useful intermediate point
1818
where we can access the MIR dialect for type checking or other purposes:
1919

2020
- `mir_built(D)` – it gives the initial MIR just after it's built;
@@ -31,7 +31,7 @@ where we can access the MIR dialect for type checking or other purposes:
3131
## Implementing and registering a pass
3232

3333
A `MirPass` is some bit of code that processes the MIR, typically transforming it along the way
34-
somehow. But it may also do other things like analysis (e.g., [`CheckPackedRef`][lint1],
34+
somehow. But it may also do other things like lingint (e.g., [`CheckPackedRef`][lint1],
3535
[`CheckConstItemMutation`][lint2], [`FunctionItemReferences`][lint3], which implement `MirLint`) or
3636
optimization (e.g., [`SimplifyCfg`][opt1], [`RemoveUnneededDrops`][opt2]). While most MIR passes
3737
are defined in the [`rustc_mir_transform`][mirtransform] crate, the `MirPass` trait itself is
@@ -42,15 +42,15 @@ The MIR is therefore modified in place (which helps to keep things efficient).
4242
A basic example of a MIR pass is [`RemoveStorageMarkers`], which walks
4343
the MIR and removes all storage marks if they won't be emitted during codegen. As you
4444
can see from its source, a MIR pass is defined by first defining a
45-
dummy type, a struct with no fields, something like:
45+
dummy type, a struct with no fields:
4646

4747
```rust
48-
struct MyPass;
48+
pub struct RemoveStorageMarkers;
4949
```
5050

51-
for which you then implement the `MirPass` trait. You can then insert
51+
for which we implement the `MirPass` trait. We can then insert
5252
this pass into the appropriate list of passes found in a query like
53-
`optimized_mir`, `mir_validated`, etc. (If this is an optimization, it
53+
`mir_built`, `optimized_mir`, etc. (If this is an optimization, it
5454
should go into the `optimized_mir` list.)
5555

5656
Another example of a simple MIR pass is [`CleanupNonCodegenStatements`][cleanup-pass], which walks
@@ -62,7 +62,7 @@ fields:
6262
pub struct CleanupNonCodegenStatements;
6363
```
6464

65-
for which we then implement the `MirPass` trait:
65+
for which we implement the `MirPass` trait:
6666

6767
```rust
6868
impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements {
@@ -95,11 +95,9 @@ ensure that, before the MIR at a particular phase in the processing
9595
pipeline is stolen, anyone who may want to read from it has already
9696
done so.
9797

98-
<!-- FIXME - What is force? Do we still have it in rustc? -->
9998
Concretely, this means that if you have a query `foo(D)`
100-
that wants to access the result of `mir_const(D)` or
101-
`mir_promoted(D)`, you need to have the successor pass "force"
102-
`foo(D)` using `ty::queries::foo::force(...)`. This will force a query
99+
that wants to access the result of `mir_promoted(D)`, you need to have `foo(D)`
100+
calling the `mir_const(D)` query first. This will force it
103101
to execute even though you don't directly require its result.
104102

105103
> This mechanism is a bit dodgy. There is a discussion of more elegant

0 commit comments

Comments
 (0)