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

Remove Spans from HIR #72015

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
596450e
Collect spans during lowering.
cjgillot May 1, 2020
1b6618d
Introduce a query for HIR spans.
cjgillot May 1, 2020
166bb39
Don't pass spans in hir::map::blocks.
cjgillot May 2, 2020
46b2dc2
Stop passing the Span in HIR visiting.
cjgillot May 2, 2020
9c1039a
Pass HirId in save_analysis.
cjgillot Jun 7, 2020
7b5f1a3
Remove Span parameter from HIR collector.
cjgillot Jun 3, 2020
07e9c5c
Fix fulldeps tests.
cjgillot Dec 13, 2020
4cff471
Fix clippy.
cjgillot Dec 13, 2020
173048d
Remove span from hir::Param.
cjgillot May 1, 2020
56a6530
Remove span from hir::Variant.
cjgillot May 1, 2020
272a1f2
Remove span from hir::StructField.
cjgillot May 1, 2020
7b8595f
Remove span from hir::Stmt.
cjgillot Mar 6, 2021
a295ae3
Remove span from hir::Block.
cjgillot May 1, 2020
32716ae
Remove span from hir::MacroDef.
cjgillot May 2, 2020
6ec2356
Remove span from hir::GenericParam.
cjgillot May 2, 2020
4f527e9
Remove span from hir::Arm.
cjgillot May 2, 2020
1fcff64
Remove span from hir::FieldPat.
cjgillot May 2, 2020
3cf2fba
Remove span from hir::Local.
cjgillot May 2, 2020
f51da1e
Remove span from hir::Pat.
cjgillot Mar 6, 2021
ec56b9f
Remove span from hir::Field.
cjgillot May 2, 2020
ec5cd74
Remove GenericArg::span.
cjgillot May 3, 2020
66e1a16
Remove Span from hir::TypeBinding.
cjgillot May 8, 2020
a29261d
Remove Span from hir::ConstArg.
cjgillot Jun 1, 2020
56871a5
Remove Span from hir::TraitItemRef.
cjgillot Jun 1, 2020
346176f
Remove Span from hir::ImplItemRef.
cjgillot Jun 1, 2020
6459750
Remove span from hir::ForeignItemRef.
cjgillot Dec 11, 2020
fcdfaf0
Fix fulldeps tests.
cjgillot May 9, 2020
e6d9d4b
Fortify find_entry.
cjgillot Dec 13, 2020
125796b
Remove Span from hir::CrateItem.
cjgillot Dec 10, 2020
7e26fd6
Pass HirId in rustc_typeck::check.
cjgillot May 2, 2020
bdb83e2
Pass HirId in rustc_lint.
cjgillot May 2, 2020
05e913a
Pass HirId in rustc_passes::stability.
cjgillot May 2, 2020
2035593
Pass HirId in rustc_incremental::persist::dirty_clean.
cjgillot Dec 11, 2020
cf99aea
Pass HirId in rustc_passes::check_attr.
cjgillot Dec 11, 2020
85396f8
Pass HirId in rustc_passes::entry.
cjgillot Dec 11, 2020
042bf08
Remove span from hir::Item.
cjgillot Dec 22, 2020
d632f42
Remove span from hir::ForeignItem.
cjgillot Dec 11, 2020
0d9d1e0
Remove Span from hir::Ty.
cjgillot May 8, 2020
e281f67
Remove Span from hir::Expr.
cjgillot May 3, 2020
f065656
Fix fulldeps tests.
cjgillot May 9, 2020
bb40d08
Fix suggestions.
cjgillot Mar 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
75 changes: 40 additions & 35 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Err => hir::ExprKind::Err,
ExprKind::Try(ref sub_expr) => self.lower_expr_try(e.span, sub_expr),
ExprKind::Paren(ref ex) => {
let mut ex = self.lower_expr_mut(ex);
let ex = self.lower_expr_mut(ex);
// Include parens in span, but only if it is a super-span.
if e.span.contains(ex.span) {
ex.span = e.span;
let ex_span = &mut self.spans[ex.hir_id];
if e.span.contains(*ex_span) {
*ex_span = e.span;
}
// Merge attributes into the inner expression.
if !e.attrs.is_empty() {
Expand All @@ -281,9 +282,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::MacCall(_) => panic!("{:?} shouldn't exist here", e.span),
};

let hir_id = self.lower_node_id(e.id);
let hir_id = self.lower_node_id(e.id, e.span);
self.lower_attrs(hir_id, &e.attrs);
hir::Expr { hir_id, kind, span: e.span }
hir::Expr { hir_id, kind }
})
}

Expand Down Expand Up @@ -534,8 +535,11 @@ impl<'hir> LoweringContext<'_, 'hir> {

// Lower condition:
let cond = self.with_loop_condition_scope(|this| this.lower_expr(cond));
let span_block =
self.mark_span_with_reason(DesugaringKind::CondTemporary, cond.span, None);
let span_block = self.mark_span_with_reason(
DesugaringKind::CondTemporary,
self.spans[cond.hir_id],
None,
);
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
// to preserve drop semantics since `while cond { ... }` does not
// let temporaries live outside of `cond`.
Expand Down Expand Up @@ -573,7 +577,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
(
this.mark_span_with_reason(
DesugaringKind::TryBlock,
expr.span,
this.spans[expr.hir_id],
this.allow_try_trait.clone(),
),
expr,
Expand All @@ -588,8 +592,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
(try_span, this.expr_unit(try_span))
};

let ok_wrapped_span =
this.mark_span_with_reason(DesugaringKind::TryBlock, tail_expr.span, None);
let ok_wrapped_span = this.mark_span_with_reason(
DesugaringKind::TryBlock,
this.spans[tail_expr.hir_id],
None,
);

// `::std::ops::Try::from_ok($tail_expr)`
block.expr = Some(this.wrap_in_try_constructor(
Expand Down Expand Up @@ -624,9 +631,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::Guard::If(self.lower_expr(cond))
}
});
let hir_id = self.next_id();
let hir_id = self.next_id(arm.span);
self.lower_attrs(hir_id, &arm.attrs);
hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span }
hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body) }
}

/// Lower an `async` construct to a generator that is then wrapped so it implements `Future`.
Expand Down Expand Up @@ -654,7 +661,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 };

// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
let decl = self.arena.alloc(hir::FnDecl {
Expand All @@ -670,7 +677,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Ident::with_dummy_span(sym::_task_context),
hir::BindingAnnotation::Mutable,
);
let param = hir::Param { hir_id: self.next_id(), pat, ty_span: span, span };
let param = hir::Param { 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 @@ -692,7 +699,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(hir::Movability::Static),
);
let generator =
hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span };
hir::Expr { hir_id: self.lower_node_id(closure_node_id, span), kind: generator_kind };

// `future::from_generator`:
let unstable_span =
Expand Down Expand Up @@ -785,7 +792,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 @@ -845,7 +852,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
let loop_expr = self.arena.alloc(hir::Expr {
hir_id: loop_hir_id,
kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span),
span,
});

// mut pinned => loop { ... }
Expand Down Expand Up @@ -1114,11 +1120,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 @@ -1255,7 +1260,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 @@ -1264,7 +1269,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 @@ -1660,10 +1665,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 @@ -1718,13 +1722,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::Expr<'hir> {
let orig_head_span = head.span;
// expand <head>
let mut head = self.lower_expr_mut(head);
let head = self.lower_expr_mut(head);
let desugared_span = self.mark_span_with_reason(
DesugaringKind::ForLoop(ForLoopLoc::Head),
orig_head_span,
None,
);
head.span = desugared_span;
self.spans[head.hir_id] = desugared_span;

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

Expand Down Expand Up @@ -1816,7 +1820,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
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 });
self.arena.alloc(hir::Expr { hir_id: self.lower_node_id(e.id, e.span), kind });

// `mut iter => { ... }`
let iter_arm = self.arm(iter_pat, loop_expr);
Expand Down Expand Up @@ -1939,7 +1943,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 @@ -2112,8 +2116,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 span = self.spans[expr.hir_id];
let hir_id = self.next_id(span);
self.expr(
span,
hir::ExprKind::Block(
Expand All @@ -2122,7 +2126,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 @@ -2142,7 +2145,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 @@ -2151,16 +2155,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
kind: hir::ExprKind<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
let hir_id = self.next_id();
let hir_id = self.next_id(span);
self.lower_attrs(hir_id, &attrs);
hir::Expr { hir_id, kind, span }
hir::Expr { hir_id, kind }
}

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(), pat, guard: None, span: expr.span, body: expr }
let span = self.spans[expr.hir_id];
hir::Arm { hir_id: self.next_id(span), pat, guard: None, body: expr }
}
}
Loading