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

Introduce rustc_interface and move some methods there #58250

Merged
merged 1 commit into from
Feb 28, 2019
Merged
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
31 changes: 31 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,7 @@ dependencies = [
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"rustc_incremental 0.0.0",
"rustc_interface 0.0.0",
"rustc_lint 0.0.0",
"rustc_metadata 0.0.0",
"rustc_mir 0.0.0",
Expand Down Expand Up @@ -2751,6 +2752,36 @@ dependencies = [
"syntax_pos 0.0.0",
]

[[package]]
name = "rustc_interface"
version = "0.0.0"
dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_allocator 0.0.0",
"rustc_borrowck 0.0.0",
"rustc_codegen_utils 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"rustc_incremental 0.0.0",
"rustc_lint 0.0.0",
"rustc_metadata 0.0.0",
"rustc_mir 0.0.0",
"rustc_passes 0.0.0",
"rustc_plugin 0.0.0",
"rustc_privacy 0.0.0",
"rustc_resolve 0.0.0",
"rustc_traits 0.0.0",
"rustc_typeck 0.0.0",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syntax 0.0.0",
"syntax_ext 0.0.0",
"syntax_pos 0.0.0",
]

[[package]]
name = "rustc_lint"
version = "0.0.0"
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ fn main() {
// actually downloaded, so we just always pass the `--sysroot` option.
cmd.arg("--sysroot").arg(&sysroot);

cmd.arg("-Zexternal-macro-backtrace");

// When we build Rust dylibs they're all intended for intermediate
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
// linking all deps statically into the dylib.
Expand Down
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ define_dep_nodes!( <'tcx>
[eval_always] CoherenceInherentImplOverlapCheck,
[] CoherenceCheckTrait(DefId),
[eval_always] PrivacyAccessLevels(CrateNum),
[eval_always] Analysis(CrateNum),

// Represents the MIR for a fn; also used as the task node for
// things read/modify that MIR.
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ impl Input {
Input::Str { ref mut input, .. } => Some(input),
}
}

pub fn source_name(&self) -> FileName {
match *self {
Input::File(ref ifile) => ifile.clone().into(),
Input::Str { ref name, .. } => name.clone(),
}
}
}

#[derive(Clone, Hash)]
Expand Down
109 changes: 66 additions & 43 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,14 +899,14 @@ impl Session {

/// Returns the number of query threads that should be used for this
/// compilation
pub fn threads_from_opts(opts: &config::Options) -> usize {
opts.debugging_opts.threads.unwrap_or(::num_cpus::get())
pub fn threads_from_count(query_threads: Option<usize>) -> usize {
query_threads.unwrap_or(::num_cpus::get())
}

/// Returns the number of query threads that should be used for this
/// compilation
pub fn threads(&self) -> usize {
Self::threads_from_opts(&self.opts)
Self::threads_from_count(self.opts.debugging_opts.threads)
}

/// Returns the number of codegen units that should be used for this
Expand Down Expand Up @@ -1023,16 +1023,67 @@ pub fn build_session(
local_crate_source_file,
registry,
Lrc::new(source_map::SourceMap::new(file_path_mapping)),
None,
DiagnosticOutput::Default,
Default::default(),
)
}

fn default_emitter(
sopts: &config::Options,
registry: errors::registry::Registry,
source_map: &Lrc<source_map::SourceMap>,
emitter_dest: Option<Box<dyn Write + Send>>,
) -> Box<dyn Emitter + sync::Send> {
match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(color_config), None) => Box::new(
EmitterWriter::stderr(
color_config,
Some(source_map.clone()),
false,
sopts.debugging_opts.teach,
).ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => Box::new(
EmitterWriter::new(dst, Some(source_map.clone()), false, false)
.ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Json(pretty), None) => Box::new(
JsonEmitter::stderr(
Some(registry),
source_map.clone(),
pretty,
).ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Json(pretty), Some(dst)) => Box::new(
JsonEmitter::new(
dst,
Some(registry),
source_map.clone(),
pretty,
).ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Short(color_config), None) => Box::new(
EmitterWriter::stderr(color_config, Some(source_map.clone()), true, false),
),
(config::ErrorOutputType::Short(_), Some(dst)) => {
Box::new(EmitterWriter::new(dst, Some(source_map.clone()), true, false))
}
}
}

pub enum DiagnosticOutput {
Default,
Raw(Box<dyn Write + Send>),
Emitter(Box<dyn Emitter + Send + sync::Send>)
}

pub fn build_session_with_source_map(
sopts: config::Options,
local_crate_source_file: Option<PathBuf>,
registry: errors::registry::Registry,
source_map: Lrc<source_map::SourceMap>,
emitter_dest: Option<Box<dyn Write + Send>>,
diagnostics_output: DiagnosticOutput,
lint_caps: FxHashMap<lint::LintId, lint::Level>,
) -> Session {
// FIXME: This is not general enough to make the warning lint completely override
// normal diagnostic warnings, since the warning lint can also be denied and changed
Expand All @@ -1054,42 +1105,13 @@ pub fn build_session_with_source_map(

let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;

let emitter: Box<dyn Emitter + sync::Send> =
match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(color_config), None) => Box::new(
EmitterWriter::stderr(
color_config,
Some(source_map.clone()),
false,
sopts.debugging_opts.teach,
).ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => Box::new(
EmitterWriter::new(dst, Some(source_map.clone()), false, false)
.ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Json(pretty), None) => Box::new(
JsonEmitter::stderr(
Some(registry),
source_map.clone(),
pretty,
).ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Json(pretty), Some(dst)) => Box::new(
JsonEmitter::new(
dst,
Some(registry),
source_map.clone(),
pretty,
).ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Short(color_config), None) => Box::new(
EmitterWriter::stderr(color_config, Some(source_map.clone()), true, false),
),
(config::ErrorOutputType::Short(_), Some(dst)) => {
Box::new(EmitterWriter::new(dst, Some(source_map.clone()), true, false))
}
};
let emitter = match diagnostics_output {
DiagnosticOutput::Default => default_emitter(&sopts, registry, &source_map, None),
DiagnosticOutput::Raw(write) => {
default_emitter(&sopts, registry, &source_map, Some(write))
}
DiagnosticOutput::Emitter(emitter) => emitter,
};

let diagnostic_handler = errors::Handler::with_emitter_and_flags(
emitter,
Expand All @@ -1103,14 +1125,15 @@ pub fn build_session_with_source_map(
},
);

build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map)
build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps)
}

pub fn build_session_(
sopts: config::Options,
local_crate_source_file: Option<PathBuf>,
span_diagnostic: errors::Handler,
source_map: Lrc<source_map::SourceMap>,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
) -> Session {
let host_triple = TargetTriple::from_triple(config::host_triple());
let host = Target::search(&host_triple).unwrap_or_else(|e|
Expand Down Expand Up @@ -1235,7 +1258,7 @@ pub fn build_session_(
},
has_global_allocator: Once::new(),
has_panic_handler: Once::new(),
driver_lint_caps: Default::default(),
driver_lint_caps,
};

validate_commandline_args_with_session_available(&sess);
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
StableVec};
use arena::{TypedArena, SyncDroplessArena};
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::sync::{self, Lrc, Lock, WorkerLocal};
use rustc_data_structures::sync::{Lrc, Lock, WorkerLocal};
use std::any::Any;
use std::borrow::Borrow;
use std::cmp::Ordering;
Expand Down Expand Up @@ -1285,8 +1285,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

let gcx = arenas.global_ctxt.as_ref().unwrap();

sync::assert_send_val(&gcx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And/or why was this there at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was there after we modified GlobalCtxt to be Sync, but didn't yet actually share it across threads.


let r = tls::enter_global(gcx, f);

gcx.queries.record_computed_queries(s);
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::extern_crate<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::analysis<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"running analysis passes on this crate".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"computing the lint levels for items in this crate".into()
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::mir::interpret::{ConstEvalRawResult, ConstEvalResult};
use crate::mir::mono::CodegenUnit;
use crate::mir;
use crate::mir::interpret::GlobalId;
use crate::session::{CompileResult, CrateDisambiguator};
use crate::session::CrateDisambiguator;
use crate::session::config::{EntryFnType, OutputFilenames, OptLevel};
use crate::traits::{self, Vtable};
use crate::traits::query::{
Expand Down Expand Up @@ -99,6 +99,9 @@ pub use self::on_disk_cache::OnDiskCache;
// as they will raise an fatal error on query cycles instead.
define_queries! { <'tcx>
Other {
/// Run analysis passes on the crate
[] fn analysis: Analysis(CrateNum) -> Result<(), ErrorReported>,

/// Records the type of every item.
[] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,

Expand Down Expand Up @@ -290,7 +293,8 @@ define_queries! { <'tcx>
},

TypeChecking {
[] fn typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult,
[] fn typeck_item_bodies:
typeck_item_bodies_dep_node(CrateNum) -> Result<(), ErrorReported>,

[] fn typeck_tables_of: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
},
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::CrateHash => { force!(crate_hash, krate!()); }
DepKind::OriginalCrateName => { force!(original_crate_name, krate!()); }
DepKind::ExtraFileName => { force!(extra_filename, krate!()); }
DepKind::Analysis => { force!(analysis, krate!()); }

DepKind::AllTraitImplementations => {
force!(all_trait_implementations, krate!());
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rustc_save_analysis = { path = "../librustc_save_analysis" }
rustc_traits = { path = "../librustc_traits" }
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
rustc_typeck = { path = "../librustc_typeck" }
rustc_interface = { path = "../librustc_interface" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
Expand Down
Loading