Skip to content

Commit b681433

Browse files
committed
Use Rc<[Symbol]> instead of Vec<Symbol> to reduce # of allocs
1 parent 1dba7cb commit b681433

File tree

19 files changed

+54
-50
lines changed

19 files changed

+54
-50
lines changed

src/librustc/hir/lowering.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use crate::util::nodemap::{DefIdMap, NodeMap};
5252
use std::collections::{BTreeSet, BTreeMap};
5353
use std::fmt::Debug;
5454
use std::mem;
55+
use std::rc::Rc;
5556
use smallvec::SmallVec;
5657
use syntax::attr;
5758
use syntax::ast;
@@ -687,7 +688,7 @@ impl<'a> LoweringContext<'a> {
687688
&self,
688689
reason: CompilerDesugaringKind,
689690
span: Span,
690-
allow_internal_unstable: Vec<Symbol>,
691+
allow_internal_unstable: Option<Rc<[Symbol]>>,
691692
) -> Span {
692693
let mark = Mark::fresh(Mark::root());
693694
mark.set_expn_info(source_map::ExpnInfo {
@@ -974,9 +975,9 @@ impl<'a> LoweringContext<'a> {
974975
let unstable_span = self.mark_span_with_reason(
975976
CompilerDesugaringKind::Async,
976977
span,
977-
vec![
978+
Some(vec![
978979
Symbol::intern("gen_future"),
979-
],
980+
].into()),
980981
);
981982
let gen_future = self.expr_std_path(
982983
unstable_span, &["future", "from_generator"], None, ThinVec::new());
@@ -1376,7 +1377,7 @@ impl<'a> LoweringContext<'a> {
13761377
let exist_ty_span = self.mark_span_with_reason(
13771378
CompilerDesugaringKind::ExistentialReturnType,
13781379
span,
1379-
Vec::new(), // doesn'c actually allow anything unstable
1380+
None,
13801381
);
13811382

13821383
let exist_ty_def_index = self
@@ -3944,9 +3945,9 @@ impl<'a> LoweringContext<'a> {
39443945
let unstable_span = this.mark_span_with_reason(
39453946
CompilerDesugaringKind::TryBlock,
39463947
body.span,
3947-
vec![
3948+
Some(vec![
39483949
Symbol::intern("try_trait"),
3949-
],
3950+
].into()),
39503951
);
39513952
let mut block = this.lower_block(body, true).into_inner();
39523953
let tail = block.expr.take().map_or_else(
@@ -4382,7 +4383,7 @@ impl<'a> LoweringContext<'a> {
43824383
let desugared_span = self.mark_span_with_reason(
43834384
CompilerDesugaringKind::ForLoop,
43844385
head_sp,
4385-
Vec::new(),
4386+
None,
43864387
);
43874388

43884389
let iter = self.str_to_ident("iter");
@@ -4548,9 +4549,9 @@ impl<'a> LoweringContext<'a> {
45484549
let unstable_span = self.mark_span_with_reason(
45494550
CompilerDesugaringKind::QuestionMark,
45504551
e.span,
4551-
vec![
4552+
Some(vec![
45524553
Symbol::intern("try_trait")
4553-
],
4554+
].into()),
45544555
);
45554556

45564557
// `Try::into_result(<expr>)`

src/librustc_allocator/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
9191
call_site: item.span, // use the call site of the static
9292
def_site: None,
9393
format: MacroAttribute(Symbol::intern(name)),
94-
allow_internal_unstable: vec![
94+
allow_internal_unstable: Some(vec![
9595
Symbol::intern("rustc_attrs"),
96-
],
96+
].into()),
9797
allow_internal_unsafe: false,
9898
local_inner_macros: false,
9999
edition: hygiene::default_edition(),

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl<'a> CrateLoader<'a> {
570570
ProcMacro::Bang { name, client } => {
571571
(name, SyntaxExtension::ProcMacro {
572572
expander: Box::new(BangProcMacro { client }),
573-
allow_internal_unstable: Vec::new(),
573+
allow_internal_unstable: None,
574574
edition: root.edition,
575575
})
576576
}

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ impl cstore::CStore {
425425
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
426426
let ext = SyntaxExtension::ProcMacro {
427427
expander: Box::new(BangProcMacro { client }),
428-
allow_internal_unstable: vec![
428+
allow_internal_unstable: Some(vec![
429429
Symbol::intern("proc_macro_def_site"),
430-
],
430+
].into()),
431431
edition: data.root.edition,
432432
};
433433
return LoadedMacro::ProcMacro(Lrc::new(ext));

src/librustc_plugin/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> Registry<'a> {
126126
self.register_syntax_extension(Symbol::intern(name), NormalTT {
127127
expander: Box::new(expander),
128128
def_info: None,
129-
allow_internal_unstable: Vec::new(),
129+
allow_internal_unstable: None,
130130
allow_internal_unsafe: false,
131131
local_inner_macros: false,
132132
unstable_feature: None,

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ pub enum SyntaxExtension {
622622
ProcMacro {
623623
expander: Box<dyn ProcMacro + sync::Sync + sync::Send>,
624624
/// Whitelist of unstable features that are treated as stable inside this macro
625-
allow_internal_unstable: Vec<Symbol>,
625+
allow_internal_unstable: Option<Rc<[Symbol]>>,
626626
edition: Edition,
627627
},
628628

@@ -642,7 +642,7 @@ pub enum SyntaxExtension {
642642
/// directly use `#[unstable]` things.
643643
///
644644
/// Only allows things that require a feature gate in the given whitelist
645-
allow_internal_unstable: Vec<Symbol>,
645+
allow_internal_unstable: Option<Rc<[Symbol]>>,
646646
/// Whether the contents of the macro can use `unsafe`
647647
/// without triggering the `unsafe_code` lint.
648648
allow_internal_unsafe: bool,
@@ -660,7 +660,7 @@ pub enum SyntaxExtension {
660660
IdentTT {
661661
expander: Box<dyn IdentMacroExpander + sync::Sync + sync::Send>,
662662
span: Option<Span>,
663-
allow_internal_unstable: Vec<Symbol>,
663+
allow_internal_unstable: Option<Rc<[Symbol]>>,
664664
},
665665

666666
/// An attribute-like procedural macro. TokenStream -> TokenStream.

src/libsyntax/ext/derive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
5858
call_site: span,
5959
def_site: None,
6060
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
61-
allow_internal_unstable: vec![
61+
allow_internal_unstable: Some(vec![
6262
Symbol::intern("rustc_attrs"),
6363
Symbol::intern("structural_match"),
64-
],
64+
].into()),
6565
allow_internal_unsafe: false,
6666
local_inner_macros: false,
6767
edition: hygiene::default_edition(),

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
558558
call_site: attr.span,
559559
def_site: None,
560560
format: MacroAttribute(Symbol::intern(&attr.path.to_string())),
561-
allow_internal_unstable: Vec::new(),
561+
allow_internal_unstable: None,
562562
allow_internal_unsafe: false,
563563
local_inner_macros: false,
564564
edition: ext.edition(),
@@ -758,7 +758,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
758758
let opt_expanded = match *ext {
759759
DeclMacro { ref expander, def_info, edition, .. } => {
760760
if let Err(dummy_span) = validate_and_set_expn_info(self, def_info.map(|(_, s)| s),
761-
Vec::new(), false, false, None,
761+
None, false, false, None,
762762
edition) {
763763
dummy_span
764764
} else {
@@ -919,7 +919,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
919919
call_site: span,
920920
def_site: None,
921921
format: MacroAttribute(pretty_name),
922-
allow_internal_unstable: Vec::new(),
922+
allow_internal_unstable: None,
923923
allow_internal_unsafe: false,
924924
local_inner_macros: false,
925925
edition: ext.edition(),
@@ -938,12 +938,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
938938
Some(invoc.fragment_kind.expect_from_annotatables(items))
939939
}
940940
BuiltinDerive(func) => {
941-
expn_info.allow_internal_unstable = vec![
941+
expn_info.allow_internal_unstable = Some(vec![
942942
Symbol::intern("rustc_attrs"),
943943
Symbol::intern("derive_clone_copy"),
944944
Symbol::intern("derive_eq"),
945945
Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize
946-
];
946+
].into());
947947
invoc.expansion_data.mark.set_expn_info(expn_info);
948948
let span = span.with_ctxt(self.cx.backtrace());
949949
let mut items = Vec::new();

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,21 +377,21 @@ pub fn compile(
377377

378378
if body.legacy {
379379
let allow_internal_unstable = attr::find_by_name(&def.attrs, "allow_internal_unstable")
380-
.map_or(Vec::new(), |attr| attr
380+
.map(|attr| attr
381381
.meta_item_list()
382382
.map(|list| list.iter()
383383
.map(|it| it.name().unwrap_or_else(|| sess.span_diagnostic.span_bug(
384384
it.span, "allow internal unstable expects feature names",
385385
)))
386-
.collect()
386+
.collect::<Vec<Symbol>>().into()
387387
)
388388
.unwrap_or_else(|| {
389389
sess.span_diagnostic.span_warn(
390390
attr.span, "allow_internal_unstable expects list of feature names. In the \
391391
future this will become a hard error. Please use `allow_internal_unstable(\
392392
foo, bar)` to only allow the `foo` and `bar` features",
393393
);
394-
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")]
394+
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")].into()
395395
})
396396
);
397397
let allow_internal_unsafe = attr::contains_name(&def.attrs, "allow_internal_unsafe");

src/libsyntax/std_inject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ fn ignored_span(sp: Span) -> Span {
2020
call_site: DUMMY_SP,
2121
def_site: None,
2222
format: MacroAttribute(Symbol::intern("std_inject")),
23-
allow_internal_unstable: vec![
23+
allow_internal_unstable: Some(vec![
2424
Symbol::intern("prelude_import"),
25-
],
25+
].into()),
2626
allow_internal_unsafe: false,
2727
local_inner_macros: false,
2828
edition: hygiene::default_edition(),

0 commit comments

Comments
 (0)