因果応報

忘れないうちに書き留める

Feb 3, 2019 - 2 minute read - Comments - rust

[Memo] Rustc Overview - librustc_driver

git revision: rust-lang/rust: ee229f7fd060b9ff3cd5df4556dd550a3df0b62f

rustc

librustc_driver

main

  • run
  • run_compiler
  • process::exit

run_compiler_with_pool

  • rustc_lint::register_builtins
  • driver::compile_input
  • phase_1_parse_input
  • CompileState::state_after_parse
  • controller_entry_point!
  • build_output_filenames
  • ::rustc_codegen_utils:: link ::find_crate_name
  • install_panic_hook
  • phase_2_configure_and_expand
  • generated_output_paths
  • write_out_deps
  • hir_map::map_crate
  • hir_map.dep_graph.assert_ignored
  • controller_entry_point!
  • AllArenas::new
  • phase_3_run_analysis_passes
  • phase_4_codegen
  • codegen_backend.join_codegen_and_link
  • controller_entry_point!

phase_1_parse_input

  • hygiene::set_default_edition(sess.edition());
  • parse::parse_crate_from_file(file, &sess.parse_sess) || parse::parse_crate_from_source_str(name.clone(), input.clone(), &sess.parse_sess)

phase_2_configure_and_expand

Run the “early phases” of the compiler: initial cfg processing, loading compiler plugins (including those from addl_plugins), syntax expansion, secondary cfg expansion, synthesis of a test harness if one is to be provided, injection of a dependency on the standard library and prelude, and name resolution.

Returns None if we’re aborting after handling -W help.

Currently, we ignore the name resolution data structures for the purposes of dependency tracking. Instead we will run name resolution and include its output in the hash of each item, much like we do for macro expansion. In other words, the hash reflects not just its contents but the results of name resolution on those contents. Hopefully we’ll push this back at some point.

  • CrateLoader::new(sess, &cstore, &crate_name);
  • Resolver::arenas();
  • phase_2_configure_and_expand_inner(
phase_2_configure_and_expand_inner

Same as phase_2_configure_and_expand, but doesn’t let you keep the resolver around

  • syntax::attr::inject
  • syntax::config::features
  • collect_crate_types
  • compute_crate_disambiguator
  • rustc_incremental::prepare_session_directory
  • rustc_incremental::load_dep_graph
  • middle::recursion_limit::update_limits
  • syntax::std_inject::maybe_inject_crates_ref
  • plugin::load::load_plugins
  • Registry::new
  • registry.register_macro("__diagnostic_used", diagnostics::plugin::expand_diagnostic_used,);
  • registry.register_macro("__register_diagnostic", diagnostics::plugin::expand_register_diagnostic,);
  • registry.register_macro("__build_diagnostic_array", diagnostics::plugin::expand_build_diagnostic_array,;
  • lint::check_ast_crate
  • Resolver::new
  • syntax_ext::register_builtins
  • krate = time(sess, “expansion”, || { … })
  • krate = time(sess, “maybe building test harness”, || { … })
  • ast_validation::check_crate(sess, &krate)
  • after_expand
  • resolver.resolve_crate(&krate)
  • syntax::feature_gate::check_crate
  • lower_crate
  • hir_map::Forest::new
  • lint::check_ast_crate

phase_3_run_analysis_passes

Run the resolution, typechecking, region checking and other miscellaneous analysis passes on the crate. Return various structures carrying the results of the analysis.

  • rustc_incremental::load_query_result_cache
  • ty::query::Providers::default
  • default_provide
  • codegen_backend.provide
  • default_provide_extern
  • codegen_backend.provide_extern
  • TyCtxt::create_and_enter

phase_4_codegen

Run the codegen backend, after which the AST and analysis can be discarded.

  • ::rustc::middle::dependency_format::calculate
  • codegen_backend.codegen_crate

Tags: rust compiler memo

[Memo] Distribute Rustc Flow [Memo] Rustc Parser

comments powered by Disqus