Add SourceInfo::outermost
.
This commit is contained in:
parent
a0c61a9044
commit
a17234ca54
@ -474,6 +474,13 @@ pub struct SourceInfo {
|
||||
pub scope: SourceScope,
|
||||
}
|
||||
|
||||
impl SourceInfo {
|
||||
#[inline]
|
||||
pub fn outermost(span: Span) -> Self {
|
||||
SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Borrow kinds
|
||||
|
||||
@ -944,7 +951,7 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||
mutability,
|
||||
ty,
|
||||
user_ty: UserTypeProjections::none(),
|
||||
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
source_info: SourceInfo::outermost(span),
|
||||
internal,
|
||||
local_info: LocalInfo::Other,
|
||||
is_block_tail: None,
|
||||
@ -960,7 +967,7 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||
mutability: Mutability::Mut,
|
||||
ty: return_ty,
|
||||
user_ty: UserTypeProjections::none(),
|
||||
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
source_info: SourceInfo::outermost(span),
|
||||
internal: false,
|
||||
is_block_tail: None,
|
||||
local_info: LocalInfo::Other,
|
||||
@ -1406,10 +1413,7 @@ impl<'tcx> BasicBlockData<'tcx> {
|
||||
let mut gap = self.statements.len()..self.statements.len() + extra_stmts;
|
||||
self.statements.resize(
|
||||
gap.end,
|
||||
Statement {
|
||||
source_info: SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
kind: StatementKind::Nop,
|
||||
},
|
||||
Statement { source_info: SourceInfo::outermost(DUMMY_SP), kind: StatementKind::Nop },
|
||||
);
|
||||
for (splice_start, new_stmts) in splices.into_iter().rev() {
|
||||
let splice_end = splice_start + new_stmts.size_hint().0;
|
||||
|
@ -242,10 +242,10 @@ macro_rules! make_mir_visitor {
|
||||
) {
|
||||
let span = body.span;
|
||||
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
|
||||
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
|
||||
span,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
}));
|
||||
self.visit_ty(
|
||||
yield_ty,
|
||||
TyContext::YieldTy(SourceInfo::outermost(span))
|
||||
);
|
||||
}
|
||||
|
||||
// for best performance, we want to use an iterator rather
|
||||
@ -263,10 +263,10 @@ macro_rules! make_mir_visitor {
|
||||
self.visit_source_scope_data(scope);
|
||||
}
|
||||
|
||||
self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
|
||||
span: body.span,
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
}));
|
||||
self.visit_ty(
|
||||
&$($mutability)? body.return_ty(),
|
||||
TyContext::ReturnTy(SourceInfo::outermost(body.span))
|
||||
);
|
||||
|
||||
for local in body.local_decls.indices() {
|
||||
self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);
|
||||
|
@ -16,7 +16,7 @@ use crate::dataflow::BottomValue;
|
||||
/// This is the `Body` that will be used by the `MockAnalysis` below. The shape of its CFG is not
|
||||
/// important.
|
||||
fn mock_body() -> mir::Body<'static> {
|
||||
let source_info = mir::SourceInfo { scope: mir::OUTERMOST_SOURCE_SCOPE, span: DUMMY_SP };
|
||||
let source_info = mir::SourceInfo::outermost(DUMMY_SP);
|
||||
|
||||
let mut blocks = IndexVec::new();
|
||||
let mut block = |n, kind| {
|
||||
|
@ -146,12 +146,11 @@ enum CallKind {
|
||||
}
|
||||
|
||||
fn temp_decl(mutability: Mutability, ty: Ty<'_>, span: Span) -> LocalDecl<'_> {
|
||||
let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span };
|
||||
LocalDecl {
|
||||
mutability,
|
||||
ty,
|
||||
user_ty: UserTypeProjections::none(),
|
||||
source_info,
|
||||
source_info: SourceInfo::outermost(span),
|
||||
internal: false,
|
||||
local_info: LocalInfo::Other,
|
||||
is_block_tail: None,
|
||||
@ -185,7 +184,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
|
||||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let span = tcx.def_span(def_id);
|
||||
|
||||
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
|
||||
let source_info = SourceInfo::outermost(span);
|
||||
|
||||
let return_block = BasicBlock::new(1);
|
||||
let mut blocks = IndexVec::with_capacity(2);
|
||||
@ -374,7 +373,7 @@ impl CloneShimBuilder<'tcx> {
|
||||
}
|
||||
|
||||
fn source_info(&self) -> SourceInfo {
|
||||
SourceInfo { span: self.span, scope: OUTERMOST_SOURCE_SCOPE }
|
||||
SourceInfo::outermost(self.span)
|
||||
}
|
||||
|
||||
fn block(
|
||||
@ -687,7 +686,7 @@ fn build_call_shim<'tcx>(
|
||||
debug!("build_call_shim: sig={:?}", sig);
|
||||
|
||||
let mut local_decls = local_decls_for_sig(&sig, span);
|
||||
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
|
||||
let source_info = SourceInfo::outermost(span);
|
||||
|
||||
let rcvr_place = || {
|
||||
assert!(rcvr_adjustment.is_some());
|
||||
@ -849,7 +848,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
|
||||
|
||||
let local_decls = local_decls_for_sig(&sig, span);
|
||||
|
||||
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
|
||||
let source_info = SourceInfo::outermost(span);
|
||||
|
||||
let variant_index = if adt_def.is_enum() {
|
||||
adt_def.variant_index_with_ctor_id(ctor_id)
|
||||
|
@ -77,11 +77,9 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
|
||||
// PART 1
|
||||
// Retag arguments at the beginning of the start block.
|
||||
{
|
||||
let source_info = SourceInfo {
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
span, // FIXME: Consider using just the span covering the function
|
||||
// FIXME: Consider using just the span covering the function
|
||||
// argument declaration.
|
||||
};
|
||||
let source_info = SourceInfo::outermost(span);
|
||||
// Gather all arguments, skip return value.
|
||||
let places = local_decls
|
||||
.iter_enumerated()
|
||||
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
|
||||
const_context,
|
||||
min_const_fn,
|
||||
violations: vec![],
|
||||
source_info: SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
source_info: SourceInfo::outermost(body.span),
|
||||
tcx,
|
||||
param_env,
|
||||
used_unsafe: Default::default(),
|
||||
|
@ -261,7 +261,7 @@ impl TransformVisitor<'tcx> {
|
||||
|
||||
let self_place = Place::from(SELF_ARG);
|
||||
let assign = Statement {
|
||||
source_info: source_info(body),
|
||||
source_info: SourceInfo::outermost(body.span),
|
||||
kind: StatementKind::Assign(box (temp, Rvalue::Discriminant(self_place))),
|
||||
};
|
||||
(assign, temp)
|
||||
@ -395,7 +395,7 @@ fn replace_local<'tcx>(
|
||||
body: &mut Body<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> Local {
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
let new_decl = LocalDecl {
|
||||
mutability: Mutability::Mut,
|
||||
ty,
|
||||
@ -784,7 +784,7 @@ fn insert_switch<'tcx>(
|
||||
targets: cases.iter().map(|&(_, d)| d).chain(iter::once(default_block)).collect(),
|
||||
};
|
||||
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
body.basic_blocks_mut().raw.insert(
|
||||
0,
|
||||
BasicBlockData {
|
||||
@ -858,7 +858,7 @@ fn create_generator_drop_shim<'tcx>(
|
||||
let mut body = body.clone();
|
||||
body.arg_count = 1; // make sure the resume argument is not included here
|
||||
|
||||
let source_info = source_info(&body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
|
||||
let mut cases = create_cases(&mut body, transform, Operation::Drop);
|
||||
|
||||
@ -922,7 +922,7 @@ fn create_generator_drop_shim<'tcx>(
|
||||
}
|
||||
|
||||
fn insert_term_block<'tcx>(body: &mut Body<'tcx>, kind: TerminatorKind<'tcx>) -> BasicBlock {
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
body.basic_blocks_mut().push(BasicBlockData {
|
||||
statements: Vec::new(),
|
||||
terminator: Some(Terminator { source_info, kind }),
|
||||
@ -948,7 +948,7 @@ fn insert_panic_block<'tcx>(
|
||||
cleanup: None,
|
||||
};
|
||||
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
body.basic_blocks_mut().push(BasicBlockData {
|
||||
statements: Vec::new(),
|
||||
terminator: Some(Terminator { source_info, kind: term }),
|
||||
@ -1025,7 +1025,7 @@ fn create_generator_resume_function<'tcx>(
|
||||
|
||||
// Poison the generator when it unwinds
|
||||
if can_unwind {
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
let poison_block = body.basic_blocks_mut().push(BasicBlockData {
|
||||
statements: vec![transform.set_discr(VariantIdx::new(POISONED), source_info)],
|
||||
terminator: Some(Terminator { source_info, kind: TerminatorKind::Resume }),
|
||||
@ -1092,10 +1092,6 @@ fn create_generator_resume_function<'tcx>(
|
||||
dump_mir(tcx, None, "generator_resume", &0, source, body, |_, _| Ok(()));
|
||||
}
|
||||
|
||||
fn source_info(body: &Body<'_>) -> SourceInfo {
|
||||
SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE }
|
||||
}
|
||||
|
||||
fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
|
||||
let return_block = insert_term_block(body, TerminatorKind::Return);
|
||||
|
||||
@ -1104,7 +1100,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
|
||||
target: return_block,
|
||||
unwind: None,
|
||||
};
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
|
||||
// Create a block to destroy an unresumed generators. This can only destroy upvars.
|
||||
body.basic_blocks_mut().push(BasicBlockData {
|
||||
@ -1135,7 +1131,7 @@ fn create_cases<'tcx>(
|
||||
transform: &TransformVisitor<'tcx>,
|
||||
operation: Operation,
|
||||
) -> Vec<(usize, BasicBlock)> {
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
|
||||
transform
|
||||
.suspension_points
|
||||
@ -1241,7 +1237,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
replace_local(resume_local, body.local_decls[resume_local].ty, body, tcx);
|
||||
|
||||
// When first entering the generator, move the resume argument into its new local.
|
||||
let source_info = source_info(body);
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
let stmts = &mut body.basic_blocks_mut()[BasicBlock::new(0)].statements;
|
||||
stmts.insert(
|
||||
0,
|
||||
|
@ -775,7 +775,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
||||
self.promoted.basic_blocks_mut().push(BasicBlockData {
|
||||
statements: vec![],
|
||||
terminator: Some(Terminator {
|
||||
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
source_info: SourceInfo::outermost(span),
|
||||
kind: TerminatorKind::Return,
|
||||
}),
|
||||
is_cleanup: false,
|
||||
@ -786,7 +786,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
||||
let last = self.promoted.basic_blocks().last().unwrap();
|
||||
let data = &mut self.promoted[last];
|
||||
data.statements.push(Statement {
|
||||
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
source_info: SourceInfo::outermost(span),
|
||||
kind: StatementKind::Assign(box (Place::from(dest), rvalue)),
|
||||
});
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ impl<'tcx> MirPatch<'tcx> {
|
||||
result.new_block(BasicBlockData {
|
||||
statements: vec![],
|
||||
terminator: Some(Terminator {
|
||||
source_info: SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE },
|
||||
source_info: SourceInfo::outermost(body.span),
|
||||
kind: TerminatorKind::Resume,
|
||||
}),
|
||||
is_cleanup: true,
|
||||
|
@ -804,10 +804,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
) -> BlockAnd<()> {
|
||||
// Allocate locals for the function arguments
|
||||
for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {
|
||||
let source_info = SourceInfo {
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
span: arg_opt.map_or(self.fn_span, |arg| arg.pat.span),
|
||||
};
|
||||
let source_info =
|
||||
SourceInfo::outermost(arg_opt.map_or(self.fn_span, |arg| arg.pat.span));
|
||||
let arg_local = self.local_decls.push(LocalDecl {
|
||||
mutability: Mutability::Mut,
|
||||
ty,
|
||||
@ -885,10 +883,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
||||
self.var_debug_info.push(VarDebugInfo {
|
||||
name,
|
||||
source_info: SourceInfo {
|
||||
scope: OUTERMOST_SOURCE_SCOPE,
|
||||
span: tcx_hir.span(var_id),
|
||||
},
|
||||
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
|
||||
place: Place {
|
||||
local: closure_env_arg,
|
||||
projection: tcx.intern_place_elems(&projs),
|
||||
|
@ -989,7 +989,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let resumeblk = self.cfg.start_new_cleanup_block();
|
||||
self.cfg.terminate(
|
||||
resumeblk,
|
||||
SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span: self.fn_span },
|
||||
SourceInfo::outermost(self.fn_span),
|
||||
TerminatorKind::Resume,
|
||||
);
|
||||
self.cached_resume_block = Some(resumeblk);
|
||||
|
Loading…
x
Reference in New Issue
Block a user