Skip to content

Commit 04b6b04

Browse files
committed
Shrink mbe's Op
1 parent 7a7446b commit 04b6b04

File tree

12 files changed

+55
-29
lines changed

12 files changed

+55
-29
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5"
10461046
name = "mbe"
10471047
version = "0.0.0"
10481048
dependencies = [
1049+
"arrayvec",
10491050
"cov-mark",
10501051
"parser",
10511052
"rustc-hash",

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ const PREDEFINED_TOOLS: &[SmolStr] = &[
103103
/// is computed by the `block_def_map` query.
104104
#[derive(Debug, PartialEq, Eq)]
105105
pub struct DefMap {
106+
/// The crate this `DefMap` belongs to.
107+
krate: CrateId,
106108
/// When this is a block def map, this will hold the block id of the block and module that
107109
/// contains this block.
108110
block: Option<BlockInfo>,
109111
/// The modules and their data declared in this crate.
110112
pub modules: Arena<ModuleData>,
111-
krate: CrateId,
112113
/// The prelude module for this crate. This either comes from an import
113114
/// marked with the `prelude_import` attribute, or (in the normal case) from
114115
/// a dependency (`std` or `core`).
@@ -124,6 +125,7 @@ pub struct DefMap {
124125

125126
/// Tracks which custom derives are in scope for an item, to allow resolution of derive helper
126127
/// attributes.
128+
// FIXME: Figure out a better way for the IDE layer to resolve these?
127129
derive_helpers_in_scope: FxHashMap<AstId<ast::Item>, Vec<(Name, MacroId, MacroCallId)>>,
128130

129131
/// The diagnostics that need to be emitted for this crate.

src/tools/rust-analyzer/crates/hir-expand/src/change.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ impl ChangeWithProcMacros {
2525

2626
pub fn apply(self, db: &mut (impl ExpandDatabase + SourceDatabaseExt)) {
2727
self.source_change.apply(db);
28-
if let Some(proc_macros) = self.proc_macros {
28+
if let Some(mut proc_macros) = self.proc_macros {
29+
proc_macros.shrink_to_fit();
2930
db.set_proc_macros_with_durability(Arc::new(proc_macros), Durability::HIGH);
3031
}
3132
if let Some(target_data_layouts) = self.target_data_layouts {

src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ fn iterate_inherent_methods(
13221322
callback: &mut dyn FnMut(ReceiverAdjustments, AssocItemId, bool) -> ControlFlow<()>,
13231323
) -> ControlFlow<()> {
13241324
for &impl_id in impls.for_self_ty(self_ty) {
1325-
for &item in &table.db.impl_data(impl_id).items {
1325+
for &item in table.db.impl_data(impl_id).items.iter() {
13261326
let visible = match is_valid_impl_method_candidate(
13271327
table,
13281328
self_ty,

src/tools/rust-analyzer/crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl Module {
760760
impl_assoc_items_scratch.clear();
761761
}
762762

763-
for &item in &db.impl_data(impl_def.id).items {
763+
for &item in db.impl_data(impl_def.id).items.iter() {
764764
AssocItem::from(item).diagnostics(db, acc, style_lints);
765765
}
766766
}

src/tools/rust-analyzer/crates/hir/src/symbols.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a> SymbolCollector<'a> {
231231
let impl_data = self.db.impl_data(impl_id);
232232
let impl_name = Some(SmolStr::new(impl_data.self_ty.display(self.db).to_string()));
233233
self.with_container_name(impl_name, |s| {
234-
for &assoc_item_id in &impl_data.items {
234+
for &assoc_item_id in impl_data.items.iter() {
235235
s.push_assoc_item(assoc_item_id)
236236
}
237237
})

src/tools/rust-analyzer/crates/mbe/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cov-mark = "2.0.0-pre.1"
1616
rustc-hash.workspace = true
1717
smallvec.workspace = true
1818
tracing.workspace = true
19+
arrayvec.workspace = true
1920

2021
# local deps
2122
syntax.workspace = true

src/tools/rust-analyzer/crates/mbe/src/benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn invocation_fixtures(
170170
Op::Literal(it) => token_trees.push(tt::Leaf::from(it.clone()).into()),
171171
Op::Ident(it) => token_trees.push(tt::Leaf::from(it.clone()).into()),
172172
Op::Punct(puncts) => {
173-
for punct in puncts {
173+
for punct in puncts.as_slice() {
174174
token_trees.push(tt::Leaf::from(*punct).into());
175175
}
176176
}
@@ -187,7 +187,7 @@ fn invocation_fixtures(
187187
}
188188
if i + 1 != cnt {
189189
if let Some(sep) = separator {
190-
match sep {
190+
match &**sep {
191191
Separator::Literal(it) => {
192192
token_trees.push(tt::Leaf::Literal(it.clone()).into())
193193
}

src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//! eof: [a $( a )* a b ·]
6060
//! ```
6161
62-
use std::rc::Rc;
62+
use std::{rc::Rc, sync::Arc};
6363

6464
use smallvec::{smallvec, SmallVec};
6565
use span::{Edition, Span};
@@ -315,7 +315,7 @@ struct MatchState<'t> {
315315
up: Option<Box<MatchState<'t>>>,
316316

317317
/// The separator if we are in a repetition.
318-
sep: Option<Separator>,
318+
sep: Option<Arc<Separator>>,
319319

320320
/// The KleeneOp of this sequence if we are in a repetition.
321321
sep_kind: Option<RepeatKind>,

src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn expand_subtree(
195195
.into(),
196196
),
197197
Op::Punct(puncts) => {
198-
for punct in puncts {
198+
for punct in puncts.as_slice() {
199199
arena.push(
200200
tt::Leaf::from({
201201
let mut it = *punct;
@@ -222,7 +222,7 @@ fn expand_subtree(
222222
}
223223
Op::Repeat { tokens: subtree, kind, separator } => {
224224
let ExpandResult { value: fragment, err: e } =
225-
expand_repeat(ctx, subtree, *kind, separator, arena, marker);
225+
expand_repeat(ctx, subtree, *kind, separator.as_deref(), arena, marker);
226226
err = err.or(e);
227227
push_fragment(ctx, arena, fragment)
228228
}
@@ -383,7 +383,7 @@ fn expand_repeat(
383383
ctx: &mut ExpandCtx<'_>,
384384
template: &MetaTemplate,
385385
kind: RepeatKind,
386-
separator: &Option<Separator>,
386+
separator: Option<&Separator>,
387387
arena: &mut Vec<tt::TokenTree<Span>>,
388388
marker: impl Fn(&mut Span) + Copy,
389389
) -> ExpandResult<Fragment> {

0 commit comments

Comments
 (0)