CodeVetter · Repo Unpack · Behavior traces
rust-lang/rust
Three flows traced end-to-end. (1) ./x build: x.py -> bootstrap.py downloads stage0 per src/stage0 -> builds bootstrap binary -> cli_main::main -> Flags::parse -> Config::parse -> out/lock -> Builder runs Step descriptions. (2) rustc hello.rs: main.rs -> rustc_driver_impl::main -> run_compiler -> interface::run_compiler -> parse -> create_and_enter_global_ctxt -> resolver_for_lowering -> analysis -> Linker::codegen_and_build_linker -> link. (3) ./x test: bootstrap test steps build compiletest -> run_tests walks suite dirs -> directive parsing -> per-mode runtest runners -> snapshot diffing. CI is a fourth: ci.yml -> citool matrix -> run-build-from-ci.sh -> x.
- Build startup order: x.py adds src/bootstrap to sys.path and calls bootstrap.main(); bootstrap.py verifies python>=3.x, reads src/stage0 pins, downloads stage0 rustc/cargo tarballs with sha256 verification into build/cache, compiles the bootstrap crate, then execs it.
- Bootstrap main order: src/bootstrap/src/bin/main.rs -> cli_main::main installs a panic hook that prints the active StepStack, parses Flags then Config, acquires a lock file at config.out.join("lock") unless bypass_bootstrap_lock, then runs the Builder.
- Step dispatch: Builder::get_step_descriptions uses the describe! macro per Kind to map CLI paths to Step impls; run_step_descriptions executes each matching Step's run() in dependency order (builder/mod.rs).
- rustc process startup order: rustc_driver_impl::main -> init_rustc_env_logger -> signal_handler::install -> TimePassesCallbacks::default -> install_ice_hook(DEFAULT_BUG_REPORT_URL) -> install_ctrlc_handler (sets rustc_const_eval::CTRL_C_RECEIVED then exits after 100ms) -> catch_with_exit_code(run_compiler).
- Compile pipeline order inside run_compiler: arg_expand_all -> handle_options -> build_session_options -> make_input/make_output -> interface::run_compiler -> passes::parse -> (optional pretty-print early exit) -> create_and_enter_global_ctxt -> resolver_for_lowering -> write_dep_info/write_interface -> tcx.ensure_ok().analysis -> Linker::codegen_and_build_linker -> linker.link.
- Session construction order inside interface::run_compiler: set_dyn_thread_safe_mode -> jobserver::initialize -> build_target_config -> build_early_session -> get_codegen_backend (dylib __rustc_codegen_backend or make_codegen_backend) -> codegen_backend.init -> build_session -> target_config -> parse_cfg/add_configuration -> parse_check_cfg -> lint store via register_lints.
- GlobalCtxt creation order in create_and_enter_global_ctxt: pre_configure_attrs -> get_crate_name -> collect_crate_types -> StableCrateId::new -> build_output_filenames -> setup_dep_graph -> CStore/Definitions/untracked construction -> load_query_result_cache -> clone DEFAULT_QUERY_PROVIDERS -> codegen_backend.provide -> override_queries hook -> TyCtxt::create_global_ctxt with OnceLock gcx_cell and WorkerLocal arenas.
- Test-run order: ./x test -> bootstrap build_steps/test.rs builds and runs the compiletest binary -> compiletest::run_tests installs a panic hook, raises the fd limit, sets __COMPAT_LAYER=RunAsInvoker on Windows, walks tests/<suite> dirs collecting files -> directives parsing (FileDirectives/DirectivesCache) -> executor schedules CollectedTests -> runtest::<mode> modules execute compile/run and diff .stderr/.stdout snapshots.
- CI job order: ci.yml 'calculate_matrix' runs citool calculate-job-matrix over jobs.yml -> each matrix job checks out, runs ~15 setup scripts under src/ci/scripts (free-disk-space, install-sccache/clang/ninja/mingw, verify-channel, verify-line-endings, verify-stable-version-number) -> builds citool -> run-build-from-ci.sh executes the build -> doc artifacts to GitHub, dist artifacts to S3, metrics to DataDog via citool upload-build-metrics.
- Incremental compile ordering: setup_dep_graph decides whether incremental is enabled and returns an IncrCompSession; dep_graph.assert_ignored() runs during HIR construction; load_query_result_cache reads the on-disk cache; after codegen, persist::save writes the new dep graph and work products.
- Early-exit branches in run_compiler happen in a fixed order: --explain, -Whelp (describe_lints after session/lint registration), help_only, --print (print_crate_info), missing input (fatal 'no input filename given'), -Zls metadata listing, -Zlink-only process_rlink, then pretty-printing, then parse_crate_root_only.