"rustc_lint",
"rustc_metadata",
"rustc_mir",
+ "rustc_parse",
"rustc_plugin",
"rustc_plugin_impl",
+ "rustc_resolve",
"rustc_save_analysis",
"rustc_target",
"serialize",
"rustc_lint",
"rustc_metadata",
"rustc_mir",
+ "rustc_parse",
"rustc_passes",
"rustc_plugin_impl",
"rustc_privacy",
"rustc_data_structures",
"rustc_errors",
"rustc_index",
+ "rustc_parse",
"rustc_target",
"serialize",
"smallvec 1.0.0",
"core",
]
+ [[package]]
+ name = "rustc_parse"
+ version = "0.0.0"
+ dependencies = [
+ "bitflags",
+ "log",
+ "rustc_data_structures",
+ "rustc_errors",
+ "rustc_lexer",
+ "rustc_target",
+ "smallvec 1.0.0",
+ "syntax",
+ "syntax_pos",
+ ]
+
[[package]]
name = "rustc_passes"
version = "0.0.0"
"rustc_data_structures",
"rustc_errors",
"rustc_index",
+ "rustc_parse",
"rustc_target",
"syntax",
"syntax_pos",
"rustc",
"rustc_codegen_utils",
"rustc_data_structures",
+ "rustc_parse",
"serde_json",
"syntax",
"syntax_pos",
name = "syntax_expand"
version = "0.0.0"
dependencies = [
- "bitflags",
- "lazy_static 1.3.0",
"log",
"rustc_data_structures",
"rustc_errors",
- "rustc_index",
"rustc_lexer",
- "scoped-tls",
+ "rustc_parse",
"serialize",
"smallvec 1.0.0",
"syntax",
"log",
"rustc_data_structures",
"rustc_errors",
+ "rustc_parse",
"rustc_target",
"smallvec 1.0.0",
"syntax",
use errors::emitter::{Emitter, EmitterWriter};
use errors::emitter::HumanReadableErrorType;
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
-use syntax::ast::{self, NodeId};
use syntax::edition::Edition;
use syntax::expand::allocator::AllocatorKind;
use syntax::feature_gate::{self, AttributeType};
use syntax::json::JsonEmitter;
use syntax::source_map;
- use syntax::sess::ParseSess;
+ use syntax::sess::{ParseSess, ProcessCfgMod};
use syntax::symbol::Symbol;
use syntax_pos::{MultiSpan, Span};
use crate::util::profiling::{SelfProfiler, SelfProfilerRef};
use ::jobserver::Client;
use std;
-use std::cell::{self, Cell, RefCell};
+use std::cell::{self, RefCell};
use std::env;
use std::fmt;
use std::io::Write;
/// Data about code being compiled, gathered during compilation.
pub code_stats: Lock<CodeStats>,
- next_node_id: OneThread<Cell<ast::NodeId>>,
-
/// If `-zfuel=crate=n` is specified, `Some(crate)`.
optimization_fuel_crate: Option<String>,
self.diagnostic().span_note_without_error(sp, msg)
}
- pub fn reserve_node_ids(&self, count: usize) -> ast::NodeId {
- let id = self.next_node_id.get();
-
- match id.as_usize().checked_add(count) {
- Some(next) => {
- self.next_node_id.set(ast::NodeId::from_usize(next));
- }
- None => bug!("input too large; ran out of node-IDs!"),
- }
-
- id
- }
- pub fn next_node_id(&self) -> NodeId {
- self.reserve_node_ids(1)
- }
pub fn diagnostic(&self) -> &errors::Handler {
&self.parse_sess.span_diagnostic
}
sopts: config::Options,
local_crate_source_file: Option<PathBuf>,
registry: errors::registry::Registry,
+ process_cfg_mod: ProcessCfgMod,
) -> Session {
let file_path_mapping = sopts.file_path_mapping();
Lrc::new(source_map::SourceMap::new(file_path_mapping)),
DiagnosticOutput::Default,
Default::default(),
+ process_cfg_mod,
)
}
source_map: Lrc<source_map::SourceMap>,
diagnostics_output: DiagnosticOutput,
lint_caps: FxHashMap<lint::LintId, lint::Level>,
+ process_cfg_mod: ProcessCfgMod,
) -> 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
},
);
- build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps)
+ build_session_(
+ sopts,
+ local_crate_source_file,
+ diagnostic_handler,
+ source_map,
+ lint_caps,
+ process_cfg_mod,
+ )
}
fn build_session_(
span_diagnostic: errors::Handler,
source_map: Lrc<source_map::SourceMap>,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
+ process_cfg_mod: ProcessCfgMod,
) -> Session {
let self_profiler =
if let SwitchWithOptPath::Enabled(ref d) = sopts.debugging_opts.self_profile {
let parse_sess = ParseSess::with_span_handler(
span_diagnostic,
source_map,
+ process_cfg_mod,
);
let sysroot = match &sopts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
recursion_limit: Once::new(),
type_length_limit: Once::new(),
const_eval_stack_frame_limit: 100,
- next_node_id: OneThread::new(Cell::new(NodeId::from_u32(1))),
allocator_kind: Once::new(),
injected_panic_runtime: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_metadata = { path = "../librustc_metadata" }
rustc_mir = { path = "../librustc_mir" }
+ rustc_parse = { path = "../librustc_parse" }
rustc_plugin = { path = "../librustc_plugin/deprecated" } # To get this in the sysroot
rustc_plugin_impl = { path = "../librustc_plugin" }
rustc_save_analysis = { path = "../librustc_save_analysis" }
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
rustc_interface = { path = "../librustc_interface" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
+rustc_resolve = { path = "../librustc_resolve" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
pub extern crate rustc_plugin_impl as plugin;
-use pretty::{PpMode, UserIdentifiedItem};
-
//use rustc_resolve as resolve;
use rustc_save_analysis as save;
use rustc_save_analysis::DumpHandler;
use syntax::ast;
use syntax::source_map::FileLoader;
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
- use syntax::parse;
use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, FileName};
return sess.compile_status();
}
- let pretty_info = parse_pretty(sess, &matches);
-
compiler.parse()?;
- if let Some((ppm, opt_uii)) = pretty_info {
+ if let Some((ppm, opt_uii)) = &sess.opts.pretty {
if ppm.needs_ast_map(&opt_uii) {
- pretty::visit_crate(sess, &mut compiler.parse()?.peek_mut(), ppm);
compiler.global_ctxt()?.peek_mut().enter(|tcx| {
let expanded_crate = compiler.expansion()?.take().0;
pretty::print_after_hir_lowering(
tcx,
compiler.input(),
&expanded_crate,
- ppm,
+ *ppm,
opt_uii.clone(),
compiler.output_file().as_ref().map(|p| &**p),
);
Ok(())
})?;
} else {
- let mut krate = compiler.parse()?.take();
- pretty::visit_crate(sess, &mut krate, ppm);
+ let krate = compiler.parse()?.take();
pretty::print_after_parsing(
sess,
&compiler.input(),
&krate,
- ppm,
+ *ppm,
compiler.output_file().as_ref().map(|p| &**p),
);
}
}
}
-fn parse_pretty(sess: &Session,
- matches: &getopts::Matches)
- -> Option<(PpMode, Option<UserIdentifiedItem>)> {
- let pretty = if sess.opts.debugging_opts.unstable_options {
- matches.opt_default("pretty", "normal").map(|a| {
- // stable pretty-print variants only
- pretty::parse_pretty(sess, &a, false)
- })
- } else {
- None
- };
-
- if pretty.is_none() {
- sess.opts.debugging_opts.unpretty.as_ref().map(|a| {
- // extended with unstable pretty-print variants
- pretty::parse_pretty(sess, &a, true)
- })
- } else {
- pretty
- }
-}
-
// Whether to stop or continue compilation.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Compilation {
// (unstable option being used on stable)
nightly_options::check_nightly_options(&matches, &config::rustc_optgroups());
- // Late check to see if @file was used without unstable options enabled
- if crate::args::used_unstable_argsfile() && !nightly_options::is_unstable_enabled(&matches) {
- early_error(ErrorOutputType::default(),
- "@path is unstable - use -Z unstable-options to enable its use");
- }
-
if matches.opt_present("h") || matches.opt_present("help") {
// Only show unstable options in --help if we accept unstable options.
usage(matches.opt_present("verbose"), nightly_options::is_unstable_enabled(&matches));
}
fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<ast::Attribute>> {
- match *input {
- Input::File(ref ifile) => {
- parse::parse_crate_attrs_from_file(ifile, &sess.parse_sess)
+ match input {
+ Input::File(ifile) => {
+ rustc_parse::parse_crate_attrs_from_file(ifile, &sess.parse_sess)
}
- Input::Str { ref name, ref input } => {
- parse::parse_crate_attrs_from_source_str(name.clone(),
- input.clone(),
- &sess.parse_sess)
+ Input::Str { name, input } => {
+ rustc_parse::parse_crate_attrs_from_source_str(
+ name.clone(),
+ input.clone(),
+ &sess.parse_sess,
+ )
}
}
}
use rustc::util::common::{time, ErrorReported};
use rustc::session::Session;
use rustc::session::config::{self, CrateType, Input, OutputFilenames, OutputType};
+use rustc::session::config::{PpMode, PpSourceMode};
use rustc::session::search_paths::PathKind;
use rustc_codegen_ssa::back::link::emit_metadata;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_incremental;
use rustc_metadata::cstore;
use rustc_mir as mir;
+ use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
use rustc_passes::{self, ast_validation, hir_stats, layout_test};
use rustc_plugin as plugin;
use rustc_plugin::registry::Registry;
use syntax::early_buffered_lints::BufferedEarlyLint;
use syntax_expand::base::{NamedSyntaxExtension, ExtCtxt};
use syntax::mut_visit::MutVisitor;
- use syntax::parse;
use syntax::util::node_count::NodeCounter;
use syntax::symbol::Symbol;
use syntax_pos::FileName;
let krate = time(sess, "parsing", || {
let _prof_timer = sess.prof.generic_activity("parse_crate");
- match *input {
- Input::File(ref file) => parse::parse_crate_from_file(file, &sess.parse_sess),
- Input::Str {
- ref input,
- ref name,
- } => parse::parse_crate_from_source_str(name.clone(), input.clone(), &sess.parse_sess),
+ match input {
+ Input::File(file) => parse_crate_from_file(file, &sess.parse_sess),
+ Input::Str { input, name } => {
+ parse_crate_from_source_str(name.clone(), input.clone(), &sess.parse_sess)
+ }
}
})?;
)
});
- let (krate, features) = syntax::config::features(
+ let (krate, features) = syntax_expand::config::features(
krate,
&sess.parse_sess,
sess.edition(),
// If we're actually rustdoc then there's no need to actually compile
// anything, so switch everything to just looping
- if sess.opts.actually_rustdoc {
- util::ReplaceBodyWithLoop::new(sess).visit_crate(&mut krate);
+ let mut should_loop = sess.opts.actually_rustdoc;
+ if let Some((PpMode::PpmSource(PpSourceMode::PpmEveryBodyLoops), _)) = sess.opts.pretty {
+ should_loop |= true;
+ }
+ if should_loop {
+ util::ReplaceBodyWithLoop::new(&mut resolver).visit_crate(&mut krate);
}
let has_proc_macro_decls = time(sess, "AST validation", || {
) -> Result<hir::map::Forest> {
// Lower AST to HIR.
let hir_forest = time(sess, "lowering AST -> HIR", || {
- let nt_to_tokenstream = syntax::parse::nt_to_tokenstream;
+ let nt_to_tokenstream = rustc_parse::nt_to_tokenstream;
let hir_crate = lower_crate(sess, &dep_graph, &krate, resolver, nt_to_tokenstream);
if sess.opts.debugging_opts.hir_stats {
use rustc_passes;
use rustc_plugin;
use rustc_privacy;
-use rustc_resolve;
+use rustc_resolve::{self, Resolver};
use rustc_typeck;
use std::env;
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
use syntax::source_map::{FileLoader, RealFileLoader, SourceMap};
use syntax::symbol::{Symbol, sym};
use syntax::{self, ast, attr};
+ use syntax_expand::config::process_configure_mod;
use syntax_pos::edition::Edition;
#[cfg(not(parallel_compiler))]
use std::{thread, panic};
// FIXME: need to figure out a way to get these back in here
// all_errors.extend_from_slice(get_codegen_backend(sess).diagnostics());
all_errors.extend_from_slice(&rustc_metadata::error_codes::DIAGNOSTICS);
+ all_errors.extend_from_slice(&rustc_parse::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_passes::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_plugin::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_mir::error_codes::DIAGNOSTICS);
source_map.clone(),
diagnostic_output,
lint_caps,
+ process_configure_mod,
);
let codegen_backend = get_codegen_backend(&sess);
// ambitious form of the closed RFC #1637. See also [#34511].
//
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
-pub struct ReplaceBodyWithLoop<'a> {
+pub struct ReplaceBodyWithLoop<'a, 'b> {
within_static_or_const: bool,
nested_blocks: Option<Vec<ast::Block>>,
- sess: &'a Session,
+ resolver: &'a mut Resolver<'b>,
}
-impl<'a> ReplaceBodyWithLoop<'a> {
- pub fn new(sess: &'a Session) -> ReplaceBodyWithLoop<'a> {
+impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
+ pub fn new(resolver: &'a mut Resolver<'b>) -> ReplaceBodyWithLoop<'a, 'b> {
ReplaceBodyWithLoop {
within_static_or_const: false,
nested_blocks: None,
- sess
+ resolver,
}
}
}
fn is_sig_const(sig: &ast::FnSig) -> bool {
- sig.header.constness.node == ast::Constness::Const || Self::should_ignore_fn(&sig.decl)
+ sig.header.constness.node == ast::Constness::Const ||
+ ReplaceBodyWithLoop::should_ignore_fn(&sig.decl)
}
}
-impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
+impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
fn visit_item_kind(&mut self, i: &mut ast::ItemKind) {
let is_const = match i {
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true,
fn visit_block(&mut self, b: &mut P<ast::Block>) {
fn stmt_to_block(rules: ast::BlockCheckMode,
s: Option<ast::Stmt>,
- sess: &Session) -> ast::Block {
+ resolver: &mut Resolver<'_>) -> ast::Block {
ast::Block {
stmts: s.into_iter().collect(),
rules,
- id: sess.next_node_id(),
+ id: resolver.next_node_id(),
span: syntax_pos::DUMMY_SP,
}
}
- fn block_to_stmt(b: ast::Block, sess: &Session) -> ast::Stmt {
+ fn block_to_stmt(b: ast::Block, resolver: &mut Resolver<'_>) -> ast::Stmt {
let expr = P(ast::Expr {
- id: sess.next_node_id(),
+ id: resolver.next_node_id(),
kind: ast::ExprKind::Block(P(b), None),
span: syntax_pos::DUMMY_SP,
attrs: ThinVec::new(),
});
ast::Stmt {
- id: sess.next_node_id(),
+ id: resolver.next_node_id(),
kind: ast::StmtKind::Expr(expr),
span: syntax_pos::DUMMY_SP,
}
}
- let empty_block = stmt_to_block(BlockCheckMode::Default, None, self.sess);
+ let empty_block = stmt_to_block(BlockCheckMode::Default, None, self.resolver);
let loop_expr = P(ast::Expr {
kind: ast::ExprKind::Loop(P(empty_block), None),
- id: self.sess.next_node_id(),
+ id: self.resolver.next_node_id(),
span: syntax_pos::DUMMY_SP,
attrs: ThinVec::new(),
});
let loop_stmt = ast::Stmt {
- id: self.sess.next_node_id(),
+ id: self.resolver.next_node_id(),
span: syntax_pos::DUMMY_SP,
kind: ast::StmtKind::Expr(loop_expr),
};
// we put a Some in there earlier with that replace(), so this is valid
let new_blocks = self.nested_blocks.take().unwrap();
self.nested_blocks = old_blocks;
- stmts.extend(new_blocks.into_iter().map(|b| block_to_stmt(b, &self.sess)));
+ stmts.extend(new_blocks.into_iter().map(|b| block_to_stmt(b, self.resolver)));
}
let mut new_block = ast::Block {
old_blocks.push(new_block);
}
- stmt_to_block(b.rules, Some(loop_stmt), self.sess)
+ stmt_to_block(b.rules, Some(loop_stmt), &mut self.resolver)
} else {
//push `loop {}` onto the end of our fresh block and yield that
new_block.stmts.push(loop_stmt);
use rustc::hir::map::definitions::DefPathTable;
use rustc::util::nodemap::DefIdMap;
use rustc_data_structures::svh::Svh;
+ use rustc_parse::source_file_to_stream;
+ use rustc_parse::parser::emit_unclosed_delims;
use smallvec::SmallVec;
use std::any::Any;
use syntax::ast;
use syntax::attr;
use syntax::source_map;
- use syntax::parse::source_file_to_stream;
- use syntax::parse::parser::emit_unclosed_delims;
use syntax::source_map::Spanned;
use syntax::symbol::Symbol;
use syntax_pos::{Span, FileName};
-use rustc_index::bit_set::BitSet;
macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
}
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
- mir_const_qualif => {
- (cdata.mir_const_qualif(def_id.index), tcx.arena.alloc(BitSet::new_empty(0)))
- }
+ mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }