You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/mir/passes.md
+12-14
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
3
3
If you would like to get the MIR:
4
4
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.
7
7
8
8
These will give you back the final, optimized MIR. For foreign def-ids, we simply read the MIR
9
9
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
13
13
14
14
To produce the optimized MIR for a given def-id `D`, `optimized_mir(D)`
15
15
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
18
18
where we can access the MIR dialect for type checking or other purposes:
19
19
20
20
-`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:
31
31
## Implementing and registering a pass
32
32
33
33
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],
35
35
[`CheckConstItemMutation`][lint2], [`FunctionItemReferences`][lint3], which implement `MirLint`) or
36
36
optimization (e.g., [`SimplifyCfg`][opt1], [`RemoveUnneededDrops`][opt2]). While most MIR passes
37
37
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).
42
42
A basic example of a MIR pass is [`RemoveStorageMarkers`], which walks
43
43
the MIR and removes all storage marks if they won't be emitted during codegen. As you
44
44
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:
46
46
47
47
```rust
48
-
structMyPass;
48
+
pubstructRemoveStorageMarkers;
49
49
```
50
50
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
52
52
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
54
54
should go into the `optimized_mir` list.)
55
55
56
56
Another example of a simple MIR pass is [`CleanupNonCodegenStatements`][cleanup-pass], which walks
0 commit comments