Debian Codegraph @

gcc/rust/checks/errors/borrowck/dev-notes.md

raw
1 # Borrow-checker Development Notes
2
3 ## Testing BIR building
4
5 There is no way to test BIR building directly, since it is a dead branch of the compilation pipeline.
6 The only way to verify its generations is through manual inspection.
7 The best way to inspect the BIR is to compare it with rustc's MIR.
8
9 The following command will compile a rust file into a library and dump its MIR:
10
11 ```shell
12 rustc --crate-type=lib -A dead_code -A unused -Z dump-mir="" <file>
13 ```
14
15 The MIR dump directory `mir_dump` contains a dump before and after each MIR pass.
16 We are interested in the one used for borrow-checking, which is called `<crate>.<function>.002-000.analysis.after.mir`.
17
18 BIR dump is emitted to a `bir_dump` directory. With the following naming scheme: `<crate>.<function>.bir.dump`.
19
20 At this point, MIR dump contains helper constructions that BIR does not contain yet (like storage live/dead annotations). To remove them from the MIR dump, run the following command:
21
22 ```shell
23 awk -i inplace '!/^\s*(\/\/|StorageLive|StorageDead|FakeRead)/' mir_dump/*
24 ```
25
26 To get the BIR dump into a similar format, run the following command:
27
28 ```shell
29 ./crab1 <file> -frust-incomplete-and-experimental-compiler-do-not-use -frust-borrowcheck -frust-dump-bir -frust-compile-until=compilation
30 ```
31
32
33 ## TODO
34
35 - scope handling, cleanup
36 - switch coercions to adjustments from typechecking
37 - operator overloading
38 - match selection
39 - let without an initializer
40 - lifetime parameters