rust-lang / rustc-dev-guide

A guide to how rustc works and how to contribute to it.
https://rustc-dev-guide.rust-lang.org
Apache License 2.0
1.65k stars 510 forks source link

Tracking issue for "Compiler walkthrough" section #1062

Open camelid opened 3 years ago

camelid commented 3 years ago

(name is to-be-bikeshedded)

cc https://rust-lang.zulipchat.com/#narrow/stream/196385-t-compiler.2Fwg-rustc-dev-guide/topic/planning.20meeting.202021.2E02.2E18


camelid commented 3 years ago

As we discussed in the meeting, we're going to show each pass of the compiler, each intermediate representation (before & after pass), and some internal data structures (like TyCtxt).

However, we're going to start with just showing tokens, AST, and HIR (with no internal data structures) going through the passes of lex, parse, resolve, and macro-expand, which are actually interleaved together:

lex -> (parse <-> resolve <-> expand)

We're going to start with this example code (I modified it slightly to use @LeSeulArtichaut's name suggestion, and to change String to &str, which is more idiomatic and will let us show lifetimes in action):

fn is_awesome(name: &str) -> bool {
    matches!(name, "Rust" | "Ferris")
}

(See the Zulip discussion for details on why we chose this example.)

camelid commented 3 years ago
  • Implement (an MVP of) -Z dump-internal-data [@camelid]

What do you think would be a good MVP for -Z dump-internal-data? Maybe print the type of everything in the program?

LeSeulArtichaut commented 3 years ago

"Internal data" is very broad. Let's maybe try to make a list of all the things we would like to be able to dump?

camelid commented 3 years ago

Sounds like a good idea :)

LeSeulArtichaut commented 3 years ago

Opened https://rust-lang.zulipchat.com/#narrow/stream/196385-t-compiler.2Fwg-rustc-dev-guide/topic/-Z.20dump-internal-data for discussion about -Z dump-internal-data