Skip to content

Commit 13db650

Browse files
committed
Auto merge of #68133 - Centril:slimmer-syntax, r=petrochenkov
Slimmer syntax High-level summary of changes: - The `syntax::node_count` pass is moved into `rustc_ast_passes`. This works towards improving #65031 by making compiling `syntax` go faster. - The `syntax::{GLOBALS, with_globals, ..}` business is consolidated into `syntax::attr` for cleaner code and future possible improvements. - The pretty printer loses its dependency on `ParseSess`, opting to use `SourceMap` & friends directly instead. - Some drive by cleanup of `syntax::attr::HasAttr` happens. - Builtin attribute logic (`syntax::attr::builtin`) + `syntax::attr::allow_internal_unstable` is moved into a new `rustc_attr` crate. More logic from `syntax::attr` should be moved into that crate over time. This also means that `syntax` loses all mentions of `ParseSess`, which enables the next point. - The pretty printer `syntax::print` is moved into a new crate `rustc_ast_pretty`. - `rustc_session::node_id` is moved back as `syntax::node_id`. As a result, `syntax` gets to drop dependencies on `rustc_session` (and implicitly `rustc_target`), `rustc_error_codes`, and `rustc_errors`. Moreover `rustc_hir` gets to drop its dependency on `rustc_session` as well. At this point, these crates are mostly "pure data crates", which is approaching a desirable end state. - We should consider renaming `syntax` to `rustc_ast` now.
2 parents 64184a3 + 1a3141c commit 13db650

File tree

139 files changed

+451
-358
lines changed

Some content is hidden

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

139 files changed

+451
-358
lines changed

Cargo.lock

+55-4
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,7 @@ dependencies = [
30933093
"rustc-rayon",
30943094
"rustc-rayon-core",
30953095
"rustc_apfloat",
3096+
"rustc_attr",
30963097
"rustc_data_structures",
30973098
"rustc_errors",
30983099
"rustc_feature",
@@ -3358,6 +3359,7 @@ version = "0.0.0"
33583359
dependencies = [
33593360
"log",
33603361
"rustc",
3362+
"rustc_ast_pretty",
33613363
"rustc_data_structures",
33623364
"rustc_errors",
33633365
"rustc_hir",
@@ -3374,6 +3376,8 @@ name = "rustc_ast_passes"
33743376
version = "0.0.0"
33753377
dependencies = [
33763378
"log",
3379+
"rustc_ast_pretty",
3380+
"rustc_attr",
33773381
"rustc_data_structures",
33783382
"rustc_errors",
33793383
"rustc_feature",
@@ -3383,12 +3387,40 @@ dependencies = [
33833387
"syntax",
33843388
]
33853389

3390+
[[package]]
3391+
name = "rustc_ast_pretty"
3392+
version = "0.0.0"
3393+
dependencies = [
3394+
"log",
3395+
"rustc_data_structures",
3396+
"rustc_span",
3397+
"syntax",
3398+
]
3399+
3400+
[[package]]
3401+
name = "rustc_attr"
3402+
version = "0.0.0"
3403+
dependencies = [
3404+
"rustc_ast_pretty",
3405+
"rustc_data_structures",
3406+
"rustc_errors",
3407+
"rustc_feature",
3408+
"rustc_macros",
3409+
"rustc_session",
3410+
"rustc_span",
3411+
"serialize",
3412+
"smallvec 1.0.0",
3413+
"syntax",
3414+
]
3415+
33863416
[[package]]
33873417
name = "rustc_builtin_macros"
33883418
version = "0.0.0"
33893419
dependencies = [
33903420
"fmt_macros",
33913421
"log",
3422+
"rustc_ast_pretty",
3423+
"rustc_attr",
33923424
"rustc_data_structures",
33933425
"rustc_errors",
33943426
"rustc_expand",
@@ -3411,6 +3443,7 @@ dependencies = [
34113443
"log",
34123444
"rustc",
34133445
"rustc-demangle",
3446+
"rustc_attr",
34143447
"rustc_codegen_ssa",
34153448
"rustc_codegen_utils",
34163449
"rustc_data_structures",
@@ -3442,6 +3475,7 @@ dependencies = [
34423475
"num_cpus",
34433476
"rustc",
34443477
"rustc_apfloat",
3478+
"rustc_attr",
34453479
"rustc_codegen_utils",
34463480
"rustc_data_structures",
34473481
"rustc_errors",
@@ -3506,6 +3540,7 @@ dependencies = [
35063540
"lazy_static 1.4.0",
35073541
"log",
35083542
"rustc",
3543+
"rustc_ast_pretty",
35093544
"rustc_codegen_utils",
35103545
"rustc_data_structures",
35113546
"rustc_error_codes",
@@ -3552,6 +3587,8 @@ version = "0.0.0"
35523587
dependencies = [
35533588
"log",
35543589
"rustc_ast_passes",
3590+
"rustc_ast_pretty",
3591+
"rustc_attr",
35553592
"rustc_data_structures",
35563593
"rustc_errors",
35573594
"rustc_feature",
@@ -3581,11 +3618,11 @@ version = "0.0.0"
35813618
name = "rustc_hir"
35823619
version = "0.0.0"
35833620
dependencies = [
3621+
"rustc_ast_pretty",
35843622
"rustc_data_structures",
35853623
"rustc_errors",
35863624
"rustc_index",
35873625
"rustc_macros",
3588-
"rustc_session",
35893626
"rustc_span",
35903627
"rustc_target",
35913628
"serialize",
@@ -3628,6 +3665,7 @@ dependencies = [
36283665
"rustc-rayon",
36293666
"rustc_ast_lowering",
36303667
"rustc_ast_passes",
3668+
"rustc_attr",
36313669
"rustc_builtin_macros",
36323670
"rustc_codegen_llvm",
36333671
"rustc_codegen_ssa",
@@ -3672,6 +3710,8 @@ version = "0.0.0"
36723710
dependencies = [
36733711
"log",
36743712
"rustc",
3713+
"rustc_ast_pretty",
3714+
"rustc_attr",
36753715
"rustc_data_structures",
36763716
"rustc_errors",
36773717
"rustc_feature",
@@ -3712,6 +3752,8 @@ dependencies = [
37123752
"log",
37133753
"memmap",
37143754
"rustc",
3755+
"rustc_ast_pretty",
3756+
"rustc_attr",
37153757
"rustc_data_structures",
37163758
"rustc_errors",
37173759
"rustc_expand",
@@ -3739,6 +3781,8 @@ dependencies = [
37393781
"polonius-engine",
37403782
"rustc",
37413783
"rustc_apfloat",
3784+
"rustc_ast_pretty",
3785+
"rustc_attr",
37423786
"rustc_data_structures",
37433787
"rustc_errors",
37443788
"rustc_hir",
@@ -3761,6 +3805,7 @@ dependencies = [
37613805
"log",
37623806
"rustc",
37633807
"rustc_apfloat",
3808+
"rustc_attr",
37643809
"rustc_data_structures",
37653810
"rustc_errors",
37663811
"rustc_hir",
@@ -3780,6 +3825,8 @@ version = "0.0.0"
37803825
dependencies = [
37813826
"bitflags",
37823827
"log",
3828+
"rustc_ast_pretty",
3829+
"rustc_attr",
37833830
"rustc_data_structures",
37843831
"rustc_errors",
37853832
"rustc_feature",
@@ -3797,6 +3844,7 @@ version = "0.0.0"
37973844
dependencies = [
37983845
"log",
37993846
"rustc",
3847+
"rustc_attr",
38003848
"rustc_data_structures",
38013849
"rustc_errors",
38023850
"rustc_feature",
@@ -3827,6 +3875,7 @@ version = "0.0.0"
38273875
dependencies = [
38283876
"log",
38293877
"rustc",
3878+
"rustc_attr",
38303879
"rustc_data_structures",
38313880
"rustc_errors",
38323881
"rustc_hir",
@@ -3844,6 +3893,8 @@ dependencies = [
38443893
"log",
38453894
"rustc",
38463895
"rustc_ast_lowering",
3896+
"rustc_ast_pretty",
3897+
"rustc_attr",
38473898
"rustc_data_structures",
38483899
"rustc_errors",
38493900
"rustc_expand",
@@ -3864,6 +3915,7 @@ dependencies = [
38643915
"rls-data",
38653916
"rls-span",
38663917
"rustc",
3918+
"rustc_ast_pretty",
38673919
"rustc_codegen_utils",
38683920
"rustc_data_structures",
38693921
"rustc_hir",
@@ -3887,6 +3939,7 @@ dependencies = [
38873939
"rustc_span",
38883940
"rustc_target",
38893941
"serialize",
3942+
"syntax",
38903943
]
38913944

38923945
[[package]]
@@ -3961,6 +4014,7 @@ dependencies = [
39614014
"arena",
39624015
"log",
39634016
"rustc",
4017+
"rustc_attr",
39644018
"rustc_data_structures",
39654019
"rustc_errors",
39664020
"rustc_hir",
@@ -4481,12 +4535,9 @@ version = "0.0.0"
44814535
dependencies = [
44824536
"log",
44834537
"rustc_data_structures",
4484-
"rustc_errors",
4485-
"rustc_feature",
44864538
"rustc_index",
44874539
"rustc_lexer",
44884540
"rustc_macros",
4489-
"rustc_session",
44904541
"rustc_span",
44914542
"scoped-tls",
44924543
"serialize",

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rustc-rayon = "0.3.0"
2121
rustc-rayon-core = "0.3.0"
2222
polonius-engine = "0.11.0"
2323
rustc_apfloat = { path = "../librustc_apfloat" }
24+
rustc_attr = { path = "../librustc_attr" }
2425
rustc_feature = { path = "../librustc_feature" }
2526
rustc_hir = { path = "../librustc_hir" }
2627
rustc_target = { path = "../librustc_target" }

src/librustc/hir/map/definitions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use rustc_data_structures::stable_hasher::StableHasher;
1010
use rustc_hir as hir;
1111
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
1212
use rustc_index::vec::IndexVec;
13-
use rustc_session::node_id::NodeMap;
1413
use rustc_session::CrateDisambiguator;
1514
use rustc_span::hygiene::ExpnId;
1615
use rustc_span::symbol::{sym, Symbol};
1716
use rustc_span::Span;
1817
use syntax::ast;
18+
use syntax::node_id::NodeMap;
1919

2020
use std::borrow::Borrow;
2121
use std::fmt::Write;

src/librustc/ich/impls_hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
44
use crate::hir::map::DefPathHash;
55
use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
6+
use rustc_attr as attr;
67
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
78
use rustc_hir as hir;
89
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
910
use smallvec::SmallVec;
1011
use std::mem;
11-
use syntax::attr;
1212

1313
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
1414
#[inline]

src/librustc/middle/codegen_fn_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::mir::mono::Linkage;
2+
use rustc_attr::{InlineAttr, OptimizeAttr};
23
use rustc_span::symbol::Symbol;
3-
use syntax::attr::{InlineAttr, OptimizeAttr};
44

55
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
66
pub struct CodegenFnAttrs {

src/librustc/middle/stability.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ pub use self::StabilityLevel::*;
55

66
use crate::session::{DiagnosticMessageId, Session};
77
use crate::ty::{self, TyCtxt};
8+
use rustc_attr::{self as attr, ConstStability, Deprecation, RustcDeprecation, Stability};
89
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
910
use rustc_errors::{Applicability, DiagnosticBuilder};
1011
use rustc_feature::GateIssue;
1112
use rustc_hir as hir;
1213
use rustc_hir::def::DefKind;
1314
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
1415
use rustc_hir::{self, HirId};
15-
use rustc_session::lint::{self, BuiltinLintDiagnostics, Lint, LintBuffer};
16+
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
17+
use rustc_session::lint::{BuiltinLintDiagnostics, Lint, LintBuffer};
18+
use rustc_session::parse::feature_err_issue;
1619
use rustc_span::symbol::{sym, Symbol};
1720
use rustc_span::{MultiSpan, Span};
1821
use syntax::ast::CRATE_NODE_ID;
19-
use syntax::attr::{self, ConstStability, Deprecation, RustcDeprecation, Stability};
20-
use syntax::sess::feature_err_issue;
2122

2223
use std::num::NonZeroU32;
2324

@@ -97,7 +98,7 @@ pub fn report_unstable(
9798
issue: Option<NonZeroU32>,
9899
is_soft: bool,
99100
span: Span,
100-
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
101+
soft_handler: impl FnOnce(&'static Lint, Span, &str),
101102
) {
102103
let msg = match reason {
103104
Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
@@ -119,7 +120,7 @@ pub fn report_unstable(
119120
let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id);
120121
if fresh {
121122
if is_soft {
122-
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
123+
soft_handler(SOFT_UNSTABLE, span, &msg)
123124
} else {
124125
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
125126
.emit();
@@ -175,19 +176,19 @@ fn deprecation_message_common(message: String, reason: Option<Symbol>) -> String
175176

176177
pub fn deprecation_message(depr: &Deprecation, path: &str) -> (String, &'static Lint) {
177178
let message = format!("use of deprecated item '{}'", path);
178-
(deprecation_message_common(message, depr.note), lint::builtin::DEPRECATED)
179+
(deprecation_message_common(message, depr.note), DEPRECATED)
179180
}
180181

181182
pub fn rustc_deprecation_message(depr: &RustcDeprecation, path: &str) -> (String, &'static Lint) {
182183
let (message, lint) = if deprecation_in_effect(&depr.since.as_str()) {
183-
(format!("use of deprecated item '{}'", path), lint::builtin::DEPRECATED)
184+
(format!("use of deprecated item '{}'", path), DEPRECATED)
184185
} else {
185186
(
186187
format!(
187188
"use of item '{}' that will be deprecated in future version {}",
188189
path, depr.since
189190
),
190-
lint::builtin::DEPRECATED_IN_FUTURE,
191+
DEPRECATED_IN_FUTURE,
191192
)
192193
};
193194
(deprecation_message_common(message, Some(depr.reason)), lint)

src/librustc/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
33
use crate::session::config::OptLevel;
44
use crate::ty::print::obsolete::DefPathBasedNames;
55
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
6+
use rustc_attr::InlineAttr;
67
use rustc_data_structures::base_n;
78
use rustc_data_structures::fx::FxHashMap;
89
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -12,7 +13,6 @@ use rustc_span::source_map::Span;
1213
use rustc_span::symbol::Symbol;
1314
use std::fmt;
1415
use std::hash::Hash;
15-
use syntax::attr::InlineAttr;
1616

1717
/// Describes how a monomorphization will be instantiated in object files.
1818
#[derive(PartialEq)]

src/librustc/traits/on_unimplemented.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use fmt_macros::{Parser, Piece, Position};
33
use crate::ty::{self, GenericParamDefKind, TyCtxt};
44
use crate::util::common::ErrorReported;
55

6+
use rustc_attr as attr;
67
use rustc_data_structures::fx::FxHashMap;
78
use rustc_errors::struct_span_err;
89
use rustc_hir::def_id::DefId;
910
use rustc_span::symbol::{kw, sym, Symbol};
1011
use rustc_span::Span;
1112
use syntax::ast::{MetaItem, NestedMetaItem};
12-
use syntax::attr;
1313

1414
#[derive(Clone, Debug)]
1515
pub struct OnUnimplementedFormatString(Symbol);

0 commit comments

Comments
 (0)