Skip to content

Commit b712f62

Browse files
Auto merge of #145354 - Kobzol:cache-proc-derive-macros, r=<try>
Cache derive proc macro expansion with incremental query
2 parents 350d0ef + ff86ff4 commit b712f62

File tree

17 files changed

+258
-49
lines changed

17 files changed

+258
-49
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,11 +3833,13 @@ dependencies = [
38333833
"rustc_lexer",
38343834
"rustc_lint_defs",
38353835
"rustc_macros",
3836+
"rustc_middle",
38363837
"rustc_parse",
38373838
"rustc_proc_macro",
38383839
"rustc_serialize",
38393840
"rustc_session",
38403841
"rustc_span",
3842+
"scoped-tls",
38413843
"smallvec",
38423844
"thin-vec",
38433845
"tracing",

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,7 @@ impl UseTree {
32433243
/// Distinguishes between `Attribute`s that decorate items and Attributes that
32443244
/// are contained as statements within items. These two cases need to be
32453245
/// distinguished for pretty-printing.
3246-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic, Walkable)]
3246+
#[derive(Clone, PartialEq, Encodable, Decodable, Hash, Debug, Copy, HashStable_Generic, Walkable)]
32473247
pub enum AttrStyle {
32483248
Outer,
32493249
Inner,

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ use rustc_span::{Ident, Symbol};
1515
use crate::ast;
1616
use crate::util::case::Case;
1717

18-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
18+
#[derive(Clone, Copy, PartialEq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
1919
pub enum CommentKind {
2020
Line,
2121
Block,
2222
}
2323

2424
// This type must not implement `Hash` due to the unusual `PartialEq` impl below.
25-
#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic)]
25+
#[derive(Copy, Clone, Debug, Hash, Encodable, Decodable, HashStable_Generic)]
2626
pub enum InvisibleOrigin {
2727
// From the expansion of a metavariable in a declarative macro.
2828
MetaVar(MetaVarKind),
@@ -113,7 +113,7 @@ impl fmt::Display for MetaVarKind {
113113
/// Describes how a sequence of token trees is delimited.
114114
/// Cannot use `proc_macro::Delimiter` directly because this
115115
/// structure should implement some additional traits.
116-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
116+
#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]
117117
pub enum Delimiter {
118118
/// `( ... )`
119119
Parenthesis,
@@ -175,7 +175,7 @@ impl Delimiter {
175175
// type. This means that float literals like `1f32` are classified by this type
176176
// as `Int`. Only upon conversion to `ast::LitKind` will such a literal be
177177
// given the `Float` kind.
178-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
178+
#[derive(Clone, Copy, PartialEq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
179179
pub enum LitKind {
180180
Bool, // AST only, must never appear in a `Token`
181181
Byte,
@@ -192,7 +192,7 @@ pub enum LitKind {
192192
}
193193

194194
/// A literal token.
195-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
195+
#[derive(Clone, Copy, PartialEq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
196196
pub struct Lit {
197197
pub kind: LitKind,
198198
pub symbol: Symbol,
@@ -338,7 +338,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
338338
.contains(&name)
339339
}
340340

341-
#[derive(PartialEq, Encodable, Decodable, Debug, Copy, Clone, HashStable_Generic)]
341+
#[derive(PartialEq, Encodable, Decodable, Hash, Debug, Copy, Clone, HashStable_Generic)]
342342
pub enum IdentIsRaw {
343343
No,
344344
Yes,
@@ -356,7 +356,7 @@ impl From<IdentIsRaw> for bool {
356356
}
357357
}
358358

359-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
359+
#[derive(Clone, Copy, PartialEq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
360360
pub enum TokenKind {
361361
/* Expression-operator symbols. */
362362
/// `=`
@@ -506,7 +506,7 @@ pub enum TokenKind {
506506
Eof,
507507
}
508508

509-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
509+
#[derive(Clone, Copy, PartialEq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
510510
pub struct Token {
511511
pub kind: TokenKind,
512512
pub span: Span,

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//! ownership of the original.
1515
1616
use std::borrow::Cow;
17+
use std::hash::Hash;
1718
use std::ops::Range;
1819
use std::sync::Arc;
1920
use std::{cmp, fmt, iter, mem};
@@ -31,7 +32,7 @@ use crate::token::{self, Delimiter, Token, TokenKind};
3132
use crate::{AttrVec, Attribute};
3233

3334
/// Part of a `TokenStream`.
34-
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
35+
#[derive(Debug, Clone, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]
3536
pub enum TokenTree {
3637
/// A single token. Should never be `OpenDelim` or `CloseDelim`, because
3738
/// delimiters are implicitly represented by `Delimited`.
@@ -557,14 +558,14 @@ pub struct AttrsTarget {
557558
}
558559

559560
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
560-
#[derive(Clone, Debug, Default, Encodable, Decodable)]
561+
#[derive(Clone, Debug, Default, Hash, Encodable, Decodable)]
561562
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
562563

563564
/// Indicates whether a token can join with the following token to form a
564565
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
565566
/// guide pretty-printing, which is where the `JointHidden` value (which isn't
566567
/// part of `proc_macro::Spacing`) comes in useful.
567-
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
568+
#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]
568569
pub enum Spacing {
569570
/// The token cannot join with the following token to form a compound
570571
/// token.
@@ -977,7 +978,7 @@ impl TokenCursor {
977978
}
978979
}
979980

980-
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)]
981+
#[derive(Debug, Copy, Clone, PartialEq, Hash, Encodable, Decodable, HashStable_Generic, Walkable)]
981982
pub struct DelimSpan {
982983
pub open: Span,
983984
pub close: Span,
@@ -1001,7 +1002,7 @@ impl DelimSpan {
10011002
}
10021003
}
10031004

1004-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
1005+
#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]
10051006
pub struct DelimSpacing {
10061007
pub open: Spacing,
10071008
pub close: Spacing,

compiler/rustc_expand/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ rustc_hir = { path = "../rustc_hir" }
2121
rustc_lexer = { path = "../rustc_lexer" }
2222
rustc_lint_defs = { path = "../rustc_lint_defs" }
2323
rustc_macros = { path = "../rustc_macros" }
24+
rustc_middle = { path = "../rustc_middle" }
2425
rustc_parse = { path = "../rustc_parse" }
2526
# We must use the proc_macro version that we will compile proc-macros against,
2627
# not the one from our own sysroot.
2728
rustc_proc_macro = { path = "../rustc_proc_macro" }
2829
rustc_serialize = { path = "../rustc_serialize" }
2930
rustc_session = { path = "../rustc_session" }
3031
rustc_span = { path = "../rustc_span" }
32+
scoped-tls = "1.0"
3133
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3234
thin-vec = "0.2.12"
3335
tracing = "0.1"

compiler/rustc_expand/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ pub mod module;
3131
#[allow(rustc::untranslatable_diagnostic)]
3232
pub mod proc_macro;
3333

34+
pub fn provide(providers: &mut rustc_middle::util::Providers) {
35+
providers.derive_macro_expansion = proc_macro::provide_derive_macro_expansion;
36+
}
37+
3438
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

0 commit comments

Comments
 (0)