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,709
536
1,709
167

Top Related Projects

102,191

Empowering everyone to build reliable and efficient software.

15,568

The Rust Programming Language

The Rust Reference

1,990

The Dark Arts of Advanced and Unsafe Rust Programming

Learn Rust with examples (Live code editor included)

55,860

: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

102,191

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.

15,568

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,990

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.

55,860

: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-linkcheck2 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-linkcheck2 to validate URLs included in our documentation. Link checking is not run by default locally, though it is in CI. To enable it locally, set the environment variable ENABLE_LINKCHECK=1 like in the following example.

$ ENABLE_LINKCHECK=1 mdbook serve

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.

Synchronizing josh subtree with rustc

This repository is linked to rust-lang/rust as a josh subtree. You can use the following commands to synchronize the subtree in both directions.

You'll need to install josh-proxy locally via

cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04

Older versions of josh-proxy may not round trip commits losslessly so it is important to install this exact version.

Pull changes from rust-lang/rust into this repository

  1. Checkout a new branch that will be used to create a PR into rust-lang/rustc-dev-guide
  2. Run the pull command
    $ cargo run --manifest-path josh-sync/Cargo.toml rustc-pull
    
  3. Push the branch to your fork and create a PR into rustc-dev-guide

Push changes from this repository into rust-lang/rust

  1. Run the push command to create a branch named <branch-name> in a rustc fork under the <gh-username> account
    $ cargo run --manifest-path josh-sync/Cargo.toml rustc-push <branch-name> <gh-username>
    
  2. Create a PR from <branch-name> into rust-lang/rust

Minimal git config

For simplicity (ease of implementation purposes), the josh-sync script simply calls out to system git. This means that the git invocation may be influenced by global (or local) git configuration.

You may observe "Nothing to pull" even if you know rustc-pull has something to pull if your global git config sets fetch.prunetags = true (and possibly other configurations may cause unexpected outcomes).

To minimize the likelihood of this happening, you may wish to keep a separate minimal git config that only has [user] entries from global git config, then repoint system git to use the minimal git config instead. E.g.

$ GIT_CONFIG_GLOBAL=/path/to/minimal/gitconfig GIT_CONFIG_SYSTEM='' cargo +stable run --manifest-path josh-sync/Cargo.toml -- rustc-pull