Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to contribute to Rust and what I have recently been working on

How to contribute to Rust and what I have recently been working on

8e686c2dcfd4cc143fbc21baf893626b?s=128

TaKO8Ki

June 15, 2022
Tweet

More Decks by TaKO8Ki

Other Decks in Technology

Transcript

  1. How to contribute to Rust and what I have recently

    been working on Takayuki Maeda (@TaKO8Ki)
  2. About myself

  3. About myself Takayuki Maeda at CTO Office GitHub: @TaKO8Ki Twitter:

    @TaKOBKi Pull requests I created in rust-lang/rust
  4. How to contribute to Rust All we want is "Guide

    to Rustc Development".
  5. 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.
  6. 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.
  7. $ git clone https://github.com/rust-lang/rust.git $ cd rust Building rustc –

    the Rust compiler – rustc is a bootstrapping compiler $ ./x.py setup
  8. Building rustc – the Rust compiler – Choose the one

    you want to contribute to
  9. 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?
  10. Building rustc – the Rust compiler – Build a compiler

    $ ./x.py build If you want to use incremental compilation $ ./x.py build -i library/std
  11. 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
  12. 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.
  13. Building rustc – the Rust compiler – $ rustup toolchain

    link stage1 build/<host- triple>/stage1 Create rustup toolchains Then you can run $ rustc +stage1 -vV $ cargo +stage1 build
  14. 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'
  15. Debugging rustc rustc uses tokio/tracing for logging.

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

  17. 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.
  18. Debugging rustc #[instrument(level = "debug", skip(self))] fn foo(&self, bar: Type)

    {} Function level filters
  19. 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:
  20. If you have any questions The best way to get

    started is by asking for help in the #new members Zulip stream.
  21. Issue #98087

  22. macro_rules! foo { () => {}; } pub use foo;

    Given the following code: Issue #98087
  23. Issue #98087 The current output is: rustc suggests adding a

    macro `pub`
  24. Issue #98087 The current output is: However, you need to

    use `# [macro_export]` to make the macro public.
  25. Issue #98087 Suggest using `#[macro_export]` when binding.kind is `NameBindingKind::Res(Res::Def(DefKind::Macro(_), _def_id),

    _)`
  26. Issue #98087 However, this suggestion is triggered also by decl_macro.

  27. Issue #98087 To solve this problem, I implemented struct `MacroData`

    including a flag for checking if a macro is `decl_macro` or not.
  28. Issue #98087 And change the type of HashMap `macro_map` value

    to `MacroData`.
  29. Issue #98087 Exclude decl_macros

  30. Issue #98087 Add a ui test

  31. Issue #98087 Add a ui test

  32. Issue #98087 Create a pull request

  33. Issue #98087 Approved 🚀🚀🚀

  34. None