Skip to content

Commit a9a89e1

Browse files
authored
Rollup 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 1d25bd2 + a67d36f commit a9a89e1

File tree

139 files changed

+452
-362
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

+452
-362
lines changed

Cargo.lock

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,7 @@ dependencies = [
30913091
"rustc-rayon",
30923092
"rustc-rayon-core",
30933093
"rustc_apfloat",
3094+
"rustc_attr",
30943095
"rustc_data_structures",
30953096
"rustc_error_codes",
30963097
"rustc_errors",
@@ -3357,6 +3358,7 @@ version = "0.0.0"
33573358
dependencies = [
33583359
"log",
33593360
"rustc",
3361+
"rustc_ast_pretty",
33603362
"rustc_data_structures",
33613363
"rustc_error_codes",
33623364
"rustc_errors",
@@ -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_error_codes",
33793383
"rustc_errors",
@@ -3384,12 +3388,41 @@ dependencies = [
33843388
"syntax",
33853389
]
33863390

3391+
[[package]]
3392+
name = "rustc_ast_pretty"
3393+
version = "0.0.0"
3394+
dependencies = [
3395+
"log",
3396+
"rustc_data_structures",
3397+
"rustc_span",
3398+
"syntax",
3399+
]
3400+
3401+
[[package]]
3402+
name = "rustc_attr"
3403+
version = "0.0.0"
3404+
dependencies = [
3405+
"rustc_ast_pretty",
3406+
"rustc_data_structures",
3407+
"rustc_error_codes",
3408+
"rustc_errors",
3409+
"rustc_feature",
3410+
"rustc_macros",
3411+
"rustc_session",
3412+
"rustc_span",
3413+
"serialize",
3414+
"smallvec 1.0.0",
3415+
"syntax",
3416+
]
3417+
33873418
[[package]]
33883419
name = "rustc_builtin_macros"
33893420
version = "0.0.0"
33903421
dependencies = [
33913422
"fmt_macros",
33923423
"log",
3424+
"rustc_ast_pretty",
3425+
"rustc_attr",
33933426
"rustc_data_structures",
33943427
"rustc_error_codes",
33953428
"rustc_errors",
@@ -3413,6 +3446,7 @@ dependencies = [
34133446
"log",
34143447
"rustc",
34153448
"rustc-demangle",
3449+
"rustc_attr",
34163450
"rustc_codegen_ssa",
34173451
"rustc_codegen_utils",
34183452
"rustc_data_structures",
@@ -3443,6 +3477,7 @@ dependencies = [
34433477
"num_cpus",
34443478
"rustc",
34453479
"rustc_apfloat",
3480+
"rustc_attr",
34463481
"rustc_codegen_utils",
34473482
"rustc_data_structures",
34483483
"rustc_error_codes",
@@ -3508,6 +3543,7 @@ dependencies = [
35083543
"lazy_static 1.3.0",
35093544
"log",
35103545
"rustc",
3546+
"rustc_ast_pretty",
35113547
"rustc_codegen_utils",
35123548
"rustc_data_structures",
35133549
"rustc_error_codes",
@@ -3554,6 +3590,8 @@ version = "0.0.0"
35543590
dependencies = [
35553591
"log",
35563592
"rustc_ast_passes",
3593+
"rustc_ast_pretty",
3594+
"rustc_attr",
35573595
"rustc_data_structures",
35583596
"rustc_errors",
35593597
"rustc_feature",
@@ -3583,11 +3621,11 @@ version = "0.0.0"
35833621
name = "rustc_hir"
35843622
version = "0.0.0"
35853623
dependencies = [
3624+
"rustc_ast_pretty",
35863625
"rustc_data_structures",
35873626
"rustc_errors",
35883627
"rustc_index",
35893628
"rustc_macros",
3590-
"rustc_session",
35913629
"rustc_span",
35923630
"rustc_target",
35933631
"serialize",
@@ -3630,6 +3668,7 @@ dependencies = [
36303668
"rustc-rayon",
36313669
"rustc_ast_lowering",
36323670
"rustc_ast_passes",
3671+
"rustc_attr",
36333672
"rustc_builtin_macros",
36343673
"rustc_codegen_llvm",
36353674
"rustc_codegen_ssa",
@@ -3674,6 +3713,8 @@ version = "0.0.0"
36743713
dependencies = [
36753714
"log",
36763715
"rustc",
3716+
"rustc_ast_pretty",
3717+
"rustc_attr",
36773718
"rustc_data_structures",
36783719
"rustc_error_codes",
36793720
"rustc_errors",
@@ -3715,6 +3756,8 @@ dependencies = [
37153756
"log",
37163757
"memmap",
37173758
"rustc",
3759+
"rustc_ast_pretty",
3760+
"rustc_attr",
37183761
"rustc_data_structures",
37193762
"rustc_error_codes",
37203763
"rustc_errors",
@@ -3743,6 +3786,8 @@ dependencies = [
37433786
"polonius-engine",
37443787
"rustc",
37453788
"rustc_apfloat",
3789+
"rustc_ast_pretty",
3790+
"rustc_attr",
37463791
"rustc_data_structures",
37473792
"rustc_error_codes",
37483793
"rustc_errors",
@@ -3766,6 +3811,7 @@ dependencies = [
37663811
"log",
37673812
"rustc",
37683813
"rustc_apfloat",
3814+
"rustc_attr",
37693815
"rustc_data_structures",
37703816
"rustc_error_codes",
37713817
"rustc_errors",
@@ -3785,6 +3831,8 @@ version = "0.0.0"
37853831
dependencies = [
37863832
"bitflags",
37873833
"log",
3834+
"rustc_ast_pretty",
3835+
"rustc_attr",
37883836
"rustc_data_structures",
37893837
"rustc_error_codes",
37903838
"rustc_errors",
@@ -3803,6 +3851,7 @@ version = "0.0.0"
38033851
dependencies = [
38043852
"log",
38053853
"rustc",
3854+
"rustc_attr",
38063855
"rustc_data_structures",
38073856
"rustc_error_codes",
38083857
"rustc_errors",
@@ -3835,6 +3884,7 @@ version = "0.0.0"
38353884
dependencies = [
38363885
"log",
38373886
"rustc",
3887+
"rustc_attr",
38383888
"rustc_data_structures",
38393889
"rustc_error_codes",
38403890
"rustc_errors",
@@ -3853,6 +3903,8 @@ dependencies = [
38533903
"log",
38543904
"rustc",
38553905
"rustc_ast_lowering",
3906+
"rustc_ast_pretty",
3907+
"rustc_attr",
38563908
"rustc_data_structures",
38573909
"rustc_error_codes",
38583910
"rustc_errors",
@@ -3874,6 +3926,7 @@ dependencies = [
38743926
"rls-data",
38753927
"rls-span",
38763928
"rustc",
3929+
"rustc_ast_pretty",
38773930
"rustc_codegen_utils",
38783931
"rustc_data_structures",
38793932
"rustc_hir",
@@ -3898,6 +3951,7 @@ dependencies = [
38983951
"rustc_span",
38993952
"rustc_target",
39003953
"serialize",
3954+
"syntax",
39013955
]
39023956

39033957
[[package]]
@@ -3972,6 +4026,7 @@ dependencies = [
39724026
"arena",
39734027
"log",
39744028
"rustc",
4029+
"rustc_attr",
39754030
"rustc_data_structures",
39764031
"rustc_error_codes",
39774032
"rustc_errors",
@@ -4493,13 +4548,9 @@ version = "0.0.0"
44934548
dependencies = [
44944549
"log",
44954550
"rustc_data_structures",
4496-
"rustc_error_codes",
4497-
"rustc_errors",
4498-
"rustc_feature",
44994551
"rustc_index",
45004552
"rustc_lexer",
45014553
"rustc_macros",
4502-
"rustc_session",
45034554
"rustc_span",
45044555
"scoped-tls",
45054556
"serialize",

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::session::config::OptLevel;
44
use crate::traits::TraitQueryMode;
55
use crate::ty::print::obsolete::DefPathBasedNames;
66
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
7+
use rustc_attr::InlineAttr;
78
use rustc_data_structures::base_n;
89
use rustc_data_structures::fx::FxHashMap;
910
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -13,7 +14,6 @@ use rustc_span::source_map::Span;
1314
use rustc_span::symbol::Symbol;
1415
use std::fmt;
1516
use std::hash::Hash;
16-
use syntax::attr::InlineAttr;
1717

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

src/librustc/traits/on_unimplemented.rs

Lines changed: 1 addition & 1 deletion
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
use rustc_error_codes::*;
1515

0 commit comments

Comments
 (0)