Use Rc<[Symbol]>
instead of Vec<Symbol>
to reduce # of allocs
This commit is contained in:
parent
1dba7cb202
commit
b681433b9d
19 changed files with 54 additions and 50 deletions
|
@ -52,6 +52,7 @@ use crate::util::nodemap::{DefIdMap, NodeMap};
|
|||
use std::collections::{BTreeSet, BTreeMap};
|
||||
use std::fmt::Debug;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use smallvec::SmallVec;
|
||||
use syntax::attr;
|
||||
use syntax::ast;
|
||||
|
@ -687,7 +688,7 @@ impl<'a> LoweringContext<'a> {
|
|||
&self,
|
||||
reason: CompilerDesugaringKind,
|
||||
span: Span,
|
||||
allow_internal_unstable: Vec<Symbol>,
|
||||
allow_internal_unstable: Option<Rc<[Symbol]>>,
|
||||
) -> Span {
|
||||
let mark = Mark::fresh(Mark::root());
|
||||
mark.set_expn_info(source_map::ExpnInfo {
|
||||
|
@ -974,9 +975,9 @@ impl<'a> LoweringContext<'a> {
|
|||
let unstable_span = self.mark_span_with_reason(
|
||||
CompilerDesugaringKind::Async,
|
||||
span,
|
||||
vec![
|
||||
Some(vec![
|
||||
Symbol::intern("gen_future"),
|
||||
],
|
||||
].into()),
|
||||
);
|
||||
let gen_future = self.expr_std_path(
|
||||
unstable_span, &["future", "from_generator"], None, ThinVec::new());
|
||||
|
@ -1376,7 +1377,7 @@ impl<'a> LoweringContext<'a> {
|
|||
let exist_ty_span = self.mark_span_with_reason(
|
||||
CompilerDesugaringKind::ExistentialReturnType,
|
||||
span,
|
||||
Vec::new(), // doesn'c actually allow anything unstable
|
||||
None,
|
||||
);
|
||||
|
||||
let exist_ty_def_index = self
|
||||
|
@ -3944,9 +3945,9 @@ impl<'a> LoweringContext<'a> {
|
|||
let unstable_span = this.mark_span_with_reason(
|
||||
CompilerDesugaringKind::TryBlock,
|
||||
body.span,
|
||||
vec![
|
||||
Some(vec![
|
||||
Symbol::intern("try_trait"),
|
||||
],
|
||||
].into()),
|
||||
);
|
||||
let mut block = this.lower_block(body, true).into_inner();
|
||||
let tail = block.expr.take().map_or_else(
|
||||
|
@ -4382,7 +4383,7 @@ impl<'a> LoweringContext<'a> {
|
|||
let desugared_span = self.mark_span_with_reason(
|
||||
CompilerDesugaringKind::ForLoop,
|
||||
head_sp,
|
||||
Vec::new(),
|
||||
None,
|
||||
);
|
||||
|
||||
let iter = self.str_to_ident("iter");
|
||||
|
@ -4548,9 +4549,9 @@ impl<'a> LoweringContext<'a> {
|
|||
let unstable_span = self.mark_span_with_reason(
|
||||
CompilerDesugaringKind::QuestionMark,
|
||||
e.span,
|
||||
vec![
|
||||
Some(vec![
|
||||
Symbol::intern("try_trait")
|
||||
],
|
||||
].into()),
|
||||
);
|
||||
|
||||
// `Try::into_result(<expr>)`
|
||||
|
|
|
@ -91,9 +91,9 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
|
|||
call_site: item.span, // use the call site of the static
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern(name)),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("rustc_attrs"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -570,7 +570,7 @@ impl<'a> CrateLoader<'a> {
|
|||
ProcMacro::Bang { name, client } => {
|
||||
(name, SyntaxExtension::ProcMacro {
|
||||
expander: Box::new(BangProcMacro { client }),
|
||||
allow_internal_unstable: Vec::new(),
|
||||
allow_internal_unstable: None,
|
||||
edition: root.edition,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -425,9 +425,9 @@ impl cstore::CStore {
|
|||
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
|
||||
let ext = SyntaxExtension::ProcMacro {
|
||||
expander: Box::new(BangProcMacro { client }),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("proc_macro_def_site"),
|
||||
],
|
||||
].into()),
|
||||
edition: data.root.edition,
|
||||
};
|
||||
return LoadedMacro::ProcMacro(Lrc::new(ext));
|
||||
|
|
|
@ -126,7 +126,7 @@ impl<'a> Registry<'a> {
|
|||
self.register_syntax_extension(Symbol::intern(name), NormalTT {
|
||||
expander: Box::new(expander),
|
||||
def_info: None,
|
||||
allow_internal_unstable: Vec::new(),
|
||||
allow_internal_unstable: None,
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
unstable_feature: None,
|
||||
|
|
|
@ -622,7 +622,7 @@ pub enum SyntaxExtension {
|
|||
ProcMacro {
|
||||
expander: Box<dyn ProcMacro + sync::Sync + sync::Send>,
|
||||
/// Whitelist of unstable features that are treated as stable inside this macro
|
||||
allow_internal_unstable: Vec<Symbol>,
|
||||
allow_internal_unstable: Option<Rc<[Symbol]>>,
|
||||
edition: Edition,
|
||||
},
|
||||
|
||||
|
@ -642,7 +642,7 @@ pub enum SyntaxExtension {
|
|||
/// directly use `#[unstable]` things.
|
||||
///
|
||||
/// Only allows things that require a feature gate in the given whitelist
|
||||
allow_internal_unstable: Vec<Symbol>,
|
||||
allow_internal_unstable: Option<Rc<[Symbol]>>,
|
||||
/// Whether the contents of the macro can use `unsafe`
|
||||
/// without triggering the `unsafe_code` lint.
|
||||
allow_internal_unsafe: bool,
|
||||
|
@ -660,7 +660,7 @@ pub enum SyntaxExtension {
|
|||
IdentTT {
|
||||
expander: Box<dyn IdentMacroExpander + sync::Sync + sync::Send>,
|
||||
span: Option<Span>,
|
||||
allow_internal_unstable: Vec<Symbol>,
|
||||
allow_internal_unstable: Option<Rc<[Symbol]>>,
|
||||
},
|
||||
|
||||
/// An attribute-like procedural macro. TokenStream -> TokenStream.
|
||||
|
|
|
@ -58,10 +58,10 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
|
|||
call_site: span,
|
||||
def_site: None,
|
||||
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("rustc_attrs"),
|
||||
Symbol::intern("structural_match"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -558,7 +558,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
call_site: attr.span,
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern(&attr.path.to_string())),
|
||||
allow_internal_unstable: Vec::new(),
|
||||
allow_internal_unstable: None,
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: ext.edition(),
|
||||
|
@ -758,7 +758,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
let opt_expanded = match *ext {
|
||||
DeclMacro { ref expander, def_info, edition, .. } => {
|
||||
if let Err(dummy_span) = validate_and_set_expn_info(self, def_info.map(|(_, s)| s),
|
||||
Vec::new(), false, false, None,
|
||||
None, false, false, None,
|
||||
edition) {
|
||||
dummy_span
|
||||
} else {
|
||||
|
@ -919,7 +919,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
call_site: span,
|
||||
def_site: None,
|
||||
format: MacroAttribute(pretty_name),
|
||||
allow_internal_unstable: Vec::new(),
|
||||
allow_internal_unstable: None,
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: ext.edition(),
|
||||
|
@ -938,12 +938,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
Some(invoc.fragment_kind.expect_from_annotatables(items))
|
||||
}
|
||||
BuiltinDerive(func) => {
|
||||
expn_info.allow_internal_unstable = vec![
|
||||
expn_info.allow_internal_unstable = Some(vec![
|
||||
Symbol::intern("rustc_attrs"),
|
||||
Symbol::intern("derive_clone_copy"),
|
||||
Symbol::intern("derive_eq"),
|
||||
Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize
|
||||
];
|
||||
].into());
|
||||
invoc.expansion_data.mark.set_expn_info(expn_info);
|
||||
let span = span.with_ctxt(self.cx.backtrace());
|
||||
let mut items = Vec::new();
|
||||
|
|
|
@ -377,13 +377,13 @@ pub fn compile(
|
|||
|
||||
if body.legacy {
|
||||
let allow_internal_unstable = attr::find_by_name(&def.attrs, "allow_internal_unstable")
|
||||
.map_or(Vec::new(), |attr| attr
|
||||
.map(|attr| attr
|
||||
.meta_item_list()
|
||||
.map(|list| list.iter()
|
||||
.map(|it| it.name().unwrap_or_else(|| sess.span_diagnostic.span_bug(
|
||||
it.span, "allow internal unstable expects feature names",
|
||||
)))
|
||||
.collect()
|
||||
.collect::<Vec<Symbol>>().into()
|
||||
)
|
||||
.unwrap_or_else(|| {
|
||||
sess.span_diagnostic.span_warn(
|
||||
|
@ -391,7 +391,7 @@ pub fn compile(
|
|||
future this will become a hard error. Please use `allow_internal_unstable(\
|
||||
foo, bar)` to only allow the `foo` and `bar` features",
|
||||
);
|
||||
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")]
|
||||
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")].into()
|
||||
})
|
||||
);
|
||||
let allow_internal_unsafe = attr::contains_name(&def.attrs, "allow_internal_unsafe");
|
||||
|
|
|
@ -20,9 +20,9 @@ fn ignored_span(sp: Span) -> Span {
|
|||
call_site: DUMMY_SP,
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern("std_inject")),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("prelude_import"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -285,11 +285,11 @@ fn generate_test_harness(sess: &ParseSess,
|
|||
call_site: DUMMY_SP,
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern("test_case")),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("main"),
|
||||
Symbol::intern("test"),
|
||||
Symbol::intern("rustc_attrs"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -138,13 +138,14 @@ fn call_intrinsic(cx: &ExtCtxt<'_>,
|
|||
-> P<ast::Expr> {
|
||||
let intrinsic_allowed_via_allow_internal_unstable = cx
|
||||
.current_expansion.mark.expn_info().unwrap()
|
||||
.allow_internal_unstable.iter()
|
||||
.any(|&s| s == "core_intrinsics");
|
||||
.allow_internal_unstable.map_or(false, |features| features.iter().any(|&s|
|
||||
s == "core_intrinsics"
|
||||
));
|
||||
if intrinsic_allowed_via_allow_internal_unstable {
|
||||
span = span.with_ctxt(cx.backtrace());
|
||||
} else { // Avoid instability errors with user defined curstom derives, cc #36316
|
||||
let mut info = cx.current_expansion.mark.expn_info().unwrap();
|
||||
info.allow_internal_unstable = vec![Symbol::intern("core_intrinsics")];
|
||||
info.allow_internal_unstable = Some(vec![Symbol::intern("core_intrinsics")].into());
|
||||
let mark = Mark::fresh(Mark::root());
|
||||
mark.set_expn_info(info);
|
||||
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
|
|||
NormalTT {
|
||||
expander: Box::new($f as MacroExpanderFn),
|
||||
def_info: None,
|
||||
allow_internal_unstable: Vec::new(),
|
||||
allow_internal_unstable: None,
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
unstable_feature: None,
|
||||
|
@ -103,9 +103,9 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
|
|||
NormalTT {
|
||||
expander: Box::new(format::expand_format_args),
|
||||
def_info: None,
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("fmt_internals"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
unstable_feature: None,
|
||||
|
@ -115,9 +115,9 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
|
|||
NormalTT {
|
||||
expander: Box::new(format::expand_format_args_nl),
|
||||
def_info: None,
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("fmt_internals"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
unstable_feature: None,
|
||||
|
|
|
@ -333,10 +333,10 @@ fn mk_decls(
|
|||
call_site: DUMMY_SP,
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern("proc_macro")),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("rustc_attrs"),
|
||||
Symbol::intern("proc_macro_internals"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -66,10 +66,10 @@ pub fn expand_test_or_bench(
|
|||
call_site: DUMMY_SP,
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern("test")),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("rustc_attrs"),
|
||||
Symbol::intern("test"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -41,10 +41,10 @@ pub fn expand(
|
|||
call_site: DUMMY_SP,
|
||||
def_site: None,
|
||||
format: MacroAttribute(Symbol::intern("test_case")),
|
||||
allow_internal_unstable: vec![
|
||||
allow_internal_unstable: Some(vec![
|
||||
Symbol::intern("test"),
|
||||
Symbol::intern("rustc_attrs"),
|
||||
],
|
||||
].into()),
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
edition: hygiene::default_edition(),
|
||||
|
|
|
@ -13,6 +13,7 @@ use crate::symbol::{keywords, Symbol};
|
|||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use std::{fmt, mem};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A SyntaxContext represents a chain of macro expansions (represented by marks).
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
|
||||
|
@ -553,7 +554,7 @@ pub struct ExpnInfo {
|
|||
/// List of #[unstable]/feature-gated features that the macro is allowed to use
|
||||
/// internally without forcing the whole crate to opt-in
|
||||
/// to them.
|
||||
pub allow_internal_unstable: Vec<Symbol>,
|
||||
pub allow_internal_unstable: Option<Rc<[Symbol]>>,
|
||||
/// Whether the macro is allowed to use `unsafe` internally
|
||||
/// even if the user crate has `#![forbid(unsafe_code)]`.
|
||||
pub allow_internal_unsafe: bool,
|
||||
|
|
|
@ -389,8 +389,9 @@ impl Span {
|
|||
match self.ctxt().outer().expn_info() {
|
||||
Some(info) => info
|
||||
.allow_internal_unstable
|
||||
.iter()
|
||||
.any(|&f| f == feature || f == "allow_internal_unstable_backcompat_hack"),
|
||||
.map_or(false, |features| features.iter().any(|&f|
|
||||
f == feature || f == "allow_internal_unstable_backcompat_hack"
|
||||
)),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||
NormalTT {
|
||||
expander: Box::new(Expander { args: args, }),
|
||||
def_info: None,
|
||||
allow_internal_unstable: Vec::new(),
|
||||
allow_internal_unstable: None,
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
unstable_feature: None,
|
||||
|
|
Loading…
Reference in a new issue