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

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)

    View Slide

  2. About myself

    View Slide

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

    View Slide

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

    View Slide

  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.

    View Slide

  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.

    View Slide

  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

    View Slide

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

    View Slide

  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?

    View Slide

  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

    View Slide

  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

    View Slide

  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.

    View Slide

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

    View Slide

  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'

    View Slide

  15. Debugging rustc
    rustc uses tokio/tracing for logging.

    View Slide

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

    View Slide

  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.

    View Slide

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

    View Slide

  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:

    View Slide

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

    View Slide

  21. Issue #98087

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  29. Issue #98087
    Exclude decl_macros

    View Slide

  30. Issue #98087
    Add a ui test

    View Slide

  31. Issue #98087
    Add a ui test

    View Slide

  32. Issue #98087
    Create a pull request

    View Slide

  33. Issue #98087
    Approved 🚀🚀🚀

    View Slide

  34. View Slide