]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_interface/util.rs
Split `rustc_mir::{build, hair, lints}` into their own crate
[rust.git] / src / librustc_interface / util.rs
index 1a2958a0a92c98a26289eb8036249b7a922806a7..2fafd3af7a5ff2d406b1d0386fd95debe2c30110 100644 (file)
@@ -1,8 +1,5 @@
 use log::info;
 use rustc::lint;
-use rustc::session::config::{ErrorOutputType, Input, OutputFilenames};
-use rustc::session::CrateDisambiguator;
-use rustc::session::{self, config, early_error, filesearch, DiagnosticOutput, Session};
 use rustc::ty;
 use rustc_codegen_utils::codegen_backend::CodegenBackend;
 use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_errors::registry::Registry;
 use rustc_metadata::dynamic_lib::DynamicLibrary;
 use rustc_resolve::{self, Resolver};
+use rustc_session as session;
+use rustc_session::config::{ErrorOutputType, Input, OutputFilenames};
+use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
+use rustc_session::CrateDisambiguator;
+use rustc_session::{config, early_error, filesearch, DiagnosticOutput, Session};
+use rustc_span::edition::Edition;
+use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMap};
+use rustc_span::symbol::{sym, Symbol};
 use smallvec::SmallVec;
 use std::env;
 use std::io::{self, Write};
 use syntax::ast::{AttrVec, BlockCheckMode};
 use syntax::mut_visit::{visit_clobber, MutVisitor, *};
 use syntax::ptr::P;
-use syntax::source_map::{FileLoader, RealFileLoader, SourceMap};
-use syntax::symbol::{sym, Symbol};
 use syntax::util::lev_distance::find_best_match_for_name;
 use syntax::{self, ast, attr};
-use syntax_pos::edition::Edition;
 
 /// Adds `target_feature = "..."` cfgs for a variety of platform
 /// specific features (SSE, NEON etc.).
@@ -71,10 +73,6 @@ pub fn create_session(
         lint_caps,
     );
 
-    sess.prof.register_queries(|profiler| {
-        rustc::ty::query::QueryName::register_with_profiler(&profiler);
-    });
-
     let codegen_backend = get_codegen_backend(&sess);
 
     let mut cfg = config::build_configuration(&sess, config::to_crate_config(cfg));
@@ -145,13 +143,15 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
         cfg = cfg.stack_size(size);
     }
 
+    crate::callbacks::setup_callbacks();
+
     scoped_thread(cfg, || {
         syntax::with_globals(edition, || {
             ty::tls::GCX_PTR.set(&Lock::new(0), || {
                 if let Some(stderr) = stderr {
                     io::set_panic(Some(box Sink(stderr.clone())));
                 }
-                ty::tls::with_thread_locals(|| f())
+                f()
             })
         })
     })
@@ -167,6 +167,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
     use rayon::{ThreadBuilder, ThreadPool, ThreadPoolBuilder};
 
     let gcx_ptr = &Lock::new(0);
+    crate::callbacks::setup_callbacks();
 
     let mut config = ThreadPoolBuilder::new()
         .thread_name(|_| "rustc".to_string())
@@ -183,20 +184,18 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
 
     syntax::with_globals(edition, || {
         syntax::GLOBALS.with(|syntax_globals| {
-            syntax_pos::GLOBALS.with(|syntax_pos_globals| {
+            rustc_span::GLOBALS.with(|rustc_span_globals| {
                 // The main handler runs for each Rayon worker thread and sets up
-                // the thread local rustc uses. syntax_globals and syntax_pos_globals are
+                // the thread local rustc uses. syntax_globals and rustc_span_globals are
                 // captured and set on the new threads. ty::tls::with_thread_locals sets up
                 // thread local callbacks from libsyntax
                 let main_handler = move |thread: ThreadBuilder| {
                     syntax::GLOBALS.set(syntax_globals, || {
-                        syntax_pos::GLOBALS.set(syntax_pos_globals, || {
+                        rustc_span::GLOBALS.set(rustc_span_globals, || {
                             if let Some(stderr) = stderr {
                                 io::set_panic(Some(box Sink(stderr.clone())));
                             }
-                            ty::tls::with_thread_locals(|| {
-                                ty::tls::GCX_PTR.set(gcx_ptr, || thread.run())
-                            })
+                            ty::tls::GCX_PTR.set(gcx_ptr, || thread.run())
                         })
                     })
                 };
@@ -423,7 +422,7 @@ pub(crate) fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguat
     CrateDisambiguator::from(hasher.finish::<Fingerprint>())
 }
 
-pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut lint::LintBuffer) {
+pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut LintBuffer) {
     // Unconditionally collect crate types from attributes to make them used
     for a in attrs.iter() {
         if a.check_name(sym::crate_type) {
@@ -445,7 +444,7 @@ pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut
                             ast::CRATE_NODE_ID,
                             span,
                             "invalid `crate_type` value",
-                            lint::builtin::BuiltinLintDiagnostics::UnknownCrateTypes(
+                            BuiltinLintDiagnostics::UnknownCrateTypes(
                                 span,
                                 "did you mean".to_string(),
                                 format!("\"{}\"", candidate),
@@ -717,7 +716,7 @@ fn stmt_to_block(
                 stmts: s.into_iter().collect(),
                 rules,
                 id: resolver.next_node_id(),
-                span: syntax_pos::DUMMY_SP,
+                span: rustc_span::DUMMY_SP,
             }
         }
 
@@ -725,14 +724,14 @@ fn block_to_stmt(b: ast::Block, resolver: &mut Resolver<'_>) -> ast::Stmt {
             let expr = P(ast::Expr {
                 id: resolver.next_node_id(),
                 kind: ast::ExprKind::Block(P(b), None),
-                span: syntax_pos::DUMMY_SP,
+                span: rustc_span::DUMMY_SP,
                 attrs: AttrVec::new(),
             });
 
             ast::Stmt {
                 id: resolver.next_node_id(),
                 kind: ast::StmtKind::Expr(expr),
-                span: syntax_pos::DUMMY_SP,
+                span: rustc_span::DUMMY_SP,
             }
         }
 
@@ -740,13 +739,13 @@ fn block_to_stmt(b: ast::Block, resolver: &mut Resolver<'_>) -> ast::Stmt {
         let loop_expr = P(ast::Expr {
             kind: ast::ExprKind::Loop(P(empty_block), None),
             id: self.resolver.next_node_id(),
-            span: syntax_pos::DUMMY_SP,
+            span: rustc_span::DUMMY_SP,
             attrs: AttrVec::new(),
         });
 
         let loop_stmt = ast::Stmt {
             id: self.resolver.next_node_id(),
-            span: syntax_pos::DUMMY_SP,
+            span: rustc_span::DUMMY_SP,
             kind: ast::StmtKind::Expr(loop_expr),
         };