Skip to content

Commit

Permalink
Auto merge of #88208 - petrochenkov:lowspan, r=Aaron1011
Browse files Browse the repository at this point in the history
ast_lowering: Introduce `lower_span` for catching all spans entering HIR

This PR cherry-picks the `fn lower_span` change from #84373.
I also introduced `fn lower_ident` for lowering spans in identifiers, and audited places where HIR structures with spans or identifiers are constructed and added a few missing `lower_span`s/`lower_ident`s.

Having a hook for spans entering HIR can be useful for things other than #84373, e.g. #35148.
I also want to check whether this change causes perf regressions due to some accidental inlining issues.

r? `@cjgillot`
  • Loading branch information
bors committed Aug 29, 2021
2 parents 59ce765 + 59013cd commit ef52471
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 169 deletions.
13 changes: 9 additions & 4 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
}
};
(op, *op_sp)
(op, self.lower_span(*op_sp))
})
.collect();

Expand Down Expand Up @@ -384,16 +384,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
late: true,
expr: None,
},
abi_span,
self.lower_span(abi_span),
));
}
}
}

let operands = self.arena.alloc_from_iter(operands);
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
let template_strs = self.arena.alloc_from_iter(asm.template_strs.iter().cloned());
let line_spans = self.arena.alloc_slice(&asm.line_spans[..]);
let template_strs = self.arena.alloc_from_iter(
asm.template_strs
.iter()
.map(|(sym, snippet, span)| (*sym, *snippet, self.lower_span(*span))),
);
let line_spans =
self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span)));
let hir_asm =
hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans };
self.arena.alloc(hir_asm)
Expand Down
Loading

0 comments on commit ef52471

Please sign in to comment.