Contributing to Rust, episode 2: Emit, Unpretty, Dump; Oh MIR
Channel: Felix K
Date: 2022-12-16

We dig into the different ways to get the Rust compiler to print your source code back to you again. Then we show how to work backwards from a specific compiler flag to the code that handles dumping, so that we can modify it to meet our needs while investigating a compiler bug.

Associated Office Hours will be on:
 * 2022-12-28, 16h30 -- 18h00 GMT, and
 * 2023-01-04, 19h00 -- 20h30 GMT

To learn more about how to join the office hours, or to ask questions about the video, join us on Zulip at https://rust-lang.zulipchat.com/#narrow/stream/328238-RustcContributor.3A.3Anew/topic/youtube.20video.3A.20emit.2C.20unpretty.2C.20dump.3B.20oh.20MIR/near/316160576

00:00 - Intro. Our plan for this session
01:35 - Today's motivating problem: two-phase borrows and indexing (`v[v.len() - 1] = ...;`)
17:17 - Internal representation via `--emit mir`
23:10 - Internal representation via `-Z unpretty=...`
34:09 - Internal representation via `-Z dump-mir=...`
43:22 - Work smarter, not harder: tailor source code input to reduce noise when comparing ouputs
49:59 - Changing course: if you can't find the output you want, change the compiler to give it to you
52:38 - Working way backwards from the `-Z` flag to editing the dump routine
57:36 - Following LSP "find references" links to continue searching backwards
1:01:14 - Found `BorrowKind::Mut { two_phase_borrows: bool }`; when+how is it set to true?
1:08:36 - Felix finally figures out when `two_phase_borrows` is set to true
1:11:19 - We find the spot to extend the dump mir routine to include two-phase borrows info
1:15:38 - Demonstrating our modified compiler
1:17:21 - Next steps towards answering our original question (about `v[vlen() - 1] = ...;`)