Slide 1

Slide 1 text

How to contribute to Rust and what I have recently been working on Takayuki Maeda (@TaKO8Ki)

Slide 2

Slide 2 text

About myself

Slide 3

Slide 3 text

About myself Takayuki Maeda at CTO Office GitHub: @TaKO8Ki Twitter: @TaKOBKi Pull requests I created in rust-lang/rust

Slide 4

Slide 4 text

How to contribute to Rust All we want is "Guide to Rustc Development".

Slide 5

Slide 5 text

Guide to Rustc Development Building and debugging rustc Contributing to rustc High-Level Compiler Architecture Source Code Representation Analysis From MIR to Binaries Appendices has seven parts: 1. 2. 3. 4. 5. 6. 7.

Slide 6

Slide 6 text

Guide to Rustc Development Building and debugging rustc Contributing to rustc High-Level Compiler Architecture Source Code Representation Analysis From MIR to Binaries Appendices has seven parts: 1. 2. 3. 4. 5. 6. 7.

Slide 7

Slide 7 text

$ git clone https://github.com/rust-lang/rust.git $ cd rust Building rustc – the Rust compiler – rustc is a bootstrapping compiler $ ./x.py setup

Slide 8

Slide 8 text

Building rustc – the Rust compiler – Choose the one you want to contribute to

Slide 9

Slide 9 text

Building rustc – the Rust compiler – ./x.py setup creates config.toml [rust] debug-logging = true # Leave debug! and trace! calls in rustc? incremental = true # Build rustc with incremental compilation?

Slide 10

Slide 10 text

Building rustc – the Rust compiler – Build a compiler $ ./x.py build If you want to use incremental compilation $ ./x.py build -i library/std

Slide 11

Slide 11 text

Building rustc – the Rust compiler – Build std using the stage0 compiler (using incremental) Build rustc using the stage0 compiler (using incremental) This produces the stage1 compiler Build std using the stage1 compiler (cannot use incremental) This command does the following things: $ ./x.py build -i library/std

Slide 12

Slide 12 text

Building rustc – the Rust compiler – You cannot use incremental compilation for stage1 libraries.This is because incremental only works when you run the same compiler twice in a row.

Slide 13

Slide 13 text

Building rustc – the Rust compiler – $ rustup toolchain link stage1 build//stage1 Create rustup toolchains Then you can run $ rustc +stage1 -vV $ cargo +stage1 build

Slide 14

Slide 14 text

Testing rustc $ ./x.py test src/test/ui If you want to run rustc ui tests If you want to run specific tests $ ./x.py test src/test/ui --test-args 'derives'

Slide 15

Slide 15 text

Debugging rustc rustc uses tokio/tracing for logging.

Slide 16

Slide 16 text

Debugging rustc debug!("lower_opaque_impl_trait: lifetime_defs= {:#?}", lifetime_defs); debug!(?lifetime_defs); or

Slide 17

Slide 17 text

Debugging rustc $ RUSTC_LOG=rustc_middle::traits=debug cargo +stage1 build You can use module level filters You can use the other filters such as function level filters and query level filters.

Slide 18

Slide 18 text

Debugging rustc #[instrument(level = "debug", skip(self))] fn foo(&self, bar: Type) {} Function level filters

Slide 19

Slide 19 text

Find issues If you are interested in developing a parser → A-parser (Area: The parsing of Rust source code to an AST.) If you are interested in developing a rustdoc → T-rustdoc (Relevant to the rustdoc Team, which will review and decide on the PR/issue.) https://github.com/rust-lang/rust/issues There are some labels like the following:

Slide 20

Slide 20 text

If you have any questions The best way to get started is by asking for help in the #new members Zulip stream.

Slide 21

Slide 21 text

Issue #98087

Slide 22

Slide 22 text

macro_rules! foo { () => {}; } pub use foo; Given the following code: Issue #98087

Slide 23

Slide 23 text

Issue #98087 The current output is: rustc suggests adding a macro `pub`

Slide 24

Slide 24 text

Issue #98087 The current output is: However, you need to use `# [macro_export]` to make the macro public.

Slide 25

Slide 25 text

Issue #98087 Suggest using `#[macro_export]` when binding.kind is `NameBindingKind::Res(Res::Def(DefKind::Macro(_), _def_id), _)`

Slide 26

Slide 26 text

Issue #98087 However, this suggestion is triggered also by decl_macro.

Slide 27

Slide 27 text

Issue #98087 To solve this problem, I implemented struct `MacroData` including a flag for checking if a macro is `decl_macro` or not.

Slide 28

Slide 28 text

Issue #98087 And change the type of HashMap `macro_map` value to `MacroData`.

Slide 29

Slide 29 text

Issue #98087 Exclude decl_macros

Slide 30

Slide 30 text

Issue #98087 Add a ui test

Slide 31

Slide 31 text

Issue #98087 Add a ui test

Slide 32

Slide 32 text

Issue #98087 Create a pull request

Slide 33

Slide 33 text

Issue #98087 Approved 🚀🚀🚀

Slide 34

Slide 34 text

No content