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,910
611
1,910
145

Top Related Projects

115,493

Empowering everyone to build reliable and efficient software.

18,076

The Rust Programming Language

The Rust Reference

2,325

The Dark Arts of Advanced and Unsafe Rust Programming

Learn Rust with examples (Live code editor included)

63,590

: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

115,493

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.

18,076

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.

2,325

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.

63,590

: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

About the rustc-dev-guide

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.

For more information, see About This Guide.

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!

See below for instructions on writing new docs.

The guide has a much lower bar for what it takes for a PR to be merged. Check out the forge documentation for our policy.

Build Instructions

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

cargo install --locked mdbook mdbook-linkcheck2 mdbook-mermaid

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

mdbook serve --open

For a one-off build, you can use mdbook build.

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

Editing the guide

Where to start

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.

Layout

The dev-guide is organized as a normal mdBook: It has a src/SUMMARY.md table of contents, which links to individual pages under src/. Configuration lives in book.toml. Images are in src/img. The build files are found in the book/html directory.

NOTE: if you do not add a page to SUMMARY.md, it will not be shown!

While writing

See the guide itself for instructions on writing new docs.

Maintaining the guide

CI

Various tools are kept under ci/. Check links with mdbook-linkcheck2 --standalone. Check semantic line breaks with cargo run --manifest-path ci/sembr/Cargo.toml src. Triage <!-- date-check --> annotations with cargo run --manifest-path ci/date-check/Cargo.toml ..

You can test those tools with cargo test --manifest-path ci/<tool>/Cargo.toml.

Synchronizing josh subtree with rustc

This repository is linked to rust-lang/rust as a josh subtree. You can use the rustc-josh-sync tool to perform synchronization.

You can find a guide on how to perform the synchronization here.