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

Split libsyntax apart #65324

Merged
merged 3 commits into from
Nov 10, 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
26 changes: 22 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3504,6 +3504,7 @@ dependencies = [
"rustc_lint",
"rustc_metadata",
"rustc_mir",
"rustc_parse",
"rustc_plugin",
"rustc_plugin_impl",
"rustc_save_analysis",
Expand Down Expand Up @@ -3571,6 +3572,7 @@ dependencies = [
"rustc_lint",
"rustc_metadata",
"rustc_mir",
"rustc_parse",
"rustc_passes",
"rustc_plugin_impl",
"rustc_privacy",
Expand Down Expand Up @@ -3648,6 +3650,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_index",
"rustc_parse",
"rustc_target",
"serialize",
"smallvec 1.0.0",
Expand Down Expand Up @@ -3691,6 +3694,21 @@ dependencies = [
"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"
Expand All @@ -3700,6 +3718,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_index",
"rustc_parse",
"rustc_target",
"syntax",
"syntax_pos",
Expand Down Expand Up @@ -3762,6 +3781,7 @@ dependencies = [
"rustc",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_parse",
"serde_json",
"syntax",
"syntax_pos",
Expand Down Expand Up @@ -4371,14 +4391,11 @@ dependencies = [
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",
Expand All @@ -4393,6 +4410,7 @@ dependencies = [
"log",
"rustc_data_structures",
"rustc_errors",
"rustc_parse",
"rustc_target",
"smallvec 1.0.0",
"syntax",
Expand Down
16 changes: 14 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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};
Expand Down Expand Up @@ -952,6 +952,7 @@ pub fn build_session(
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();

Expand All @@ -962,6 +963,7 @@ pub fn build_session(
Lrc::new(source_map::SourceMap::new(file_path_mapping)),
DiagnosticOutput::Default,
Default::default(),
process_cfg_mod,
)
}

Expand Down Expand Up @@ -1040,6 +1042,7 @@ pub fn build_session_with_source_map(
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
Expand Down Expand Up @@ -1080,7 +1083,14 @@ pub fn build_session_with_source_map(
},
);

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_(
Expand All @@ -1089,6 +1099,7 @@ 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 {
Expand Down Expand Up @@ -1127,6 +1138,7 @@ fn build_session_(
let parse_sess = ParseSess::with_span_handler(
span_diagnostic,
source_map,
process_cfg_mod,
);
let sysroot = match &sopts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
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 @@ -21,6 +21,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
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" }
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ use std::time::Instant;
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};

Expand Down Expand Up @@ -1096,14 +1095,16 @@ pub fn handle_options(args: &[String]) -> Option<getopts::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,
)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] }
syntax = { path = "../libsyntax" }
syntax_ext = { path = "../libsyntax_ext" }
syntax_expand = { path = "../libsyntax_expand" }
rustc_parse = { path = "../librustc_parse" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc = { path = "../librustc" }
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_data_structures::OnDrop;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use rustc_parse::new_parser_from_source_str;
use std::path::PathBuf;
use std::result;
use std::sync::{Arc, Mutex};
use syntax::{self, parse};
use syntax::ast::{self, MetaItemKind};
use syntax::token;
use syntax::source_map::{FileName, FileLoader, SourceMap};
use syntax::sess::ParseSess;
use syntax_expand::config::process_configure_mod;
use syntax_pos::edition;

pub type Result<T> = result::Result<T, ErrorReported>;
Expand Down Expand Up @@ -64,9 +65,9 @@ impl Compiler {
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
syntax::with_default_globals(move || {
let cfg = cfgspecs.into_iter().map(|s| {
let sess = ParseSess::with_silent_emitter();
let sess = ParseSess::with_silent_emitter(process_configure_mod);
let filename = FileName::cfg_spec_source_code(&s);
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());

macro_rules! error {($reason: expr) => {
early_error(ErrorOutputType::default(),
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use rustc_errors::PResult;
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;
Expand All @@ -37,7 +38,6 @@ use syntax::{self, ast, visit};
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;
Expand All @@ -60,12 +60,11 @@ pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
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)
}
}
})?;

Expand Down Expand Up @@ -181,7 +180,7 @@ pub fn register_plugins<'a>(
)
});

let (krate, features) = syntax::config::features(
let (krate, features) = syntax_expand::config::features(
krate,
&sess.parse_sess,
sess.edition(),
Expand Down Expand Up @@ -484,7 +483,7 @@ pub fn lower_to_hir(
) -> 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 {
Expand Down
59 changes: 24 additions & 35 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc::session::config::{build_configuration, build_session_options, to_crat
use rustc::session::config::{LtoCli, LinkerPluginLto, SwitchWithOptPath, ExternEntry};
use rustc::session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
use rustc::session::config::{rustc_optgroups, Options, ErrorOutputType, Passes};
use rustc::session::build_session;
use rustc::session::{build_session, Session};
use rustc::session::search_paths::SearchPath;
use std::collections::{BTreeMap, BTreeSet};
use std::iter::FromIterator;
Expand All @@ -17,16 +17,23 @@ use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
use syntax::symbol::sym;
use syntax::edition::{Edition, DEFAULT_EDITION};
use syntax;
use syntax_expand::config::process_configure_mod;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{ColorConfig, emitter::HumanReadableErrorType, registry};

pub fn build_session_options_and_crate_config(
matches: &getopts::Matches,
) -> (Options, FxHashSet<(String, Option<String>)>) {
(
build_session_options(matches),
parse_cfgspecs(matches.opt_strs("cfg")),
)
type CfgSpecs = FxHashSet<(String, Option<String>)>;

fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options, CfgSpecs) {
let sessopts = build_session_options(&matches);
let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
(sessopts, cfg)
}

fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
let registry = registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry, process_configure_mod);
(sess, cfg)
}

fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
Expand Down Expand Up @@ -59,31 +66,19 @@ fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
#[test]
fn test_switch_implies_cfg_test() {
syntax::with_default_globals(|| {
let matches = &match optgroups().parse(&["--test".to_string()]) {
Ok(m) => m,
Err(f) => panic!("test_switch_implies_cfg_test: {}", f),
};
let registry = registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let matches = optgroups().parse(&["--test".to_string()]).unwrap();
let (sess, cfg) = mk_session(matches);
let cfg = build_configuration(&sess, to_crate_config(cfg));
assert!(cfg.contains(&(sym::test, None)));
});
}

// When the user supplies --test and --cfg test, don't implicitly add
// another --cfg test
// When the user supplies --test and --cfg test, don't implicitly add another --cfg test
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
syntax::with_default_globals(|| {
let matches = &match optgroups().parse(&["--test".to_string(),
"--cfg=test".to_string()]) {
Ok(m) => m,
Err(f) => panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f),
};
let registry = registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, None, registry);
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
let (sess, cfg) = mk_session(matches);
let cfg = build_configuration(&sess, to_crate_config(cfg));
let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
assert!(test_items.next().is_some());
Expand All @@ -95,27 +90,21 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
fn test_can_print_warnings() {
syntax::with_default_globals(|| {
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
let registry = registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
let (sess, _) = mk_session(matches);
assert!(!sess.diagnostic().can_emit_warnings());
});

syntax::with_default_globals(|| {
let matches = optgroups()
.parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()])
.unwrap();
let registry = registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
let (sess, _) = mk_session(matches);
assert!(sess.diagnostic().can_emit_warnings());
});

syntax::with_default_globals(|| {
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
let registry = registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, None, registry);
let (sess, _) = mk_session(matches);
assert!(sess.diagnostic().can_emit_warnings());
});
}
Expand Down Expand Up @@ -704,6 +693,6 @@ fn test_edition_parsing() {
let matches = optgroups()
.parse(&["--edition=2018".to_string()])
.unwrap();
let (sessopts, _) = build_session_options_and_crate_config(&matches);
let (sessopts, _) = build_session_options_and_crate_config(matches);
assert!(sessopts.edition == Edition::Edition2018)
}
Loading