Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[driver breaking] Rename rustc_trans to rustc_codegen_llvm and allow runtime switching between trans backends #45677

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/doc/rustc-ux-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ for details on how to format and write long error codes.
[librustc_passes](https://github.com/rust-lang/rust/blob/master/src/librustc_passes/diagnostics.rs),
[librustc_privacy](https://github.com/rust-lang/rust/blob/master/src/librustc_privacy/diagnostics.rs),
[librustc_resolve](https://github.com/rust-lang/rust/blob/master/src/librustc_resolve/diagnostics.rs),
[librustc_trans](https://github.com/rust-lang/rust/blob/master/src/librustc_trans/diagnostics.rs),
[librustc_codegen_llvm](https://github.com/rust-lang/rust/blob/master/src/librustc_codegen_llvm/diagnostics.rs),
[librustc_plugin](https://github.com/rust-lang/rust/blob/master/src/librustc_plugin/diagnostics.rs),
[librustc_typeck](https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/diagnostics.rs).
* Explanations have full markdown support. Use it, especially to highlight
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! rustc compiler intrinsics.
//!
//! The corresponding definitions are in librustc_trans/intrinsic.rs.
//! The corresponding definitions are in librustc_codegen_llvm/intrinsic.rs.
//!
//! # Volatiles
//!
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ syntax_pos = { path = "../libsyntax_pos" }
# rlib/dylib pair but all crates.io crates tend to just be rlibs. This means
# we've got a problem for dependency graphs that look like:
#
# foo - rustc_trans
# / \
# rustc ---- rustc_driver
# foo - rustc_codegen_llvm
# / \
# rustc ----- rustc_driver
# \ /
# foo - rustc_metadata
#
# Here the crate `foo` is linked into the `rustc_trans` and the
# Here the crate `foo` is linked into the `rustc_codegen_llvm` and the
# `rustc_metadata` dylibs, meaning we've got duplicate copies! When we then
# go to link `rustc_driver` the compiler notices this and gives us a compiler
# error.
#
# To work around this problem we just add these crates.io dependencies to the
# `rustc` crate which is a shared dependency above. That way the crate `foo`
# shows up in the dylib for the `rustc` crate, deduplicating it and allowing
# crates like `rustc_trans` to use `foo` *through* the `rustc` crate.
# crates like `rustc_codegen_llvm` to use `foo` *through* the `rustc` crate.
#
# tl;dr; this is not needed to get `rustc` to compile, but if you remove it then
# later crate stop compiling. If you can remove this and everything
Expand Down
36 changes: 18 additions & 18 deletions src/librustc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The crates of rustc
===================

Rustc consists of a number of crates, including `syntax`,
`rustc`, `rustc_back`, `rustc_trans`, `rustc_driver`, and
`rustc`, `rustc_back`, `rustc_codegen_llvm`, `rustc_driver`, and
many more. The source for each crate can be found in a directory
like `src/libXXX`, where `XXX` is the crate name.

Expand All @@ -38,23 +38,23 @@ incremental improves that may change.)
The dependency structure of these crates is roughly a diamond:

```
rustc_driver
/ | \
/ | \
/ | \
/ v \
rustc_trans rustc_borrowck ... rustc_metadata
\ | /
\ | /
\ | /
\ v /
rustc
|
v
syntax
/ \
/ \
syntax_pos syntax_ext
rustc_driver
/ | \
/ | \
/ | \
/ v \
rustc_codegen_llvm rustc_borrowck ... rustc_metadata
\ | /
\ | /
\ | /
\ v /
rustc
|
v
syntax
/ \
/ \
syntax_pos syntax_ext
```

The `rustc_driver` crate, at the top of this lattice, is effectively
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
build_debugging_options, "Z", "debugging",
DB_OPTIONS, db_type_desc, dbsetters,
trans: Option<String> = (None, parse_opt_string, [TRACKED],
"the backend to use"),
verbose: bool = (false, parse_bool, [UNTRACKED],
"in general, enable more debug printouts"),
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn profq_msg(msg: ProfileQueriesMsg) {
// Do nothing.
//
// FIXME(matthewhammer): Multi-threaded translation phase triggers the panic below.
// From backtrace: rustc_trans::back::write::spawn_work::{{closure}}.
// From backtrace: rustc_codegen_llvm::back::write::spawn_work::{{closure}}.
//
// panic!("no channel on which to send profq_msg: {:?}", msg)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
authors = ["The Rust Project Developers"]
name = "rustc_trans"
name = "rustc_codegen_llvm"
version = "0.0.0"

[lib]
name = "rustc_trans"
name = "rustc_codegen_llvm"
path = "lib.rs"
crate-type = ["dylib"]
test = false
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn get_simple_intrinsic(ccx: &CrateContext, name: &str) -> Option<ValueRef> {

/// Remember to add all intrinsics here, in librustc_typeck/check/mod.rs,
/// and in libcore/intrinsics.rs; if you need access to any llvm intrinsics,
/// add them to librustc_trans/trans/context.rs
/// add them to librustc_codegen_llvm/trans/context.rs
pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
callee_ty: Ty<'tcx>,
fn_ty: &FnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub struct CrateInfo {
used_crates_dynamic: Vec<(CrateNum, LibSource)>,
}

__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }
__build_diagnostic_array! { librustc_codegen_llvm, DIAGNOSTICS }

pub fn provide_local(providers: &mut Providers) {
back::symbol_names::provide(providers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn print(req: PrintRequest, sess: &Session) {
match req {
PrintRequest::TargetCPUs => llvm::LLVMRustPrintTargetCPUs(tm),
PrintRequest::TargetFeatures => llvm::LLVMRustPrintTargetFeatures(tm),
_ => bug!("rustc_trans can't handle print request: {:?}", req),
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/librustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rustc_plugin = { path = "../librustc_plugin" }
rustc_privacy = { path = "../librustc_privacy" }
rustc_resolve = { path = "../librustc_resolve" }
rustc_save_analysis = { path = "../librustc_save_analysis" }
rustc_trans = { path = "../librustc_trans", optional = true }
rustc_codegen_llvm = { path = "../librustc_codegen_llvm", optional = true }
rustc_trans_utils = { path = "../librustc_trans_utils" }
rustc_typeck = { path = "../librustc_typeck" }
serialize = { path = "../libserialize" }
Expand All @@ -41,4 +41,4 @@ syntax_pos = { path = "../libsyntax_pos" }
ar = "0.3.0"

[features]
llvm = ["rustc_trans"]
llvm = ["rustc_codegen_llvm"]
44 changes: 13 additions & 31 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use rustc_incremental;
use rustc_resolve::{MakeGlobMap, Resolver};
use rustc_metadata::creader::CrateLoader;
use rustc_metadata::cstore::{self, CStore};
use rustc_trans as trans;
use rustc_trans_utils::trans_crate::TransCrate;
use rustc_typeck as typeck;
use rustc_privacy;
Expand All @@ -41,7 +40,6 @@ use rustc_plugin as plugin;
use rustc_passes::{self, ast_validation, no_asm, loops, consts, static_recursion, hir_stats};
use rustc_const_eval::{self, check_match};
use super::Compilation;
use ::DefaultTransCrate;

use serialize::json;

Expand All @@ -67,7 +65,7 @@ use derive_registrar;

use profile;

pub fn compile_input(sess: &Session,
pub fn compile_input<Trans: TransCrate>(sess: &Session,
cstore: &CStore,
input: &Input,
outdir: &Option<PathBuf>,
Expand Down Expand Up @@ -207,7 +205,7 @@ pub fn compile_input(sess: &Session,
None
};

phase_3_run_analysis_passes(sess,
phase_3_run_analysis_passes::<Trans, _, _>(sess,
cstore,
hir_map,
analysis,
Expand Down Expand Up @@ -244,7 +242,7 @@ pub fn compile_input(sess: &Session,
tcx.print_debug_stats();
}

let trans = phase_4_translate_to_llvm::<DefaultTransCrate>(tcx, rx);
let trans = phase_4_translate_to_llvm::<Trans>(tcx, rx);

if log_enabled!(::log::LogLevel::Info) {
println!("Post-trans");
Expand All @@ -267,18 +265,19 @@ pub fn compile_input(sess: &Session,
}

let (phase5_result, trans) =
phase_5_run_llvm_passes::<DefaultTransCrate>(sess, &dep_graph, trans);
phase_5_run_llvm_passes::<Trans>(sess, &dep_graph, trans);

controller_entry_point!(after_llvm,
sess,
CompileState::state_after_llvm(input, sess, outdir, output, &trans),
phase5_result);
phase5_result?;

if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe ||
i == OutputType::Metadata) {
return Ok(());
}

// Run the linker on any artifacts that resulted from the LLVM run.
// This should produce either a finished executable or library.
time(sess.time_passes(), "linking", || {
DefaultTransCrate::link_binary(sess, &trans, &outputs)
Trans::link_binary(sess, &trans, &outputs)
});

// Now that we won't touch anything in the incremental compilation directory
Expand Down Expand Up @@ -338,7 +337,6 @@ pub struct CompileController<'a> {
pub after_expand: PhaseController<'a>,
pub after_hir_lowering: PhaseController<'a>,
pub after_analysis: PhaseController<'a>,
pub after_llvm: PhaseController<'a>,
pub compilation_done: PhaseController<'a>,

// FIXME we probably want to group the below options together and offer a
Expand All @@ -357,7 +355,6 @@ impl<'a> CompileController<'a> {
after_expand: PhaseController::basic(),
after_hir_lowering: PhaseController::basic(),
after_analysis: PhaseController::basic(),
after_llvm: PhaseController::basic(),
compilation_done: PhaseController::basic(),
make_glob_map: MakeGlobMap::No,
keep_ast: false,
Expand Down Expand Up @@ -405,7 +402,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
pub resolutions: Option<&'a Resolutions>,
pub analysis: Option<&'a ty::CrateAnalysis>,
pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
pub trans: Option<&'a trans::CrateTranslation>,
}

impl<'a, 'tcx> CompileState<'a, 'tcx> {
Expand All @@ -431,7 +427,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
resolutions: None,
analysis: None,
tcx: None,
trans: None,
}
}

Expand Down Expand Up @@ -521,19 +516,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
}
}

fn state_after_llvm(input: &'a Input,
session: &'tcx Session,
out_dir: &'a Option<PathBuf>,
out_file: &'a Option<PathBuf>,
trans: &'a trans::CrateTranslation)
-> Self {
CompileState {
trans: Some(trans),
out_file: out_file.as_ref().map(|s| &**s),
..CompileState::empty(input, session, out_dir)
}
}

fn state_when_compilation_done(input: &'a Input,
session: &'tcx Session,
out_dir: &'a Option<PathBuf>,
Expand Down Expand Up @@ -910,7 +892,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
/// Run the resolution, typechecking, region checking and other
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
pub fn phase_3_run_analysis_passes<'tcx, Trans: TransCrate, F, R>(sess: &'tcx Session,
cstore: &'tcx CrateStore,
hir_map: hir_map::Map<'tcx>,
mut analysis: ty::CrateAnalysis,
Expand Down Expand Up @@ -966,7 +948,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
mir::provide(&mut local_providers);
reachable::provide(&mut local_providers);
rustc_privacy::provide(&mut local_providers);
DefaultTransCrate::provide_local(&mut local_providers);
Trans::provide_local(&mut local_providers);
typeck::provide(&mut local_providers);
ty::provide(&mut local_providers);
traits::provide(&mut local_providers);
Expand All @@ -979,7 +961,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,

let mut extern_providers = ty::maps::Providers::default();
cstore::provide(&mut extern_providers);
DefaultTransCrate::provide_extern(&mut extern_providers);
Trans::provide_extern(&mut extern_providers);
ty::provide_extern(&mut extern_providers);
traits::provide_extern(&mut extern_providers);
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
Expand Down
Loading