Skip to content

Commit

Permalink
Auto merge of #68133 - Centril:slimmer-syntax, r=petrochenkov
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Feb 1, 2020
2 parents 64184a3 + 1a3141c commit 13db650
Show file tree
Hide file tree
Showing 139 changed files with 451 additions and 358 deletions.
59 changes: 55 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3093,6 +3093,7 @@ dependencies = [
"rustc-rayon",
"rustc-rayon-core",
"rustc_apfloat",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand Down Expand Up @@ -3358,6 +3359,7 @@ version = "0.0.0"
dependencies = [
"log",
"rustc",
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
Expand All @@ -3374,6 +3376,8 @@ name = "rustc_ast_passes"
version = "0.0.0"
dependencies = [
"log",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand All @@ -3383,12 +3387,40 @@ dependencies = [
"syntax",
]

[[package]]
name = "rustc_ast_pretty"
version = "0.0.0"
dependencies = [
"log",
"rustc_data_structures",
"rustc_span",
"syntax",
]

[[package]]
name = "rustc_attr"
version = "0.0.0"
dependencies = [
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_macros",
"rustc_session",
"rustc_span",
"serialize",
"smallvec 1.0.0",
"syntax",
]

[[package]]
name = "rustc_builtin_macros"
version = "0.0.0"
dependencies = [
"fmt_macros",
"log",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_expand",
Expand All @@ -3411,6 +3443,7 @@ dependencies = [
"log",
"rustc",
"rustc-demangle",
"rustc_attr",
"rustc_codegen_ssa",
"rustc_codegen_utils",
"rustc_data_structures",
Expand Down Expand Up @@ -3442,6 +3475,7 @@ dependencies = [
"num_cpus",
"rustc",
"rustc_apfloat",
"rustc_attr",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -3506,6 +3540,7 @@ dependencies = [
"lazy_static 1.4.0",
"log",
"rustc",
"rustc_ast_pretty",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_error_codes",
Expand Down Expand Up @@ -3552,6 +3587,8 @@ version = "0.0.0"
dependencies = [
"log",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand Down Expand Up @@ -3581,11 +3618,11 @@ version = "0.0.0"
name = "rustc_hir"
version = "0.0.0"
dependencies = [
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_index",
"rustc_macros",
"rustc_session",
"rustc_span",
"rustc_target",
"serialize",
Expand Down Expand Up @@ -3628,6 +3665,7 @@ dependencies = [
"rustc-rayon",
"rustc_ast_lowering",
"rustc_ast_passes",
"rustc_attr",
"rustc_builtin_macros",
"rustc_codegen_llvm",
"rustc_codegen_ssa",
Expand Down Expand Up @@ -3672,6 +3710,8 @@ version = "0.0.0"
dependencies = [
"log",
"rustc",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand Down Expand Up @@ -3712,6 +3752,8 @@ dependencies = [
"log",
"memmap",
"rustc",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_expand",
Expand Down Expand Up @@ -3739,6 +3781,8 @@ dependencies = [
"polonius-engine",
"rustc",
"rustc_apfloat",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
Expand All @@ -3761,6 +3805,7 @@ dependencies = [
"log",
"rustc",
"rustc_apfloat",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
Expand All @@ -3780,6 +3825,8 @@ version = "0.0.0"
dependencies = [
"bitflags",
"log",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand All @@ -3797,6 +3844,7 @@ version = "0.0.0"
dependencies = [
"log",
"rustc",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand Down Expand Up @@ -3827,6 +3875,7 @@ version = "0.0.0"
dependencies = [
"log",
"rustc",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
Expand All @@ -3844,6 +3893,8 @@ dependencies = [
"log",
"rustc",
"rustc_ast_lowering",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_expand",
Expand All @@ -3864,6 +3915,7 @@ dependencies = [
"rls-data",
"rls-span",
"rustc",
"rustc_ast_pretty",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_hir",
Expand All @@ -3887,6 +3939,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"serialize",
"syntax",
]

[[package]]
Expand Down Expand Up @@ -3961,6 +4014,7 @@ dependencies = [
"arena",
"log",
"rustc",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
Expand Down Expand Up @@ -4481,12 +4535,9 @@ version = "0.0.0"
dependencies = [
"log",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_index",
"rustc_lexer",
"rustc_macros",
"rustc_session",
"rustc_span",
"scoped-tls",
"serialize",
Expand Down
1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rustc-rayon = "0.3.0"
rustc-rayon-core = "0.3.0"
polonius-engine = "0.11.0"
rustc_apfloat = { path = "../librustc_apfloat" }
rustc_attr = { path = "../librustc_attr" }
rustc_feature = { path = "../librustc_feature" }
rustc_hir = { path = "../librustc_hir" }
rustc_target = { path = "../librustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use rustc_data_structures::stable_hasher::StableHasher;
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_index::vec::IndexVec;
use rustc_session::node_id::NodeMap;
use rustc_session::CrateDisambiguator;
use rustc_span::hygiene::ExpnId;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
use syntax::ast;
use syntax::node_id::NodeMap;

use std::borrow::Borrow;
use std::fmt::Write;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use crate::hir::map::DefPathHash;
use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
use rustc_attr as attr;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
use smallvec::SmallVec;
use std::mem;
use syntax::attr;

impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::mir::mono::Linkage;
use rustc_attr::{InlineAttr, OptimizeAttr};
use rustc_span::symbol::Symbol;
use syntax::attr::{InlineAttr, OptimizeAttr};

#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
pub struct CodegenFnAttrs {
Expand Down
17 changes: 9 additions & 8 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ pub use self::StabilityLevel::*;

use crate::session::{DiagnosticMessageId, Session};
use crate::ty::{self, TyCtxt};
use rustc_attr::{self as attr, ConstStability, Deprecation, RustcDeprecation, Stability};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_feature::GateIssue;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
use rustc_hir::{self, HirId};
use rustc_session::lint::{self, BuiltinLintDiagnostics, Lint, LintBuffer};
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
use rustc_session::lint::{BuiltinLintDiagnostics, Lint, LintBuffer};
use rustc_session::parse::feature_err_issue;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{MultiSpan, Span};
use syntax::ast::CRATE_NODE_ID;
use syntax::attr::{self, ConstStability, Deprecation, RustcDeprecation, Stability};
use syntax::sess::feature_err_issue;

use std::num::NonZeroU32;

Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn report_unstable(
issue: Option<NonZeroU32>,
is_soft: bool,
span: Span,
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
soft_handler: impl FnOnce(&'static Lint, Span, &str),
) {
let msg = match reason {
Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
Expand All @@ -119,7 +120,7 @@ pub fn report_unstable(
let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
if is_soft {
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
soft_handler(SOFT_UNSTABLE, span, &msg)
} else {
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
.emit();
Expand Down Expand Up @@ -175,19 +176,19 @@ fn deprecation_message_common(message: String, reason: Option<Symbol>) -> String

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

pub fn rustc_deprecation_message(depr: &RustcDeprecation, path: &str) -> (String, &'static Lint) {
let (message, lint) = if deprecation_in_effect(&depr.since.as_str()) {
(format!("use of deprecated item '{}'", path), lint::builtin::DEPRECATED)
(format!("use of deprecated item '{}'", path), DEPRECATED)
} else {
(
format!(
"use of item '{}' that will be deprecated in future version {}",
path, depr.since
),
lint::builtin::DEPRECATED_IN_FUTURE,
DEPRECATED_IN_FUTURE,
)
};
(deprecation_message_common(message, Some(depr.reason)), lint)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
use crate::session::config::OptLevel;
use crate::ty::print::obsolete::DefPathBasedNames;
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
use rustc_attr::InlineAttr;
use rustc_data_structures::base_n;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand All @@ -12,7 +13,6 @@ use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol;
use std::fmt;
use std::hash::Hash;
use syntax::attr::InlineAttr;

/// Describes how a monomorphization will be instantiated in object files.
#[derive(PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use fmt_macros::{Parser, Piece, Position};
use crate::ty::{self, GenericParamDefKind, TyCtxt};
use crate::util::common::ErrorReported;

use rustc_attr as attr;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::struct_span_err;
use rustc_hir::def_id::DefId;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
use syntax::ast::{MetaItem, NestedMetaItem};
use syntax::attr;

#[derive(Clone, Debug)]
pub struct OnUnimplementedFormatString(Symbol);
Expand Down
Loading

0 comments on commit 13db650

Please sign in to comment.