Skip to content

Commit

Permalink
Auto merge of #116427 - cjgillot:no-internal, r=oli-obk
Browse files Browse the repository at this point in the history
Remove mir::LocalDecl::internal.

It does not serve any purpose, as we don't have typeck-based generator witnesses any more.
  • Loading branch information
bors committed Oct 5, 2023
2 parents e293927 + e63d19c commit 5c3a0e9
Show file tree
Hide file tree
Showing 38 changed files with 106 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
if self.const_kind() == hir::ConstContext::ConstFn {
for (idx, local) in body.local_decls.iter_enumerated() {
// Handle the return place below.
if idx == RETURN_PLACE || local.internal {
if idx == RETURN_PLACE {
continue;
}

Expand Down
26 changes: 1 addition & 25 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,22 +830,6 @@ pub struct LocalDecl<'tcx> {
// FIXME(matthewjasper) Don't store in this in `Body`
pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>,

/// `true` if this is an internal local.
///
/// These locals are not based on types in the source code and are only used
/// for a few desugarings at the moment.
///
/// The generator transformation will sanity check the locals which are live
/// across a suspension point against the type components of the generator
/// which type checking knows are live across a suspension point. We need to
/// flag drop flags to avoid triggering this check as they are introduced
/// outside of type inference.
///
/// This should be sound because the drop flags are fully algebraic, and
/// therefore don't affect the auto-trait or outlives properties of the
/// generator.
pub internal: bool,

/// The type of this local.
pub ty: Ty<'tcx>,

Expand Down Expand Up @@ -1058,7 +1042,7 @@ impl<'tcx> LocalDecl<'tcx> {
self.source_info.span.desugaring_kind().is_some()
}

/// Creates a new `LocalDecl` for a temporary: mutable, non-internal.
/// Creates a new `LocalDecl` for a temporary, mutable.
#[inline]
pub fn new(ty: Ty<'tcx>, span: Span) -> Self {
Self::with_source_info(ty, SourceInfo::outermost(span))
Expand All @@ -1070,20 +1054,12 @@ impl<'tcx> LocalDecl<'tcx> {
LocalDecl {
mutability: Mutability::Mut,
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
internal: false,
ty,
user_ty: None,
source_info,
}
}

/// Converts `self` into same `LocalDecl` except tagged as internal.
#[inline]
pub fn internal(mut self) -> Self {
self.internal = true;
self
}

/// Converts `self` into same `LocalDecl` except tagged as immutable.
#[inline]
pub fn immutable(mut self) -> Self {
Expand Down
11 changes: 2 additions & 9 deletions compiler/rustc_middle/src/mir/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ impl<'tcx> MirPatch<'tcx> {
Location { block: bb, statement_index: offset }
}

pub fn new_internal_with_info(
pub fn new_local_with_info(
&mut self,
ty: Ty<'tcx>,
span: Span,
local_info: LocalInfo<'tcx>,
) -> Local {
let index = self.next_local;
self.next_local += 1;
let mut new_decl = LocalDecl::new(ty, span).internal();
let mut new_decl = LocalDecl::new(ty, span);
**new_decl.local_info.as_mut().assert_crate_local() = local_info;
self.new_locals.push(new_decl);
Local::new(index)
Expand All @@ -148,13 +148,6 @@ impl<'tcx> MirPatch<'tcx> {
Local::new(index)
}

pub fn new_internal(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
let index = self.next_local;
self.next_local += 1;
self.new_locals.push(LocalDecl::new(ty, span).internal());
Local::new(index)
}

pub fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
let block = BasicBlock::new(self.patch_map.len());
debug!("MirPatch: new_block: {:?}: {:?}", block, data);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,6 @@ macro_rules! make_mir_visitor {
ty,
user_ty,
source_info,
internal: _,
local_info: _,
} = local_decl;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// The `Box<T>` temporary created here is not a part of the HIR,
// and therefore is not considered during generator auto-trait
// determination. See the comment about `box` at `yield_in_scope`.
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span).internal());
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span));
this.cfg.push(
block,
Statement { source_info, kind: StatementKind::StorageLive(result) },
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/as_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let local_info = match expr.kind {
ExprKind::StaticRef { def_id, .. } => {
assert!(!this.tcx.is_thread_local_static(def_id));
local_decl.internal = true;
LocalInfo::StaticRef { def_id, is_thread_local: false }
}
ExprKind::ThreadLocalRef(def_id) => {
assert!(this.tcx.is_thread_local_static(def_id));
local_decl.internal = true;
LocalInfo::StaticRef { def_id, is_thread_local: true }
}
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let fake_borrow_ty =
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, fake_borrow_deref_ty);
let mut fake_borrow_temp = LocalDecl::new(fake_borrow_ty, temp_span);
fake_borrow_temp.internal = self.local_decls[matched_place.local].internal;
fake_borrow_temp.local_info = ClearCrossCrate::Set(Box::new(LocalInfo::FakeBorrow));
let fake_borrow_temp = self.local_decls.push(fake_borrow_temp);

Expand Down Expand Up @@ -2268,7 +2267,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ty: var_ty,
user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
source_info,
internal: false,
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
VarBindingForm {
binding_mode,
Expand Down Expand Up @@ -2298,7 +2296,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ty: Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, var_ty),
user_ty: None,
source_info,
internal: false,
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(
BindingForm::RefForGuard,
))),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/build/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// N.B., **No cleanup is scheduled for this temporary.** You should
/// call `schedule_drop` once the temporary is initialized.
pub(crate) fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
// Mark this local as internal to avoid temporaries with types not present in the
// user's code resulting in ICEs from the generator transform.
let temp = self.local_decls.push(LocalDecl::new(ty, span).internal());
let temp = self.local_decls.push(LocalDecl::new(ty, span));
let place = Place::from(temp);
debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty);
place
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
// statement.
fn add_dummy_assignment(&mut self, span: Span, block: BasicBlock, source_info: SourceInfo) {
let local_decl = LocalDecl::new(Ty::new_unit(self.tcx), span).internal();
let local_decl = LocalDecl::new(Ty::new_unit(self.tcx), span);
let temp_place = Place::from(self.local_decls.push(local_decl));
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
// Check the base local: it might be an unsafe-to-access static. We only check derefs of the
// temporary holding the static pointer to avoid duplicate errors
// <https://github.com/rust-lang/rust/pull/78068#issuecomment-731753506>.
if decl.internal && place.projection.first() == Some(&ProjectionElem::Deref) {
if place.projection.first() == Some(&ProjectionElem::Deref) {
// If the projection root is an artificial local that we introduced when
// desugaring `static`, give a more specific error message
// (avoid the general "raw pointer" clause below, that would only be confusing).
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/deref_separator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() {
if !p_ref.projection.is_empty() && p_elem == ProjectionElem::Deref {
let ty = p_ref.ty(self.local_decls, self.tcx).ty;
let temp = self.patcher.new_internal_with_info(
let temp = self.patcher.new_local_with_info(
ty,
self.local_decls[p_ref.local].source_info.span,
LocalInfo::DerefTemp,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/elaborate_box_derefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'tcx, 'a> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'tcx, 'a> {
let (unique_ty, nonnull_ty, ptr_ty) =
build_ptr_tys(tcx, base_ty.boxed_ty(), self.unique_did, self.nonnull_did);

let ptr_local = self.patch.new_internal(ptr_ty, source_info.span);
let ptr_local = self.patch.new_temp(ptr_ty, source_info.span);

self.patch.add_assign(
location,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let tcx = self.tcx;
let patch = &mut self.patch;
debug!("create_drop_flag({:?})", self.body.span);
self.drop_flags[index].get_or_insert_with(|| patch.new_internal(tcx.types.bool, span));
self.drop_flags[index].get_or_insert_with(|| patch.new_temp(tcx.types.bool, span));
}

fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl<'tcx> TransformVisitor<'tcx> {

// Create a statement which reads the discriminant into a temporary
fn get_discr(&self, body: &mut Body<'tcx>) -> (Statement<'tcx>, Place<'tcx>) {
let temp_decl = LocalDecl::new(self.discr_ty, body.span).internal();
let temp_decl = LocalDecl::new(self.discr_ty, body.span);
let local_decls_len = body.local_decls.push(temp_decl);
let temp = Place::from(local_decls_len);

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,7 @@ impl<'tcx> Inliner<'tcx> {
// If there are any locals without storage markers, give them storage only for the
// duration of the call.
for local in callee_body.vars_and_temps_iter() {
if !callee_body.local_decls[local].internal
&& integrator.always_live_locals.contains(local)
{
if integrator.always_live_locals.contains(local) {
let new_local = integrator.map_local(local);
caller_body[callsite.block].statements.push(Statement {
source_info: callsite.source_info,
Expand All @@ -641,9 +639,7 @@ impl<'tcx> Inliner<'tcx> {
n += 1;
}
for local in callee_body.vars_and_temps_iter().rev() {
if !callee_body.local_decls[local].internal
&& integrator.always_live_locals.contains(local)
{
if integrator.always_live_locals.contains(local) {
let new_local = integrator.map_local(local);
caller_body[block].statements.push(Statement {
source_info: callsite.source_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
_2 = const u8::MAX;
StorageLive(_3);
_3 = const 1_u8;
StorageLive(_4);
- _4 = CheckedAdd(_2, _3);
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
+ _4 = const (0_u8, true);
Expand All @@ -29,6 +30,7 @@
bb1: {
- _1 = move (_4.0: u8);
+ _1 = const 0_u8;
StorageDead(_4);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
_2 = const u8::MAX;
StorageLive(_3);
_3 = const 1_u8;
StorageLive(_4);
- _4 = CheckedAdd(_2, _3);
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue];
+ _4 = const (0_u8, true);
Expand All @@ -29,6 +30,7 @@
bb1: {
- _1 = move (_4.0: u8);
+ _1 = const 0_u8;
StorageDead(_4);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
_2 = const u8::MAX;
StorageLive(_3);
_3 = const 1_u8;
StorageLive(_4);
- _4 = CheckedAdd(_2, _3);
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
+ _4 = CheckedAdd(const u8::MAX, const 1_u8);
Expand All @@ -29,6 +30,7 @@
bb1: {
- _1 = move (_4.0: u8);
+ _1 = const 0_u8;
StorageDead(_4);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
_2 = const u8::MAX;
StorageLive(_3);
_3 = const 1_u8;
StorageLive(_4);
- _4 = CheckedAdd(_2, _3);
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue];
+ _4 = CheckedAdd(const u8::MAX, const 1_u8);
Expand All @@ -29,6 +30,7 @@
bb1: {
- _1 = move (_4.0: u8);
+ _1 = const 0_u8;
StorageDead(_4);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
_7 = (move _8,);
StorageLive(_9);
_9 = move (_7.0: i32);
StorageLive(_10);
StorageLive(_12);
StorageLive(_11);
_10 = ((*_6).0: &i32);
_11 = (*_10);
Expand All @@ -50,6 +52,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
_0 = (move _11, move _13);
StorageDead(_13);
StorageDead(_11);
StorageDead(_12);
StorageDead(_10);
StorageDead(_9);
StorageDead(_8);
StorageDead(_7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
+ StorageDead(_3);
+ StorageLive(_6);
+ _6 = const false;
+ StorageLive(_7);
+ StorageLive(_8);
+ _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ _8 = discriminant((*_7));
+ switchInt(move _8) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9];
Expand All @@ -52,6 +54,8 @@
bb1: {
- _3 = &mut _4;
- _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>::new(move _3) -> [return: bb2, unwind unreachable];
+ StorageDead(_8);
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageDead(_2);
+ drop(_4) -> [return: bb2, unwind unreachable];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@
- _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
+ StorageLive(_6);
+ _6 = const false;
+ StorageLive(_7);
+ StorageLive(_8);
+ _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ _8 = discriminant((*_7));
+ switchInt(move _8) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
}

- bb3: {
+ bb1: {
+ StorageDead(_8);
+ StorageDead(_7);
+ StorageDead(_6);
StorageDead(_2);
- drop(_4) -> [return: bb4, unwind: bb6];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@
+ _3 = const _;
+ _2 = Vec::<u32> { buf: move _3, len: const 0_usize };
+ StorageDead(_3);
+ StorageLive(_4);
+ StorageLive(_5);
+ StorageLive(_6);
+ StorageLive(_7);
+ _4 = SizeOf(std::vec::Vec<u32>);
+ _5 = AlignOf(std::vec::Vec<u32>);
+ StorageLive(_8);
+ StorageLive(_10);
+ StorageLive(_11);
+ StorageLive(_12);
+ StorageLive(_13);
Expand Down Expand Up @@ -178,10 +183,15 @@
+ StorageDead(_13);
+ StorageDead(_12);
+ StorageDead(_11);
+ StorageDead(_10);
+ StorageDead(_8);
+ _1 = ShallowInitBox(move _6, std::vec::Vec<u32>);
+ _7 = (((_1.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>);
+ (*_7) = move _2;
+ StorageDead(_7);
+ StorageDead(_6);
+ StorageDead(_5);
+ StorageDead(_4);
StorageDead(_2);
_0 = const ();
- drop(_1) -> [return: bb3, unwind unreachable];
Expand Down
Loading

0 comments on commit 5c3a0e9

Please sign in to comment.