Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a3b6e57

Browse files
committedNov 10, 2019
Auto merge of #65324 - Centril:organize-syntax, r=petrochenkov
Split libsyntax apart In this PR the general idea is to separate the AST, parser, and friends by a more data / logic structure (tho not fully realized!) by separating out the parser and macro expansion code from libsyntax. Specifically have now three crates instead of one (libsyntax): - libsyntax: - concrete syntax tree (`syntax::ast`) - definition of tokens and token-streams (`syntax::{token, tokenstream}`) -- used by `syntax::ast` - visitors (`syntax::visit`, `syntax::mut_visit`) - shared definitions between `libsyntax_expand` - feature gating (`syntax::feature_gate`) -- we could possibly move this out to its own crater later. - attribute and meta item utilities, including used-marking (`syntax::attr`) - pretty printer (`syntax::print`) -- this should possibly be moved out later. For now I've reduced down the dependencies to a single essential one which could be broken via `ParseSess`. This entails that e.g. `Debug` impls for `Path` cannot reference the pretty printer. - definition of `ParseSess` (`syntax::sess`) -- this is used by `syntax::{attr, print, feature_gate}` and is a common definition used by the parser and other things like librustc. - the `syntax::source_map` -- this includes definitions used by `syntax::ast` and other things but could ostensibly be moved `syntax_pos` since that is more related to this module. - a smattering of misc utilities not sufficiently important to itemize -- some of these could be moved to where they are used (often a single place) but I wanted to limit the scope of this PR. - librustc_parse: - parser (`rustc_parse::parser`) -- reading a file and such are defined in the crate root tho. - lexer (`rustc_parse::lexer`) - validation of meta grammar (post-expansion) in (`rustc_parse::validate_attr`) - libsyntax_expand -- this defines the infra for macro expansion and conditional compilation but this is not libsyntax_ext; we might want to merge them later but currently libsyntax_expand is depended on by librustc_metadata which libsyntax_ext is not. - conditional compilation (`syntax_expand::config`) -- moved from `syntax::config` to here - the bulk of this crate is made up of the old `syntax::ext` r? @estebank
2 parents 86c2832 + 4ae2728 commit a3b6e57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+859
-701
lines changed
 

‎Cargo.lock

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,7 @@ dependencies = [
35043504
"rustc_lint",
35053505
"rustc_metadata",
35063506
"rustc_mir",
3507+
"rustc_parse",
35073508
"rustc_plugin",
35083509
"rustc_plugin_impl",
35093510
"rustc_resolve",
@@ -3572,6 +3573,7 @@ dependencies = [
35723573
"rustc_lint",
35733574
"rustc_metadata",
35743575
"rustc_mir",
3576+
"rustc_parse",
35753577
"rustc_passes",
35763578
"rustc_plugin_impl",
35773579
"rustc_privacy",
@@ -3649,6 +3651,7 @@ dependencies = [
36493651
"rustc_data_structures",
36503652
"rustc_errors",
36513653
"rustc_index",
3654+
"rustc_parse",
36523655
"rustc_target",
36533656
"serialize",
36543657
"smallvec 1.0.0",
@@ -3692,6 +3695,21 @@ dependencies = [
36923695
"core",
36933696
]
36943697

3698+
[[package]]
3699+
name = "rustc_parse"
3700+
version = "0.0.0"
3701+
dependencies = [
3702+
"bitflags",
3703+
"log",
3704+
"rustc_data_structures",
3705+
"rustc_errors",
3706+
"rustc_lexer",
3707+
"rustc_target",
3708+
"smallvec 1.0.0",
3709+
"syntax",
3710+
"syntax_pos",
3711+
]
3712+
36953713
[[package]]
36963714
name = "rustc_passes"
36973715
version = "0.0.0"
@@ -3701,6 +3719,7 @@ dependencies = [
37013719
"rustc_data_structures",
37023720
"rustc_errors",
37033721
"rustc_index",
3722+
"rustc_parse",
37043723
"rustc_target",
37053724
"syntax",
37063725
"syntax_pos",
@@ -3763,6 +3782,7 @@ dependencies = [
37633782
"rustc",
37643783
"rustc_codegen_utils",
37653784
"rustc_data_structures",
3785+
"rustc_parse",
37663786
"serde_json",
37673787
"syntax",
37683788
"syntax_pos",
@@ -4372,14 +4392,11 @@ dependencies = [
43724392
name = "syntax_expand"
43734393
version = "0.0.0"
43744394
dependencies = [
4375-
"bitflags",
4376-
"lazy_static 1.3.0",
43774395
"log",
43784396
"rustc_data_structures",
43794397
"rustc_errors",
4380-
"rustc_index",
43814398
"rustc_lexer",
4382-
"scoped-tls",
4399+
"rustc_parse",
43834400
"serialize",
43844401
"smallvec 1.0.0",
43854402
"syntax",
@@ -4394,6 +4411,7 @@ dependencies = [
43944411
"log",
43954412
"rustc_data_structures",
43964413
"rustc_errors",
4414+
"rustc_parse",
43974415
"rustc_target",
43984416
"smallvec 1.0.0",
43994417
"syntax",

‎src/librustc/session/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use syntax::expand::allocator::AllocatorKind;
2626
use syntax::feature_gate::{self, AttributeType};
2727
use syntax::json::JsonEmitter;
2828
use syntax::source_map;
29-
use syntax::sess::ParseSess;
29+
use syntax::sess::{ParseSess, ProcessCfgMod};
3030
use syntax::symbol::Symbol;
3131
use syntax_pos::{MultiSpan, Span};
3232
use crate::util::profiling::{SelfProfiler, SelfProfilerRef};
@@ -934,6 +934,7 @@ pub fn build_session(
934934
sopts: config::Options,
935935
local_crate_source_file: Option<PathBuf>,
936936
registry: errors::registry::Registry,
937+
process_cfg_mod: ProcessCfgMod,
937938
) -> Session {
938939
let file_path_mapping = sopts.file_path_mapping();
939940

@@ -944,6 +945,7 @@ pub fn build_session(
944945
Lrc::new(source_map::SourceMap::new(file_path_mapping)),
945946
DiagnosticOutput::Default,
946947
Default::default(),
948+
process_cfg_mod,
947949
)
948950
}
949951

@@ -1022,6 +1024,7 @@ pub fn build_session_with_source_map(
10221024
source_map: Lrc<source_map::SourceMap>,
10231025
diagnostics_output: DiagnosticOutput,
10241026
lint_caps: FxHashMap<lint::LintId, lint::Level>,
1027+
process_cfg_mod: ProcessCfgMod,
10251028
) -> Session {
10261029
// FIXME: This is not general enough to make the warning lint completely override
10271030
// normal diagnostic warnings, since the warning lint can also be denied and changed
@@ -1062,7 +1065,14 @@ pub fn build_session_with_source_map(
10621065
},
10631066
);
10641067

1065-
build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps)
1068+
build_session_(
1069+
sopts,
1070+
local_crate_source_file,
1071+
diagnostic_handler,
1072+
source_map,
1073+
lint_caps,
1074+
process_cfg_mod,
1075+
)
10661076
}
10671077

10681078
fn build_session_(
@@ -1071,6 +1081,7 @@ fn build_session_(
10711081
span_diagnostic: errors::Handler,
10721082
source_map: Lrc<source_map::SourceMap>,
10731083
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
1084+
process_cfg_mod: ProcessCfgMod,
10741085
) -> Session {
10751086
let self_profiler =
10761087
if let SwitchWithOptPath::Enabled(ref d) = sopts.debugging_opts.self_profile {
@@ -1109,6 +1120,7 @@ fn build_session_(
11091120
let parse_sess = ParseSess::with_span_handler(
11101121
span_diagnostic,
11111122
source_map,
1123+
process_cfg_mod,
11121124
);
11131125
let sysroot = match &sopts.maybe_sysroot {
11141126
Some(sysroot) => sysroot.clone(),

0 commit comments

Comments
 (0)
Please sign in to comment.