1
Fork 0
This commit is contained in:
bjorn3 2025-02-08 22:12:13 +00:00
parent 3183b44a1e
commit 1fcae03369
287 changed files with 5888 additions and 4608 deletions

View file

@ -99,10 +99,13 @@ fn add_move_for_packed_drop<'tcx>(
patch.add_statement(loc, StatementKind::StorageLive(temp));
patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(*place)));
patch.patch_terminator(loc.block, TerminatorKind::Drop {
place: Place::from(temp),
target: storage_dead_block,
unwind,
replace,
});
patch.patch_terminator(
loc.block,
TerminatorKind::Drop {
place: Place::from(temp),
target: storage_dead_block,
unwind,
replace,
},
);
}

View file

@ -111,10 +111,13 @@ impl<'tcx> crate::MirPass<'tcx> for AddRetag {
.collect::<Vec<_>>();
// Now we go over the returns we collected to retag the return values.
for (source_info, dest_place, dest_block) in returns {
basic_blocks[dest_block].statements.insert(0, Statement {
source_info,
kind: StatementKind::Retag(RetagKind::Default, Box::new(dest_place)),
});
basic_blocks[dest_block].statements.insert(
0,
Statement {
source_info,
kind: StatementKind::Retag(RetagKind::Default, Box::new(dest_place)),
},
);
}
// PART 3
@ -169,10 +172,13 @@ impl<'tcx> crate::MirPass<'tcx> for AddRetag {
};
// Insert a retag after the statement.
let source_info = block_data.statements[i].source_info;
block_data.statements.insert(i + 1, Statement {
source_info,
kind: StatementKind::Retag(retag_kind, Box::new(place)),
});
block_data.statements.insert(
i + 1,
Statement {
source_info,
kind: StatementKind::Retag(retag_kind, Box::new(place)),
},
);
}
}
}

View file

@ -83,10 +83,12 @@ fn check_recursion<'tcx>(
let sp = tcx.def_span(def_id);
let hir_id = tcx.local_def_id_to_hir_id(def_id);
tcx.emit_node_span_lint(UNCONDITIONAL_RECURSION, hir_id, sp, UnconditionalRecursion {
span: sp,
call_sites: vis.reachable_recursive_calls,
});
tcx.emit_node_span_lint(
UNCONDITIONAL_RECURSION,
hir_id,
sp,
UnconditionalRecursion { span: sp, call_sites: vis.reachable_recursive_calls },
);
}
}

View file

@ -1044,11 +1044,14 @@ fn insert_switch<'tcx>(
let switch = TerminatorKind::SwitchInt { discr: Operand::Move(discr), targets: switch_targets };
let source_info = SourceInfo::outermost(body.span);
body.basic_blocks_mut().raw.insert(0, BasicBlockData {
statements: vec![assign],
terminator: Some(Terminator { source_info, kind: switch }),
is_cleanup: false,
});
body.basic_blocks_mut().raw.insert(
0,
BasicBlockData {
statements: vec![assign],
terminator: Some(Terminator { source_info, kind: switch }),
is_cleanup: false,
},
);
let blocks = body.basic_blocks_mut().iter_mut();
@ -1594,13 +1597,16 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
// (which is now a generator interior).
let source_info = SourceInfo::outermost(body.span);
let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements;
stmts.insert(0, Statement {
source_info,
kind: StatementKind::Assign(Box::new((
old_resume_local.into(),
Rvalue::Use(Operand::Move(resume_local.into())),
))),
});
stmts.insert(
0,
Statement {
source_info,
kind: StatementKind::Assign(Box::new((
old_resume_local.into(),
Rvalue::Use(Operand::Move(resume_local.into())),
))),
},
);
let always_live_locals = always_storage_live_locals(body);
@ -1839,12 +1845,17 @@ fn check_suspend_tys<'tcx>(tcx: TyCtxt<'tcx>, layout: &CoroutineLayout<'tcx>, bo
continue;
};
check_must_not_suspend_ty(tcx, decl.ty, hir_id, SuspendCheckData {
source_span: decl.source_info.span,
yield_span: yield_source_info.span,
plural_len: 1,
..Default::default()
});
check_must_not_suspend_ty(
tcx,
decl.ty,
hir_id,
SuspendCheckData {
source_span: decl.source_info.span,
yield_span: yield_source_info.span,
plural_len: 1,
..Default::default()
},
);
}
}
}
@ -1883,13 +1894,17 @@ fn check_must_not_suspend_ty<'tcx>(
ty::Adt(_, args) if ty.is_box() => {
let boxed_ty = args.type_at(0);
let allocator_ty = args.type_at(1);
check_must_not_suspend_ty(tcx, boxed_ty, hir_id, SuspendCheckData {
descr_pre: &format!("{}boxed ", data.descr_pre),
..data
}) || check_must_not_suspend_ty(tcx, allocator_ty, hir_id, SuspendCheckData {
descr_pre: &format!("{}allocator ", data.descr_pre),
..data
})
check_must_not_suspend_ty(
tcx,
boxed_ty,
hir_id,
SuspendCheckData { descr_pre: &format!("{}boxed ", data.descr_pre), ..data },
) || check_must_not_suspend_ty(
tcx,
allocator_ty,
hir_id,
SuspendCheckData { descr_pre: &format!("{}allocator ", data.descr_pre), ..data },
)
}
ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data),
// FIXME: support adding the attribute to TAITs
@ -1902,10 +1917,12 @@ fn check_must_not_suspend_ty<'tcx>(
{
let def_id = poly_trait_predicate.trait_ref.def_id;
let descr_pre = &format!("{}implementer{} of ", data.descr_pre, plural_suffix);
if check_must_not_suspend_def(tcx, def_id, hir_id, SuspendCheckData {
descr_pre,
..data
}) {
if check_must_not_suspend_def(
tcx,
def_id,
hir_id,
SuspendCheckData { descr_pre, ..data },
) {
has_emitted = true;
break;
}
@ -1919,10 +1936,12 @@ fn check_must_not_suspend_ty<'tcx>(
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() {
let def_id = trait_ref.def_id;
let descr_post = &format!(" trait object{}{}", plural_suffix, data.descr_post);
if check_must_not_suspend_def(tcx, def_id, hir_id, SuspendCheckData {
descr_post,
..data
}) {
if check_must_not_suspend_def(
tcx,
def_id,
hir_id,
SuspendCheckData { descr_post, ..data },
) {
has_emitted = true;
break;
}
@ -1934,10 +1953,12 @@ fn check_must_not_suspend_ty<'tcx>(
let mut has_emitted = false;
for (i, ty) in fields.iter().enumerate() {
let descr_post = &format!(" in tuple element {i}");
if check_must_not_suspend_ty(tcx, ty, hir_id, SuspendCheckData {
descr_post,
..data
}) {
if check_must_not_suspend_ty(
tcx,
ty,
hir_id,
SuspendCheckData { descr_post, ..data },
) {
has_emitted = true;
}
}
@ -1945,12 +1966,17 @@ fn check_must_not_suspend_ty<'tcx>(
}
ty::Array(ty, len) => {
let descr_pre = &format!("{}array{} of ", data.descr_pre, plural_suffix);
check_must_not_suspend_ty(tcx, ty, hir_id, SuspendCheckData {
descr_pre,
// FIXME(must_not_suspend): This is wrong. We should handle printing unevaluated consts.
plural_len: len.try_to_target_usize(tcx).unwrap_or(0) as usize + 1,
..data
})
check_must_not_suspend_ty(
tcx,
ty,
hir_id,
SuspendCheckData {
descr_pre,
// FIXME(must_not_suspend): This is wrong. We should handle printing unevaluated consts.
plural_len: len.try_to_target_usize(tcx).unwrap_or(0) as usize + 1,
..data
},
)
}
// If drop tracking is enabled, we want to look through references, since the referent
// may not be considered live across the await point.

View file

@ -138,10 +138,10 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
// If the parent capture is by-ref, then we need to apply an additional
// deref before applying any further projections to this place.
if parent_capture.is_by_ref() {
child_precise_captures.insert(0, Projection {
ty: parent_capture.place.ty(),
kind: ProjectionKind::Deref,
});
child_precise_captures.insert(
0,
Projection { ty: parent_capture.place.ty(), kind: ProjectionKind::Deref },
);
}
// If the child capture is by-ref, then we need to apply a "ref"
// projection (i.e. `&`) at the end. But wait! We don't have that

View file

@ -20,29 +20,25 @@ fn make_graph<Node: Idx + Ord>(num_nodes: usize, edge_pairs: Vec<(Node, Node)>)
/// (Knuth & Stevenson, 1973), but with 0-based node IDs.
#[test]
fn example_driver() {
let graph = make_graph::<u32>(5, vec![
(0, 1),
(0, 3),
(1, 0),
(1, 2),
(2, 1),
(2, 4),
(3, 3),
(3, 4),
(4, 0),
]);
let graph = make_graph::<u32>(
5,
vec![(0, 1), (0, 3), (1, 0), (1, 2), (2, 1), (2, 4), (3, 3), (3, 4), (4, 0)],
);
let node_flow_data = node_flow_data(&graph);
let counters = make_node_counters(&node_flow_data, &[3, 1, 2, 0, 4]);
assert_eq!(format_counter_expressions(&counters), &[
// (comment to force vertical formatting for clarity)
"[0]: +c0",
"[1]: +c0 +c2 -c4",
"[2]: +c2",
"[3]: +c3",
"[4]: +c4",
]);
assert_eq!(
format_counter_expressions(&counters),
&[
// (comment to force vertical formatting for clarity)
"[0]: +c0",
"[1]: +c0 +c2 -c4",
"[2]: +c2",
"[3]: +c3",
"[4]: +c4",
]
);
}
fn format_counter_expressions<Node: Idx>(counters: &NodeCounters<Node>) -> Vec<String> {

View file

@ -129,15 +129,18 @@ impl<'tcx> MockBlocks<'tcx> {
}
fn call(&mut self, some_from_block: Option<BasicBlock>) -> BasicBlock {
self.add_block_from(some_from_block, TerminatorKind::Call {
func: Operand::Copy(self.dummy_place.clone()),
args: [].into(),
destination: self.dummy_place.clone(),
target: Some(TEMP_BLOCK),
unwind: UnwindAction::Continue,
call_source: CallSource::Misc,
fn_span: DUMMY_SP,
})
self.add_block_from(
some_from_block,
TerminatorKind::Call {
func: Operand::Copy(self.dummy_place.clone()),
args: [].into(),
destination: self.dummy_place.clone(),
target: Some(TEMP_BLOCK),
unwind: UnwindAction::Continue,
call_source: CallSource::Misc,
fn_span: DUMMY_SP,
},
)
}
fn goto(&mut self, some_from_block: Option<BasicBlock>) -> BasicBlock {

View file

@ -90,10 +90,12 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
let span = terminator.source_info.span;
let foreign = fn_def_id.is_some();
tcx.emit_node_span_lint(FFI_UNWIND_CALLS, lint_root, span, errors::FfiUnwindCall {
tcx.emit_node_span_lint(
FFI_UNWIND_CALLS,
lint_root,
span,
foreign,
});
errors::FfiUnwindCall { span, foreign },
);
tainted = true;
}

View file

@ -1111,10 +1111,13 @@ fn new_call_temp<'tcx>(
});
if let Some(block) = return_block {
caller_body[block].statements.insert(0, Statement {
source_info: callsite.source_info,
kind: StatementKind::StorageDead(local),
});
caller_body[block].statements.insert(
0,
Statement {
source_info: callsite.source_info,
kind: StatementKind::StorageDead(local),
},
);
}
local

View file

@ -296,11 +296,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
let source_info = self.body.source_info(location);
if let Some(lint_root) = self.lint_root(*source_info) {
let span = source_info.span;
self.tcx.emit_node_span_lint(lint_kind.lint(), lint_root, span, AssertLint {
self.tcx.emit_node_span_lint(
lint_kind.lint(),
lint_root,
span,
assert_kind,
lint_kind,
});
AssertLint { span, assert_kind, lint_kind },
);
}
}

View file

@ -920,19 +920,23 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
self.extra_statements.push((loc, promoted_ref_statement));
(
Rvalue::Ref(tcx.lifetimes.re_erased, *borrow_kind, Place {
local: mem::replace(&mut place.local, promoted_ref),
projection: List::empty(),
}),
Rvalue::Ref(
tcx.lifetimes.re_erased,
*borrow_kind,
Place {
local: mem::replace(&mut place.local, promoted_ref),
projection: List::empty(),
},
),
promoted_operand,
)
};
assert_eq!(self.new_block(), START_BLOCK);
self.visit_rvalue(&mut rvalue, Location {
block: START_BLOCK,
statement_index: usize::MAX,
});
self.visit_rvalue(
&mut rvalue,
Location { block: START_BLOCK, statement_index: usize::MAX },
);
let span = self.promoted.span;
self.assign(RETURN_PLACE, rvalue, span);

View file

@ -447,17 +447,19 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
}
fn combine_sync_surface(&mut self) -> Ty<'tcx> {
self.apply_combinator(1, LangItem::AsyncDropSurfaceDropInPlace, &[self
.self_ty
.unwrap()
.into()])
self.apply_combinator(
1,
LangItem::AsyncDropSurfaceDropInPlace,
&[self.self_ty.unwrap().into()],
)
}
fn combine_deferred_drop_in_place(&mut self) -> Ty<'tcx> {
self.apply_combinator(1, LangItem::AsyncDropDeferredDropInPlace, &[self
.self_ty
.unwrap()
.into()])
self.apply_combinator(
1,
LangItem::AsyncDropDeferredDropInPlace,
&[self.self_ty.unwrap().into()],
)
}
fn combine_fuse(&mut self, inner_future_ty: Ty<'tcx>) -> Ty<'tcx> {
@ -477,11 +479,11 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
}
fn combine_either(&mut self, other: Ty<'tcx>, matched: Ty<'tcx>) -> Ty<'tcx> {
self.apply_combinator(4, LangItem::AsyncDropEither, &[
other.into(),
matched.into(),
self.self_ty.unwrap().into(),
])
self.apply_combinator(
4,
LangItem::AsyncDropEither,
&[other.into(), matched.into(), self.self_ty.unwrap().into()],
)
}
fn return_(mut self) -> Body<'tcx> {

View file

@ -113,10 +113,13 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral {
// if we have StorageDeads to remove then make sure to insert them at the top of
// each target
for bb_idx in new_targets.all_targets() {
storage_deads_to_insert.push((*bb_idx, Statement {
source_info: terminator.source_info,
kind: StatementKind::StorageDead(opt.to_switch_on.local),
}));
storage_deads_to_insert.push((
*bb_idx,
Statement {
source_info: terminator.source_info,
kind: StatementKind::StorageDead(opt.to_switch_on.local),
},
));
}
}

View file

@ -159,10 +159,11 @@ impl SsaLocals {
) {
for &local in &self.assignment_order {
match self.assignments[local] {
Set1::One(DefLocation::Argument) => f(local, AssignedValue::Arg, Location {
block: START_BLOCK,
statement_index: 0,
}),
Set1::One(DefLocation::Argument) => f(
local,
AssignedValue::Arg,
Location { block: START_BLOCK, statement_index: 0 },
),
Set1::One(DefLocation::Assignment(loc)) => {
let bb = &mut basic_blocks[loc.block];
// `loc` must point to a direct assignment to `local`.