1 of 48

Hacking rustc

Contributing to the Compiler

Esteban Küber

@ekuber

@estebank

2 of 48

3 of 48

Hacking rustc

Contributing to the Compiler

Esteban Küber

@ekuber

@estebank

4 of 48

Hacking rustc

Contributing to the Compiler

You can

v

x

/

e

Esteban Küber

@ekuber

@estebank

5 of 48

6 of 48

optimization passes

Parser

type inference

lifetime analysis

7 of 48

rustc: it’s “just” a program

8 of 48

rustc: it’s “just” a program

*

*terms and conditions apply

9 of 48

What are YOU interested in?

Get yourself ready

Find things to do

10 of 48

Finding things to do:

-You already know what you want to do

- found something broken?

- want something we don’t have?

11 of 48

Adding new things to Rust

The RFC process is to propose new language features to the lang team

The MCP “Major Change Proposal” process is for changes to the compiler

12 of 48

Finding things to do:

-You already know what you want to do

- found something broken?

- want something we don’t have?

- Check the backlog for

bugs and feature requests

13 of 48

14 of 48

15 of 48

16 of 48

17 of 48

18 of 48

19 of 48

20 of 48

21 of 48

Settings things up

22 of 48

23 of 48

24 of 48

get ready to wait

25 of 48

git

cmake

python

26 of 48

VIDEO

VIDEO

27 of 48

get ready to wait

28 of 48

x.py

like cargo, but for the compiler

29 of 48

rustup toolchain link dev \

~/rust/build/x86_64-apple-darwin/stage1/

rustc +dev file.rs

cargo +dev build

30 of 48

31 of 48

# contents of my config.toml

# Includes one of the default files in src/bootstrap/defaults

profile = "compiler"

changelog-seen = 2

[rust]

debug = true

debug-assertions = false

debuginfo-level = 1

debuginfo-level-rustc = 1

debuginfo-level-std = 1

run-dsymutil = true

32 of 48

RUSTC_LOG=path::to::module::I::care::about=info \

rustc +dev file.rs

33 of 48

Resources:

  • Rust Compiler Dev Guide

https://rustc-dev-guide.rust-lang.org

34 of 48

Resources:

  • Rust Compiler Dev Guide
  • Zulip

https://rust-lang.zulipchat.com/

35 of 48

Resources:

  • Rust Compiler Dev Guide
  • Zulip
  • Merged Pull Requests and closed tickets

36 of 48

Resources:

  • Rust Compiler Dev Guide
  • Zulip
  • Merged Pull Requests and closed tickets

37 of 48

38 of 48

RUST_BACKTRACE=1 \

rustc +dev file.rs \

-Ztreat-err-as-bug=1

39 of 48

SCREEN SHOT OF BACKTRACE

40 of 48

The compiler

  • takes a text file
  • tokenizes it
  • parses the tokens, giving you an AST
  • turns the AST into a HIR tree

...

41 of 48

...

  • name resolution
  • typechecking
  • trait resolution
  • lifetime analysis

The compiler

42 of 48

vec

Vec

let x = 1i32;

let y = vec![1, 2, 3];

let z = y[x]; // 🙅‍♀️

43 of 48

...

  • name resolution
  • typechecking
  • trait resolution
  • lifetime analysis

The compiler

44 of 48

...

  • AND MORE!!1

The compiler

45 of 48

46 of 48

47 of 48

we need more time

the rust compiler is big

working on it can be slow

IT’S WORTH IT

48 of 48

thank you for listening!

enjoy the rest of RustConf