Convert Figma logo to code with AI

rust-lang logorustc-dev-guide

A guide to how rustc works and how to contribute to it.

1,636
499
1,636
193

Top Related Projects

96,644

Empowering everyone to build reliable and efficient software.

14,881

The Rust Programming Language

The Rust Reference

1,790

The Dark Arts of Advanced and Unsafe Rust Programming

Learn Rust with examples (Live code editor included)

52,586

:crab: Small exercises to get you used to reading and writing Rust code!

Quick Overview

The rust-lang/rustc-dev-guide is a comprehensive documentation project for the Rust compiler (rustc). It serves as a guide for developers who want to contribute to the Rust compiler, providing detailed information about its architecture, implementation, and development processes.

Pros

  • Extensive and well-organized documentation on the Rust compiler's internals
  • Regularly updated to reflect changes in the Rust compiler
  • Includes both high-level overviews and detailed technical explanations
  • Helps lower the barrier to entry for new contributors to the Rust compiler

Cons

  • Can be overwhelming for beginners due to the complexity of the compiler
  • Requires a solid understanding of Rust and compiler design concepts
  • May not always be up-to-date with the latest changes in the rapidly evolving Rust ecosystem
  • Some sections might lack depth or require further expansion

Note: As this is a documentation project and not a code library, the code examples and getting started instructions sections have been omitted.

Competitor Comparisons

96,644

Empowering everyone to build reliable and efficient software.

Pros of rust

  • Contains the actual Rust compiler and standard library source code
  • Provides a comprehensive test suite for the Rust language
  • Allows direct contributions to the Rust language and its core components

Cons of rust

  • Larger and more complex codebase, potentially harder for newcomers to navigate
  • Requires a deeper understanding of Rust internals to contribute effectively
  • May have a steeper learning curve for those looking to understand Rust's implementation

Code Comparison

rustc-dev-guide (documentation example):

# The `ty` module: representing types

This module defines how the Rust compiler represents types internally.

rust (actual implementation):

pub mod ty {
    use crate::mir::interpret::{AllocId, ConstValue, Scalar};
    use crate::ty::subst::{GenericArg, SubstsRef};
    // ... (more implementation details)
}

The rustc-dev-guide repository focuses on providing documentation and guidance for Rust compiler development, while the rust repository contains the actual implementation of the Rust compiler and standard library. The rustc-dev-guide is more accessible for those looking to understand the compiler's architecture, while rust is where the actual development and maintenance of the language occur.

14,881

The Rust Programming Language

Pros of book

  • More beginner-friendly, focusing on teaching Rust from the ground up
  • Covers a broader range of Rust concepts and features
  • Regularly updated with new Rust releases and community feedback

Cons of book

  • Less detailed information on Rust's internal workings
  • Not as helpful for contributors looking to work on the Rust compiler itself
  • May not cover some advanced or niche topics in depth

Code comparison

book:

fn main() {
    println!("Hello, world!");
}

rustc-dev-guide:

fn compile_input(input: &str) -> Result<(), Box<dyn Error>> {
    let config = rustc_interface::Config::default();
    rustc_interface::run_compiler(config, |compiler| {
        // Compiler operations here
    })
}

The book example shows a simple "Hello, world!" program, typical for beginners. The rustc-dev-guide example demonstrates a more complex function related to compiler operations, reflecting its focus on Rust's internals.

Both repositories serve different purposes within the Rust ecosystem. book is an excellent resource for learning Rust programming, while rustc-dev-guide is invaluable for those interested in contributing to Rust's compiler or understanding its inner workings. The choice between them depends on the user's goals and level of expertise in Rust.

The Rust Reference

Pros of Reference

  • More comprehensive coverage of Rust language features
  • Serves as the authoritative specification for the Rust language
  • Regularly updated to reflect the latest stable Rust version

Cons of Reference

  • Focuses solely on language features, not compiler internals
  • May be more challenging for beginners to understand
  • Less practical guidance for contributing to Rust development

Code Comparison

Reference:

fn main() {
    let x: i32 = 5;
    let y: i32 = 10;
    println!("x + y = {}", x + y);
}

rustc-dev-guide:

fn compile_fn(tcx: TyCtxt<'_>, def_id: DefId) {
    let body = tcx.optimized_mir(def_id);
    // ... compiler-specific code ...
}

The Reference provides examples of Rust code as it would be written by users, while the rustc-dev-guide shows internal compiler code and processes.

Summary

The Reference is ideal for understanding Rust language features and serves as the official language specification. The rustc-dev-guide, on the other hand, is more suitable for those interested in contributing to Rust's development or understanding the compiler's inner workings. While the Reference covers a broader range of topics related to the language itself, the rustc-dev-guide offers practical insights into the compiler's implementation and development process.

1,790

The Dark Arts of Advanced and Unsafe Rust Programming

Pros of nomicon

  • Focuses on advanced and unsafe Rust concepts, providing deeper insights
  • More concise and targeted content for experienced Rust developers
  • Includes detailed explanations of memory layout and low-level operations

Cons of nomicon

  • Less comprehensive coverage of the Rust compiler's internals
  • Not as frequently updated as rustc-dev-guide
  • Lacks specific guidance for contributing to the Rust project

Code comparison

nomicon:

unsafe {
    let mut num = 5;
    let r1 = &num as *const i32;
    let r2 = &mut num as *mut i32;
    *r2 += 1;
    println!("r1: {}, r2: {}", *r1, *r2);
}

rustc-dev-guide:

fn compile_crate() -> Result<(), ErrorReported> {
    let sess = ty::TyCtxt::create_global_ctxt(...);
    sess.enter(|tcx| {
        tcx.analysis(LOCAL_CRATE)
    })
}

The nomicon example demonstrates unsafe Rust and raw pointers, while the rustc-dev-guide snippet shows compiler-specific code related to type checking and analysis.

Learn Rust with examples (Live code editor included)

Pros of rust-by-example

  • More beginner-friendly with interactive examples
  • Covers a wide range of Rust concepts and features
  • Provides practical, runnable code snippets

Cons of rust-by-example

  • Less in-depth coverage of advanced topics
  • Focuses on language features rather than compiler internals
  • May not be as up-to-date with the latest Rust developments

Code comparison

rustc-dev-guide (explaining compiler internals):

fn compile_crate() -> Compilation {
    let sess = ParseSess::new(opts);
    let krate = parse::parse_crate_from_file(&input, &sess);
    // ... more compiler-specific code
}

rust-by-example (demonstrating language features):

fn main() {
    let x = 5;
    let y = if x == 5 { 10 } else { 15 };
    println!("y = {}", y);
}

The rustc-dev-guide repository is focused on explaining the internals of the Rust compiler, making it more suitable for advanced users and those interested in contributing to the compiler itself. It provides detailed information about the compilation process, data structures, and algorithms used in rustc.

On the other hand, rust-by-example is designed to teach Rust programming through interactive examples. It covers a wide range of language features and concepts, making it ideal for beginners and those looking to improve their Rust skills. The examples are concise and runnable, allowing users to experiment with the code directly in their browser.

52,586

:crab: Small exercises to get you used to reading and writing Rust code!

Pros of rustlings

  • More beginner-friendly, focusing on hands-on exercises
  • Interactive learning experience with immediate feedback
  • Covers a wide range of Rust concepts in bite-sized lessons

Cons of rustlings

  • Less comprehensive coverage of Rust's internals and compiler
  • Limited depth in advanced topics and language implementation details
  • Doesn't provide extensive documentation on Rust's development process

Code comparison

rustlings example:

fn main() {
    let x = 5;
    println!("x has the value {}", x);
}

rustc-dev-guide example:

fn main() {
    let tcx: TyCtxt<'_> = /* ... */;
    let def_id = /* ... */;
    let ty = tcx.type_of(def_id);
}

The rustlings example focuses on basic syntax and concepts, while the rustc-dev-guide example deals with internal compiler structures and processes.

Summary

rustlings is an excellent resource for beginners learning Rust through practical exercises. It offers a more interactive and approachable learning experience compared to the rustc-dev-guide. However, it lacks the depth and comprehensive coverage of Rust's internals that the rustc-dev-guide provides. The rustc-dev-guide is better suited for those interested in understanding Rust's compiler internals and contributing to its development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CI

This is a collaborative effort to build a guide that explains how rustc works. The aim of the guide is to help new contributors get oriented to rustc, as well as to help more experienced folks in figuring out some new part of the compiler that they haven't worked on before.

You can read the latest version of the guide here.

You may also find the rustdocs for the compiler itself useful. Note that these are not intended as a guide; it's recommended that you search for the docs you're looking for instead of reading them top to bottom.

For documentation on developing the standard library, see std-dev-guide.

Contributing to the guide

The guide is useful today, but it has a lot of work still to go.

If you'd like to help improve the guide, we'd love to have you! You can find plenty of issues on the issue tracker. Just post a comment on the issue you would like to work on to make sure that we don't accidentally duplicate work. If you think something is missing, please open an issue about it!

In general, if you don't know how the compiler works, that is not a problem! In that case, what we will do is to schedule a bit of time for you to talk with someone who does know the code, or who wants to pair with you and figure it out. Then you can work on writing up what you learned.

In general, when writing about a particular part of the compiler's code, we recommend that you link to the relevant parts of the rustc rustdocs.

Build Instructions

To build a local static HTML site, install mdbook with:

> cargo install mdbook mdbook-linkcheck mdbook-toc mdbook-mermaid

and execute the following command in the root of the repository:

> mdbook build --open

The build files are found in the book/html directory.

Link Validations

We use mdbook-linkcheck to validate URLs included in our documentation. linkcheck will be run automatically when you build with the instructions in the section above.

Table of Contents

We use mdbook-toc to auto-generate TOCs for long sections. You can invoke the preprocessor by including the <!-- toc --> marker at the place where you want the TOC.

How to fix toolstate failures

NOTE: Currently, we do not track the rustc-dev-guide toolstate due to spurious failures, but we leave these instructions for when we do it again in the future.

  1. You will get a ping from the toolstate commit. e.g. https://github.com/rust-lang-nursery/rust-toolstate/commit/8ffa0e4c30ac9ba8546b7046e5c4ccc2b96ebdd4

  2. The commit contains a link to the PR that caused the breakage. e.g. https://github.com/rust-lang/rust/pull/64321

  3. If you go to that PR's thread, there is a post from bors with a link to the CI status: https://github.com/rust-lang/rust/pull/64321#issuecomment-529763807

  4. Follow the check-actions link to get to the Actions page for that build

  5. There will be approximately 1 billion different jobs for the build. They are for different configurations and platforms. The rustc-dev-guide build only runs on the Linux x86_64-gnu-tools job. So click on that job in the list, which is about 60% down in the list.

  6. Click the Run build step in the job to get the console log for the step.

  7. Click on the log and Ctrl-f to get a search box in the log

  8. Search for rustc-dev-guide. This gets you to the place where the links are checked. It is usually ~11K lines into the log.

  9. Look at the links in the log near that point in the log

  10. Fix those links in the rustc-dev-guide (by making a PR in the rustc-dev-guide repo)

  11. Make a PR on the rust-lang/rust repo to update the rustc-dev-guide git submodule in src/docs/rustc-dev-guide. To make a PR, the following steps are useful.

# Assuming you already cloned the rust-lang/rust repo and you're in the correct directory
git submodule update --remote src/doc/rustc-dev-guide
git add -u
git commit -m "Update rustc-dev-guide"
# Note that you can use -i, which is short for --incremental, in the following command
./x test --incremental src/doc/rustc-dev-guide # This is optional and should succeed anyway
# Open a PR in rust-lang/rust
  1. Wait for PR to merge

Voilà!