Skip to content

Remove Spans from HIR -- 2/N -- Small HIR nodes #73094

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
625594f
Remove useless Clone bound in IndexVec.
cjgillot May 19, 2020
6758a85
Introduce HirIdVec.
cjgillot May 19, 2020
0b793a3
Collect spans during lowering.
cjgillot May 1, 2020
e69a8df
Introduce a query for HIR spans.
cjgillot May 1, 2020
0d98c91
Don't pass spans in hir::map::blocks.
cjgillot May 2, 2020
3947c9e
Stop passing the Span in HIR visiting.
cjgillot May 2, 2020
973d19b
Pass HirId in save_analysis.
cjgillot Jun 7, 2020
700d697
Remove Span parameter from HIR collector.
cjgillot Jun 3, 2020
05dc82a
Fix fulldeps tests.
cjgillot Dec 13, 2020
7b9999c
Fix clippy.
cjgillot Dec 13, 2020
3dd2859
Remove span from hir::Param.
cjgillot May 1, 2020
5dada24
Remove span from hir::Variant.
cjgillot May 1, 2020
e92e9f7
Remove span from hir::StructField.
cjgillot May 1, 2020
f94bbef
Remove span from hir::Stmt.
cjgillot May 1, 2020
2bc251c
Remove span from hir::Block.
cjgillot May 1, 2020
fcae632
Remove span from hir::MacroDef.
cjgillot May 2, 2020
1641026
Remove span from hir::GenericParam.
cjgillot May 2, 2020
521bc45
Remove span from hir::Arm.
cjgillot May 2, 2020
0373228
Remove span from hir::FieldPat.
cjgillot May 2, 2020
afc6e69
Remove span from hir::Local.
cjgillot May 2, 2020
732ae69
Remove span from hir::Pat.
cjgillot May 2, 2020
96b8564
Remove span from hir::Field.
cjgillot May 2, 2020
e6c0698
Remove GenericArg::span.
cjgillot May 3, 2020
4491f82
Remove Span from hir::TypeBinding.
cjgillot May 8, 2020
fdd2c7d
Remove Span from hir::ConstArg.
cjgillot Jun 1, 2020
ba8fc92
Remove Span from hir::TraitItemRef.
cjgillot Jun 1, 2020
272df28
Remove Span from hir::ImplItemRef.
cjgillot Jun 1, 2020
a0b4ad1
Remove span from hir::ForeignItemRef.
cjgillot Dec 11, 2020
b604b5e
Fix fulldeps tests.
cjgillot May 9, 2020
7ec01a6
Fortify find_entry.
cjgillot Dec 13, 2020
304bdec
Remove Span from hir::CrateItem.
cjgillot Dec 10, 2020
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
50 changes: 21 additions & 29 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_session::parse::feature_err;
use rustc_span::hygiene::ForLoopLoc;
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned, DUMMY_SP};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_target::asm;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -229,6 +229,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Include parens in span, but only if it is a super-span.
if e.span.contains(ex.span) {
ex.span = e.span;
self.spans[ex.hir_id] = e.span;
}
// Merge attributes into the inner expression.
let mut attrs: Vec<_> = e.attrs.iter().map(|a| self.lower_attr(a)).collect();
Expand All @@ -246,7 +247,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
};

hir::Expr {
hir_id: self.lower_node_id(e.id),
hir_id: self.lower_node_id(e.id, e.span),
kind,
span: e.span,
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
Expand Down Expand Up @@ -514,12 +515,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
});
hir::Arm {
hir_id: self.next_id(),
hir_id: self.next_id(arm.span),
attrs: self.lower_attrs(&arm.attrs),
pat,
guard,
body: self.lower_expr(&arm.body),
span: arm.span,
}
}

Expand Down Expand Up @@ -548,7 +548,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

// Resume argument type. We let the compiler infer this to simplify the lowering. It is
// fully constrained by `future::from_generator`.
let input_ty = hir::Ty { hir_id: self.next_id(), kind: hir::TyKind::Infer, span };
let input_ty = hir::Ty { hir_id: self.next_id(span), kind: hir::TyKind::Infer, span };

// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
let decl = self.arena.alloc(hir::FnDecl {
Expand All @@ -564,7 +564,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 { attrs: &[], hir_id: self.next_id(span), pat, ty_span: span };
let params = arena_vec![self; param];

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

// `::std::task::Poll::Ready(result) => break result`
let loop_node_id = self.resolver.next_node_id();
let loop_hir_id = self.lower_node_id(loop_node_id);
let loop_hir_id = self.lower_node_id(loop_node_id, span);
let ready_arm = {
let x_ident = Ident::with_dummy_span(sym::result);
let (x_pat, x_pat_hid) = self.pat_ident(span, x_ident);
Expand Down Expand Up @@ -1008,11 +1008,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
let field_pats = self.arena.alloc_from_iter(fields.iter().map(|f| {
let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments);
hir::FieldPat {
hir_id: self.next_id(),
hir_id: self.next_id(f.span),
ident: f.ident,
pat,
is_shorthand: f.is_shorthand,
span: f.span,
}
}));
let qpath = self.lower_qpath(
Expand Down Expand Up @@ -1149,7 +1148,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let target_id = match destination {
Some((id, _)) => {
if let Some(loop_id) = self.resolver.get_label_res(id) {
Ok(self.lower_node_id(loop_id))
Ok(self.lower_node_id(loop_id, DUMMY_SP))
} else {
Err(hir::LoopIdError::UnresolvedLabel)
}
Expand All @@ -1158,7 +1157,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
.loop_scopes
.last()
.cloned()
.map(|id| Ok(self.lower_node_id(id)))
.map(|id| Ok(self.lower_node_id(id, DUMMY_SP)))
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)),
};
hir::Destination { label: destination.map(|(_, label)| label), target_id }
Expand Down Expand Up @@ -1554,10 +1553,9 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_field(&mut self, f: &Field) -> hir::Field<'hir> {
hir::Field {
hir_id: self.next_id(),
hir_id: self.next_id(f.span),
ident: f.ident,
expr: self.lower_expr(&f.expr),
span: f.span,
is_shorthand: f.is_shorthand,
}
}
Expand Down Expand Up @@ -1619,6 +1617,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
None,
);
head.span = desugared_span;
self.spans[head.hir_id] = desugared_span;

let iter = Ident::with_dummy_span(sym::iter);

Expand Down Expand Up @@ -1705,7 +1704,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `[opt_ident]: loop { ... }`
let kind = hir::ExprKind::Loop(loop_block, opt_label, hir::LoopSource::ForLoop);
let loop_expr = self.arena.alloc(hir::Expr {
hir_id: self.lower_node_id(e.id),
hir_id: self.lower_node_id(e.id, e.span),
kind,
span: e.span,
attrs: ThinVec::new(),
Expand Down Expand Up @@ -1832,7 +1831,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let thin_attrs = ThinVec::from(attrs);
let catch_scope = self.catch_scopes.last().copied();
let ret_expr = if let Some(catch_node) = catch_scope {
let target_id = Ok(self.lower_node_id(catch_node));
let target_id = Ok(self.lower_node_id(catch_node, DUMMY_SP));
self.arena.alloc(self.expr(
try_span,
hir::ExprKind::Break(
Expand Down Expand Up @@ -2005,8 +2004,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
let hir_id = self.next_id();
let span = expr.span;
let hir_id = self.next_id(span);
self.expr(
span,
hir::ExprKind::Block(
Expand All @@ -2015,7 +2014,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
expr: Some(expr),
hir_id,
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
span,
targeted_by_break: false,
}),
None,
Expand All @@ -2035,7 +2033,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
b: &'hir hir::Block<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
self.expr(b.span, hir::ExprKind::Block(b, None), attrs)
let span = self.spans[b.hir_id];
self.expr(span, hir::ExprKind::Block(b, None), attrs)
}

pub(super) fn expr(
Expand All @@ -2044,21 +2043,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
kind: hir::ExprKind<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
hir::Expr { hir_id: self.next_id(), kind, span, attrs }
hir::Expr { hir_id: self.next_id(span), kind, span, attrs }
}

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 }
hir::Field { hir_id: self.next_id(span), ident, 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(expr.span), attrs: &[], pat, guard: None, body: expr }
}
}
Loading