Skip to content
Permalink
Browse files

Make the rustc driver and interface demand driven

  • Loading branch information...
Zoxc committed Dec 8, 2018
1 parent 26b4cb4 commit 51938c61f6f1b26e463f9071716f543543486e72
Showing with 2,511 additions and 2,745 deletions.
  1. +0 −5 src/librustc/ich/impls_ty.rs
  2. +26 −10 src/librustc/session/config.rs
  3. +4 −14 src/librustc/session/mod.rs
  4. +37 −50 src/librustc/ty/context.rs
  5. +1 −1 src/librustc/ty/mod.rs
  6. +3 −2 src/librustc_codegen_llvm/lib.rs
  7. +4 −3 src/librustc_codegen_utils/codegen_backend.rs
  8. +172 −0 src/librustc_data_structures/box_region.rs
  9. +3 −0 src/librustc_data_structures/lib.rs
  10. +0 −1,244 src/librustc_driver/driver.rs
  11. +265 −464 src/librustc_driver/lib.rs
  12. +107 −166 src/librustc_driver/pretty.rs
  13. +43 −99 src/librustc_driver/test.rs
  14. +1 −1 src/librustc_incremental/lib.rs
  15. +3 −3 src/librustc_incremental/persist/load.rs
  16. +1 −1 src/librustc_incremental/persist/mod.rs
  17. +155 −0 src/librustc_interface/interface.rs
  18. +8 −3 src/librustc_interface/lib.rs
  19. +744 −12 src/librustc_interface/passes.rs
  20. +302 −0 src/librustc_interface/queries.rs
  21. +158 −1 src/librustc_interface/util.rs
  22. +4 −4 src/librustdoc/clean/auto_trait.rs
  23. +4 −4 src/librustdoc/clean/blanket_impl.rs
  24. +2 −2 src/librustdoc/clean/def_ctor.rs
  25. +19 −19 src/librustdoc/clean/inline.rs
  26. +107 −107 src/librustdoc/clean/mod.rs
  27. +2 −2 src/librustdoc/clean/simplify.rs
  28. +1 −1 src/librustdoc/config.rs
  29. +76 −131 src/librustdoc/core.rs
  30. +5 −6 src/librustdoc/lib.rs
  31. +2 −2 src/librustdoc/markdown.rs
  32. +1 −1 src/librustdoc/passes/calculate_doc_coverage.rs
  33. +5 −5 src/librustdoc/passes/check_code_block_syntax.rs
  34. +1 −1 src/librustdoc/passes/collapse_docs.rs
  35. +30 −32 src/librustdoc/passes/collect_intra_doc_links.rs
  36. +6 −6 src/librustdoc/passes/collect_trait_impls.rs
  37. +4 −4 src/librustdoc/passes/mod.rs
  38. +6 −6 src/librustdoc/passes/private_items_doc_tests.rs
  39. +1 −1 src/librustdoc/passes/propagate_doc_cfg.rs
  40. +1 −1 src/librustdoc/passes/strip_hidden.rs
  41. +1 −1 src/librustdoc/passes/strip_priv_imports.rs
  42. +1 −1 src/librustdoc/passes/strip_private.rs
  43. +1 −1 src/librustdoc/passes/unindent_comments.rs
  44. +122 −172 src/librustdoc/test.rs
  45. +6 −6 src/librustdoc/visit_ast.rs
  46. +5 −5 src/librustdoc/visit_lib.rs
  47. +0 −11 src/rustc/rustc.rs
  48. +3 −2 src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs
  49. +29 −45 src/test/run-make-fulldeps/issue-19371/foo.rs
  50. +10 −71 src/test/run-pass-fulldeps/compiler-calls.rs
  51. +2 −0 src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr
  52. +1 −1 src/test/rustdoc-ui/deny-missing-docs-crate.stderr
  53. +1 −1 src/test/rustdoc-ui/deny-missing-docs-macro.stderr
  54. +2 −0 src/test/rustdoc-ui/doc-without-codeblock.stderr
  55. +5 −2 src/test/rustdoc-ui/failed-doctest-output.stdout
  56. +2 −0 src/test/rustdoc-ui/intra-doc-alias-ice.stderr
  57. +2 −0 src/test/rustdoc-ui/intra-link-span-ice-55723.stderr
  58. +2 −0 src/test/rustdoc-ui/lint-group.stderr
  59. +2 −0 src/test/rustdoc-ui/private-item-doc-test.stderr
  60. +0 −12 src/tools/rustdoc/main.rs
@@ -946,11 +946,6 @@ impl_stable_hash_for!(struct ty::CrateInherentImpls {
inherent_impls
});

impl_stable_hash_for!(enum crate::session::CompileIncomplete {
Stopped,
Errored(error_reported)
});

impl_stable_hash_for!(struct crate::util::common::ErrorReported {});

impl_stable_hash_for!(tuple_struct crate::middle::reachable::ReachableSet {
@@ -11,6 +11,7 @@ use rustc_target::spec::{Target, TargetTriple};
use crate::lint;
use crate::middle::cstore;

use syntax;
use syntax::ast::{self, IntTy, UintTy, MetaItemKind};
use syntax::source_map::{FileName, FilePathMapping};
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
@@ -1494,6 +1495,15 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
ret
}

/// Converts the crate cfg! configuration from String to Symbol.
/// `rustc_interface::interface::Config` accepts this in the compiler configuration,
/// but the symbol interner is not yet set up then, so we must convert it later.
pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> ast::CrateConfig {
cfg.into_iter()
.map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b))))
.collect()
}

pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> ast::CrateConfig {
// Combine the configuration requested by the session (command line) with
// some default and generated configuration items
@@ -1800,10 +1810,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
}

// Convert strings provided as --cfg [cfgspec] into a crate_cfg
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
cfgspecs
.into_iter()
.map(|s| {
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
syntax::with_globals(move || {
let cfg = cfgspecs.into_iter().map(|s| {
let sess = parse::ParseSess::new(FilePathMapping::empty());
let filename = FileName::cfg_spec_source_code(&s);
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
@@ -1835,8 +1844,11 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
}

error!(r#"expected `key` or `key="value"`"#);
})
.collect::<ast::CrateConfig>()
}).collect::<ast::CrateConfig>();
cfg.into_iter().map(|(a, b)| {
(a.to_string(), b.map(|b| b.to_string()))
}).collect()
})
}

pub fn get_cmd_lint_options(matches: &getopts::Matches,
@@ -1864,7 +1876,7 @@ pub fn get_cmd_lint_options(matches: &getopts::Matches,

pub fn build_session_options_and_crate_config(
matches: &getopts::Matches,
) -> (Options, ast::CrateConfig) {
) -> (Options, FxHashSet<(String, Option<String>)>) {
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
Some("auto") => ColorConfig::Auto,
Some("always") => ColorConfig::Always,
@@ -2590,7 +2602,11 @@ mod tests {
use getopts;
use crate::lint;
use crate::middle::cstore;
use crate::session::config::{build_configuration, build_session_options_and_crate_config};
use crate::session::config::{
build_configuration,
build_session_options_and_crate_config,
to_crate_config
};
use crate::session::config::{LtoCli, LinkerPluginLto};
use crate::session::build_session;
use crate::session::search_paths::SearchPath;
@@ -2631,7 +2647,7 @@ mod tests {
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
let cfg = build_configuration(&sess, to_crate_config(cfg));
assert!(cfg.contains(&(Symbol::intern("test"), None)));
});
}
@@ -2649,7 +2665,7 @@ mod tests {
let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let cfg = build_configuration(&sess, cfg);
let cfg = build_configuration(&sess, to_crate_config(cfg));
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
assert!(test_items.next().is_some());
assert!(test_items.next().is_none());
@@ -311,7 +311,7 @@ impl Session {
pub fn abort_if_errors(&self) {
self.diagnostic().abort_if_errors();
}
pub fn compile_status(&self) -> Result<(), CompileIncomplete> {
pub fn compile_status(&self) -> Result<(), ErrorReported> {
compile_result_from_err_count(self.err_count())
}
pub fn track_errors<F, T>(&self, f: F) -> Result<T, ErrorReported>
@@ -1124,7 +1124,7 @@ pub fn build_session_with_source_map(
build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps)
}

pub fn build_session_(
fn build_session_(
sopts: config::Options,
local_crate_source_file: Option<PathBuf>,
span_diagnostic: errors::Handler,
@@ -1334,22 +1334,12 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
}

#[derive(Copy, Clone, Debug)]
pub enum CompileIncomplete {
Stopped,
Errored(ErrorReported),
}
impl From<ErrorReported> for CompileIncomplete {
fn from(err: ErrorReported) -> CompileIncomplete {
CompileIncomplete::Errored(err)
}
}
pub type CompileResult = Result<(), CompileIncomplete>;
pub type CompileResult = Result<(), ErrorReported>;

pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
if err_count == 0 {
Ok(())
} else {
Err(CompileIncomplete::Errored(ErrorReported))
Err(ErrorReported)
}
}
@@ -78,15 +78,13 @@ use crate::hir;
pub struct AllArenas<'tcx> {
pub global: WorkerLocal<GlobalArenas<'tcx>>,
pub interner: SyncDroplessArena,
global_ctxt: Option<GlobalCtxt<'tcx>>,
}

impl<'tcx> AllArenas<'tcx> {
pub fn new() -> Self {
AllArenas {
global: WorkerLocal::new(|_| GlobalArenas::default()),
interner: SyncDroplessArena::default(),
global_ctxt: None,
}
}
}
@@ -1182,20 +1180,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// to the context. The closure enforces that the type context and any interned
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
/// reference to the context, to allow formatting values that need it.
pub fn create_and_enter<F, R>(s: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
local_providers: ty::query::Providers<'tcx>,
extern_providers: ty::query::Providers<'tcx>,
arenas: &'tcx mut AllArenas<'tcx>,
resolutions: ty::Resolutions,
hir: hir_map::Map<'tcx>,
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
crate_name: &str,
tx: mpsc::Sender<Box<dyn Any + Send>>,
output_filenames: &OutputFilenames,
f: F) -> R
where F: for<'b> FnOnce(TyCtxt<'b, 'tcx, 'tcx>) -> R
{
pub fn create_global_ctxt(
s: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
local_providers: ty::query::Providers<'tcx>,
extern_providers: ty::query::Providers<'tcx>,
arenas: &'tcx AllArenas<'tcx>,
resolutions: ty::Resolutions,
hir: hir_map::Map<'tcx>,
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
crate_name: &str,
tx: mpsc::Sender<Box<dyn Any + Send>>,
output_filenames: &OutputFilenames,
) -> GlobalCtxt<'tcx> {
let data_layout = TargetDataLayout::parse(&s.target.target).unwrap_or_else(|err| {
s.fatal(&err);
});
@@ -1247,7 +1244,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
Lrc::new(StableVec::new(v)));
}

arenas.global_ctxt = Some(GlobalCtxt {
GlobalCtxt {
sess: s,
cstore,
global_arenas: &arenas.global,
@@ -1293,15 +1290,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
alloc_map: Lock::new(interpret::AllocMap::new()),
tx_to_llvm_workers: Lock::new(tx),
output_filenames: Arc::new(output_filenames.clone()),
});

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

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

gcx.queries.record_computed_queries(s);

r
}
}

pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
@@ -1985,31 +1974,29 @@ pub mod tls {
pub fn enter_global<'gcx, F, R>(gcx: &'gcx GlobalCtxt<'gcx>, f: F) -> R
where F: FnOnce(TyCtxt<'gcx, 'gcx, 'gcx>) -> R
{
with_thread_locals(|| {
// Update GCX_PTR to indicate there's a GlobalCtxt available
GCX_PTR.with(|lock| {
*lock.lock() = gcx as *const _ as usize;
});
// Set GCX_PTR back to 0 when we exit
let _on_drop = OnDrop(move || {
GCX_PTR.with(|lock| *lock.lock() = 0);
});
// Update GCX_PTR to indicate there's a GlobalCtxt available
GCX_PTR.with(|lock| {
*lock.lock() = gcx as *const _ as usize;
});
// Set GCX_PTR back to 0 when we exit
let _on_drop = OnDrop(move || {
GCX_PTR.with(|lock| *lock.lock() = 0);
});

let tcx = TyCtxt {
gcx,
interners: &gcx.global_interners,
dummy: PhantomData,
};
let icx = ImplicitCtxt {
tcx,
query: None,
diagnostics: None,
layout_depth: 0,
task_deps: None,
};
enter_context(&icx, |_| {
f(tcx)
})
let tcx = TyCtxt {
gcx,
interners: &gcx.global_interners,
dummy: PhantomData,
};
let icx = ImplicitCtxt {
tcx,
query: None,
diagnostics: None,
layout_depth: 0,
task_deps: None,
};
enter_context(&icx, |_| {
f(tcx)
})
}

@@ -71,7 +71,7 @@ pub use self::binding::BindingMode;
pub use self::binding::BindingMode::*;

pub use self::context::{TyCtxt, FreeRegionInfo, GlobalArenas, AllArenas, tls, keep_local};
pub use self::context::{Lift, TypeckTables, CtxtInterners};
pub use self::context::{Lift, TypeckTables, CtxtInterners, GlobalCtxt};
pub use self::context::{
UserTypeAnnotationIndex, UserType, CanonicalUserType,
CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
@@ -63,11 +63,12 @@ use std::sync::{mpsc, Arc};
use rustc::dep_graph::DepGraph;
use rustc::middle::allocator::AllocatorKind;
use rustc::middle::cstore::{EncodedMetadata, MetadataLoader};
use rustc::session::{Session, CompileIncomplete};
use rustc::session::Session;
use rustc::session::config::{OutputFilenames, OutputType, PrintRequest, OptLevel};
use rustc::ty::{self, TyCtxt};
use rustc::util::time_graph;
use rustc::util::profiling::ProfileCategory;
use rustc::util::common::ErrorReported;
use rustc_mir::monomorphize;
use rustc_codegen_ssa::ModuleCodegen;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
@@ -311,7 +312,7 @@ impl CodegenBackend for LlvmCodegenBackend {
sess: &Session,
dep_graph: &DepGraph,
outputs: &OutputFilenames,
) -> Result<(), CompileIncomplete>{
) -> Result<(), ErrorReported>{
use rustc::util::common::time;
let (codegen_results, work_products) =
ongoing_codegen.downcast::
@@ -21,7 +21,8 @@ use flate2::write::DeflateEncoder;

use syntax::symbol::Symbol;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::session::{Session, CompileIncomplete};
use rustc::session::Session;
use rustc::util::common::ErrorReported;
use rustc::session::config::{CrateType, OutputFilenames, PrintRequest};
use rustc::ty::TyCtxt;
use rustc::ty::query::Providers;
@@ -61,7 +62,7 @@ pub trait CodegenBackend {
sess: &Session,
dep_graph: &DepGraph,
outputs: &OutputFilenames,
) -> Result<(), CompileIncomplete>;
) -> Result<(), ErrorReported>;
}

pub struct NoLlvmMetadataLoader;
@@ -163,7 +164,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
sess: &Session,
_dep_graph: &DepGraph,
outputs: &OutputFilenames,
) -> Result<(), CompileIncomplete> {
) -> Result<(), ErrorReported> {
let ongoing_codegen = ongoing_codegen.downcast::<OngoingCodegen>()
.expect("Expected MetadataOnlyCodegenBackend's OngoingCodegen, found Box<dyn Any>");
for &crate_type in sess.opts.crate_types.iter() {
Oops, something went wrong.

0 comments on commit 51938c6

Please sign in to comment.
You can’t perform that action at this time.