Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store HIR attributes in a side table #79519

Merged
merged 38 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
736fc96
Remove useless Clone bound in IndexVec.
cjgillot May 19, 2020
d50ca3c
Introduce HirIdVec.
cjgillot May 19, 2020
1fb257b
Collect attributes during HIR lowering.
cjgillot Nov 24, 2020
4a21af6
Take a slice in stmt_let_pat.
cjgillot Jan 4, 2021
b84bdf1
Access attrs directly from HirId in rustc_lint::late.
cjgillot Nov 25, 2020
7e16e1e
Access attrs directly from HirId in rustc_lint::levels.
cjgillot Nov 25, 2020
7b1dd1a
Access attrs directly from HirId in rustc_passes::check_attr.
cjgillot Nov 25, 2020
0c88350
Access attrs directly from HirId in rustc_incremental::assert_dep_graph.
cjgillot Nov 26, 2020
f8514aa
Access attrs directly from HirId in rustc_passes::stability.
cjgillot Nov 26, 2020
a50454d
Access attrs directly from HirId in rustc_passes::dead.
cjgillot Nov 26, 2020
260aa9f
Access attrs directly from HirId in rustc_passes::lang_items.
cjgillot Nov 26, 2020
662f11a
Access attrs directly from HirId in rustc_lint::builtin.
cjgillot Nov 26, 2020
99ba08e
Access attrs directly from HirId in rustc_passes::diagnostic_item.
cjgillot Nov 26, 2020
3137f81
Access attrs directly from HirId in rustdoc::doctest.
cjgillot Feb 18, 2021
f5dc5dc
Simplify clippy author.
cjgillot Dec 6, 2020
8e81605
Do not store attrs in FnKind.
cjgillot Nov 27, 2020
4bb07be
Visit attributes in one go.
cjgillot Nov 25, 2020
ff79ad3
Remove hir::StmtKind::attrs.
cjgillot Nov 25, 2020
7ea1eac
Remove hir::Local::attrs.
cjgillot Nov 25, 2020
fd8a021
Remove hir::GenericParam::attrs.
cjgillot Nov 27, 2020
c05c902
Remove hir::MacroDef::attrs.
cjgillot Feb 18, 2021
a987bbb
Remove hir::Crate::attrs.
cjgillot Nov 26, 2020
96788df
Remove hir::Arm::attrs.
cjgillot Nov 26, 2020
a0a4611
Remove hir::Param::attrs.
cjgillot Nov 26, 2020
3c0afc3
Remove hir::Variant::attrs.
cjgillot Nov 26, 2020
c298744
Remove hir::StructField::attrs.
cjgillot Nov 26, 2020
4bab93a
Remove hir::ForeignItem::attrs.
cjgillot Nov 26, 2020
c49359a
Remove hir::TraitItem::attrs.
cjgillot Nov 27, 2020
5474f17
Remove hir::ImplItem::attrs.
cjgillot Nov 27, 2020
c701872
Remove hir::Item::attrs.
cjgillot Jan 24, 2021
fb753cc
Remove hir::Expr::attrs.
cjgillot Nov 27, 2020
6b5d2de
Bless tests.
cjgillot Nov 28, 2020
27ef0ee
Track HirId when visiting attributes.
cjgillot Dec 5, 2020
12ce80a
Fix ui-fulldeps tests.
cjgillot Dec 5, 2020
2658fb7
Alias attributes of hir::Stmt.
cjgillot Dec 6, 2020
90a562c
Deduplicate unchecked_attrs errors.
cjgillot Dec 7, 2020
38d9d09
Use BTreeMap to store attributes.
cjgillot Jan 24, 2021
77c0f21
Rebase fallout.
cjgillot Feb 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 30 additions & 43 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
ex.span = e.span;
}
// Merge attributes into the inner expression.
let mut attrs: Vec<_> = e.attrs.iter().map(|a| self.lower_attr(a)).collect();
attrs.extend::<Vec<_>>(ex.attrs.into());
ex.attrs = attrs.into();
if !e.attrs.is_empty() {
let old_attrs = self.attrs.get(&ex.hir_id).map(|la| *la).unwrap_or(&[]);
self.attrs.insert(
ex.hir_id,
&*self.arena.alloc_from_iter(
e.attrs
.iter()
.map(|a| self.lower_attr(a))
.chain(old_attrs.iter().cloned()),
),
);
}
return ex;
}

Expand All @@ -272,12 +281,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::MacCall(_) => panic!("{:?} shouldn't exist here", e.span),
};

hir::Expr {
hir_id: self.lower_node_id(e.id),
kind,
span: e.span,
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
}
let hir_id = self.lower_node_id(e.id);
self.lower_attrs(hir_id, &e.attrs);
hir::Expr { hir_id, kind, span: e.span }
})
}

Expand Down Expand Up @@ -618,14 +624,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::Guard::If(self.lower_expr(cond))
}
});
hir::Arm {
hir_id: self.next_id(),
attrs: self.lower_attrs(&arm.attrs),
pat,
guard,
body: self.lower_expr(&arm.body),
span: arm.span,
}
let hir_id = self.next_id();
self.lower_attrs(hir_id, &arm.attrs);
hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span }
}

/// Lower an `async` construct to a generator that is then wrapped so it implements `Future`.
Expand Down Expand Up @@ -669,7 +670,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Ident::with_dummy_span(sym::_task_context),
hir::BindingAnnotation::Mutable,
);
let param = hir::Param { attrs: &[], hir_id: self.next_id(), pat, ty_span: span, span };
let param = hir::Param { hir_id: self.next_id(), pat, ty_span: span, span };
let params = arena_vec![self; param];

let body_id = self.lower_body(move |this| {
Expand All @@ -690,12 +691,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
Some(hir::Movability::Static),
);
let generator = hir::Expr {
hir_id: self.lower_node_id(closure_node_id),
kind: generator_kind,
span,
attrs: ThinVec::new(),
};
let generator =
hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span };

// `future::from_generator`:
let unstable_span =
Expand Down Expand Up @@ -849,7 +846,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir_id: loop_hir_id,
kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span),
span,
attrs: ThinVec::new(),
});

// mut pinned => loop { ... }
Expand Down Expand Up @@ -1026,7 +1022,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

// Introduce a `let` for destructuring: `let (lhs1, lhs2) = t`.
let destructure_let = self.stmt_let_pat(
ThinVec::new(),
None,
whole_span,
Some(rhs),
pat,
Expand Down Expand Up @@ -1785,7 +1781,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

// `let mut __next`
let next_let = self.stmt_let_pat(
ThinVec::new(),
None,
desugared_span,
None,
next_pat,
Expand All @@ -1795,7 +1791,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `let <pat> = __next`
let pat = self.lower_pat(pat);
let pat_let = self.stmt_let_pat(
ThinVec::new(),
None,
desugared_span,
Some(next_expr),
pat,
Expand All @@ -1819,12 +1815,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::LoopSource::ForLoop,
e.span.with_hi(orig_head_span.hi()),
);
let loop_expr = self.arena.alloc(hir::Expr {
hir_id: self.lower_node_id(e.id),
kind,
span: e.span,
attrs: ThinVec::new(),
});
let loop_expr =
self.arena.alloc(hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span });

// `mut iter => { ... }`
let iter_arm = self.arm(iter_pat, loop_expr);
Expand Down Expand Up @@ -2159,21 +2151,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
kind: hir::ExprKind<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
hir::Expr { hir_id: self.next_id(), kind, span, attrs }
let hir_id = self.next_id();
self.lower_attrs(hir_id, &attrs);
hir::Expr { hir_id, kind, span }
}

fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {
hir::Field { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
}

fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
hir::Arm {
hir_id: self.next_id(),
attrs: &[],
pat,
guard: None,
span: expr.span,
body: expr,
}
hir::Arm { hir_id: self.next_id(), pat, guard: None, span: expr.span, body: expr }
}
}
Loading