Skip to content

Commit 5c3a0e9

Browse files
committed
Auto merge of #116427 - cjgillot:no-internal, r=oli-obk
Remove mir::LocalDecl::internal. It does not serve any purpose, as we don't have typeck-based generator witnesses any more.
2 parents e293927 + e63d19c commit 5c3a0e9

File tree

38 files changed

+106
-57
lines changed

38 files changed

+106
-57
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
237237
if self.const_kind() == hir::ConstContext::ConstFn {
238238
for (idx, local) in body.local_decls.iter_enumerated() {
239239
// Handle the return place below.
240-
if idx == RETURN_PLACE || local.internal {
240+
if idx == RETURN_PLACE {
241241
continue;
242242
}
243243

compiler/rustc_middle/src/mir/mod.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -830,22 +830,6 @@ pub struct LocalDecl<'tcx> {
830830
// FIXME(matthewjasper) Don't store in this in `Body`
831831
pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>,
832832

833-
/// `true` if this is an internal local.
834-
///
835-
/// These locals are not based on types in the source code and are only used
836-
/// for a few desugarings at the moment.
837-
///
838-
/// The generator transformation will sanity check the locals which are live
839-
/// across a suspension point against the type components of the generator
840-
/// which type checking knows are live across a suspension point. We need to
841-
/// flag drop flags to avoid triggering this check as they are introduced
842-
/// outside of type inference.
843-
///
844-
/// This should be sound because the drop flags are fully algebraic, and
845-
/// therefore don't affect the auto-trait or outlives properties of the
846-
/// generator.
847-
pub internal: bool,
848-
849833
/// The type of this local.
850834
pub ty: Ty<'tcx>,
851835

@@ -1058,7 +1042,7 @@ impl<'tcx> LocalDecl<'tcx> {
10581042
self.source_info.span.desugaring_kind().is_some()
10591043
}
10601044

1061-
/// Creates a new `LocalDecl` for a temporary: mutable, non-internal.
1045+
/// Creates a new `LocalDecl` for a temporary, mutable.
10621046
#[inline]
10631047
pub fn new(ty: Ty<'tcx>, span: Span) -> Self {
10641048
Self::with_source_info(ty, SourceInfo::outermost(span))
@@ -1070,20 +1054,12 @@ impl<'tcx> LocalDecl<'tcx> {
10701054
LocalDecl {
10711055
mutability: Mutability::Mut,
10721056
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
1073-
internal: false,
10741057
ty,
10751058
user_ty: None,
10761059
source_info,
10771060
}
10781061
}
10791062

1080-
/// Converts `self` into same `LocalDecl` except tagged as internal.
1081-
#[inline]
1082-
pub fn internal(mut self) -> Self {
1083-
self.internal = true;
1084-
self
1085-
}
1086-
10871063
/// Converts `self` into same `LocalDecl` except tagged as immutable.
10881064
#[inline]
10891065
pub fn immutable(mut self) -> Self {

compiler/rustc_middle/src/mir/patch.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ impl<'tcx> MirPatch<'tcx> {
127127
Location { block: bb, statement_index: offset }
128128
}
129129

130-
pub fn new_internal_with_info(
130+
pub fn new_local_with_info(
131131
&mut self,
132132
ty: Ty<'tcx>,
133133
span: Span,
134134
local_info: LocalInfo<'tcx>,
135135
) -> Local {
136136
let index = self.next_local;
137137
self.next_local += 1;
138-
let mut new_decl = LocalDecl::new(ty, span).internal();
138+
let mut new_decl = LocalDecl::new(ty, span);
139139
**new_decl.local_info.as_mut().assert_crate_local() = local_info;
140140
self.new_locals.push(new_decl);
141141
Local::new(index)
@@ -148,13 +148,6 @@ impl<'tcx> MirPatch<'tcx> {
148148
Local::new(index)
149149
}
150150

151-
pub fn new_internal(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
152-
let index = self.next_local;
153-
self.next_local += 1;
154-
self.new_locals.push(LocalDecl::new(ty, span).internal());
155-
Local::new(index)
156-
}
157-
158151
pub fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
159152
let block = BasicBlock::new(self.patch_map.len());
160153
debug!("MirPatch: new_block: {:?}: {:?}", block, data);

compiler/rustc_middle/src/mir/visit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,6 @@ macro_rules! make_mir_visitor {
815815
ty,
816816
user_ty,
817817
source_info,
818-
internal: _,
819818
local_info: _,
820819
} = local_decl;
821820

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
183183
// The `Box<T>` temporary created here is not a part of the HIR,
184184
// and therefore is not considered during generator auto-trait
185185
// determination. See the comment about `box` at `yield_in_scope`.
186-
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span).internal());
186+
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span));
187187
this.cfg.push(
188188
block,
189189
Statement { source_info, kind: StatementKind::StorageLive(result) },

compiler/rustc_mir_build/src/build/expr/as_temp.rs

-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5252
let local_info = match expr.kind {
5353
ExprKind::StaticRef { def_id, .. } => {
5454
assert!(!this.tcx.is_thread_local_static(def_id));
55-
local_decl.internal = true;
5655
LocalInfo::StaticRef { def_id, is_thread_local: false }
5756
}
5857
ExprKind::ThreadLocalRef(def_id) => {
5958
assert!(this.tcx.is_thread_local_static(def_id));
60-
local_decl.internal = true;
6159
LocalInfo::StaticRef { def_id, is_thread_local: true }
6260
}
6361
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {

compiler/rustc_mir_build/src/build/matches/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17981798
let fake_borrow_ty =
17991799
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, fake_borrow_deref_ty);
18001800
let mut fake_borrow_temp = LocalDecl::new(fake_borrow_ty, temp_span);
1801-
fake_borrow_temp.internal = self.local_decls[matched_place.local].internal;
18021801
fake_borrow_temp.local_info = ClearCrossCrate::Set(Box::new(LocalInfo::FakeBorrow));
18031802
let fake_borrow_temp = self.local_decls.push(fake_borrow_temp);
18041803

@@ -2268,7 +2267,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22682267
ty: var_ty,
22692268
user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
22702269
source_info,
2271-
internal: false,
22722270
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
22732271
VarBindingForm {
22742272
binding_mode,
@@ -2298,7 +2296,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22982296
ty: Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, var_ty),
22992297
user_ty: None,
23002298
source_info,
2301-
internal: false,
23022299
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(
23032300
BindingForm::RefForGuard,
23042301
))),

compiler/rustc_mir_build/src/build/misc.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1515
/// N.B., **No cleanup is scheduled for this temporary.** You should
1616
/// call `schedule_drop` once the temporary is initialized.
1717
pub(crate) fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
18-
// Mark this local as internal to avoid temporaries with types not present in the
19-
// user's code resulting in ICEs from the generator transform.
20-
let temp = self.local_decls.push(LocalDecl::new(ty, span).internal());
18+
let temp = self.local_decls.push(LocalDecl::new(ty, span));
2119
let place = Place::from(temp);
2220
debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty);
2321
place

compiler/rustc_mir_build/src/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
725725
// Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
726726
// statement.
727727
fn add_dummy_assignment(&mut self, span: Span, block: BasicBlock, source_info: SourceInfo) {
728-
let local_decl = LocalDecl::new(Ty::new_unit(self.tcx), span).internal();
728+
let local_decl = LocalDecl::new(Ty::new_unit(self.tcx), span);
729729
let temp_place = Place::from(self.local_decls.push(local_decl));
730730
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
731731
}

compiler/rustc_mir_transform/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
179179
// Check the base local: it might be an unsafe-to-access static. We only check derefs of the
180180
// temporary holding the static pointer to avoid duplicate errors
181181
// <https://github.com/rust-lang/rust/pull/78068#issuecomment-731753506>.
182-
if decl.internal && place.projection.first() == Some(&ProjectionElem::Deref) {
182+
if place.projection.first() == Some(&ProjectionElem::Deref) {
183183
// If the projection root is an artificial local that we introduced when
184184
// desugaring `static`, give a more specific error message
185185
// (avoid the general "raw pointer" clause below, that would only be confusing).

compiler/rustc_mir_transform/src/deref_separator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
3737
for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() {
3838
if !p_ref.projection.is_empty() && p_elem == ProjectionElem::Deref {
3939
let ty = p_ref.ty(self.local_decls, self.tcx).ty;
40-
let temp = self.patcher.new_internal_with_info(
40+
let temp = self.patcher.new_local_with_info(
4141
ty,
4242
self.local_decls[p_ref.local].source_info.span,
4343
LocalInfo::DerefTemp,

compiler/rustc_mir_transform/src/elaborate_box_derefs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx, 'a> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'tcx, 'a> {
6969
let (unique_ty, nonnull_ty, ptr_ty) =
7070
build_ptr_tys(tcx, base_ty.boxed_ty(), self.unique_did, self.nonnull_did);
7171

72-
let ptr_local = self.patch.new_internal(ptr_ty, source_info.span);
72+
let ptr_local = self.patch.new_temp(ptr_ty, source_info.span);
7373

7474
self.patch.add_assign(
7575
location,

compiler/rustc_mir_transform/src/elaborate_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
271271
let tcx = self.tcx;
272272
let patch = &mut self.patch;
273273
debug!("create_drop_flag({:?})", self.body.span);
274-
self.drop_flags[index].get_or_insert_with(|| patch.new_internal(tcx.types.bool, span));
274+
self.drop_flags[index].get_or_insert_with(|| patch.new_temp(tcx.types.bool, span));
275275
}
276276

277277
fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {

compiler/rustc_mir_transform/src/generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl<'tcx> TransformVisitor<'tcx> {
321321

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

compiler/rustc_mir_transform/src/inline.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,7 @@ impl<'tcx> Inliner<'tcx> {
616616
// If there are any locals without storage markers, give them storage only for the
617617
// duration of the call.
618618
for local in callee_body.vars_and_temps_iter() {
619-
if !callee_body.local_decls[local].internal
620-
&& integrator.always_live_locals.contains(local)
621-
{
619+
if integrator.always_live_locals.contains(local) {
622620
let new_local = integrator.map_local(local);
623621
caller_body[callsite.block].statements.push(Statement {
624622
source_info: callsite.source_info,
@@ -641,9 +639,7 @@ impl<'tcx> Inliner<'tcx> {
641639
n += 1;
642640
}
643641
for local in callee_body.vars_and_temps_iter().rev() {
644-
if !callee_body.local_decls[local].internal
645-
&& integrator.always_live_locals.contains(local)
646-
{
642+
if integrator.always_live_locals.contains(local) {
647643
let new_local = integrator.map_local(local);
648644
caller_body[block].statements.push(Statement {
649645
source_info: callsite.source_info,

tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_2 = const u8::MAX;
2121
StorageLive(_3);
2222
_3 = const 1_u8;
23+
StorageLive(_4);
2324
- _4 = CheckedAdd(_2, _3);
2425
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
2526
+ _4 = const (0_u8, true);
@@ -29,6 +30,7 @@
2930
bb1: {
3031
- _1 = move (_4.0: u8);
3132
+ _1 = const 0_u8;
33+
StorageDead(_4);
3234
StorageDead(_3);
3335
StorageDead(_2);
3436
StorageDead(_1);

tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_2 = const u8::MAX;
2121
StorageLive(_3);
2222
_3 = const 1_u8;
23+
StorageLive(_4);
2324
- _4 = CheckedAdd(_2, _3);
2425
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue];
2526
+ _4 = const (0_u8, true);
@@ -29,6 +30,7 @@
2930
bb1: {
3031
- _1 = move (_4.0: u8);
3132
+ _1 = const 0_u8;
33+
StorageDead(_4);
3234
StorageDead(_3);
3335
StorageDead(_2);
3436
StorageDead(_1);

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.panic-abort.diff

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_2 = const u8::MAX;
2121
StorageLive(_3);
2222
_3 = const 1_u8;
23+
StorageLive(_4);
2324
- _4 = CheckedAdd(_2, _3);
2425
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
2526
+ _4 = CheckedAdd(const u8::MAX, const 1_u8);
@@ -29,6 +30,7 @@
2930
bb1: {
3031
- _1 = move (_4.0: u8);
3132
+ _1 = const 0_u8;
33+
StorageDead(_4);
3234
StorageDead(_3);
3335
StorageDead(_2);
3436
StorageDead(_1);

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.panic-unwind.diff

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_2 = const u8::MAX;
2121
StorageLive(_3);
2222
_3 = const 1_u8;
23+
StorageLive(_4);
2324
- _4 = CheckedAdd(_2, _3);
2425
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue];
2526
+ _4 = CheckedAdd(const u8::MAX, const 1_u8);
@@ -29,6 +30,7 @@
2930
bb1: {
3031
- _1 = move (_4.0: u8);
3132
+ _1 = const 0_u8;
33+
StorageDead(_4);
3234
StorageDead(_3);
3335
StorageDead(_2);
3436
StorageDead(_1);

tests/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
4141
_7 = (move _8,);
4242
StorageLive(_9);
4343
_9 = move (_7.0: i32);
44+
StorageLive(_10);
45+
StorageLive(_12);
4446
StorageLive(_11);
4547
_10 = ((*_6).0: &i32);
4648
_11 = (*_10);
@@ -50,6 +52,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
5052
_0 = (move _11, move _13);
5153
StorageDead(_13);
5254
StorageDead(_11);
55+
StorageDead(_12);
56+
StorageDead(_10);
5357
StorageDead(_9);
5458
StorageDead(_8);
5559
StorageDead(_7);

tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
+ StorageDead(_3);
4545
+ StorageLive(_6);
4646
+ _6 = const false;
47+
+ StorageLive(_7);
48+
+ StorageLive(_8);
4749
+ _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
4850
+ _8 = discriminant((*_7));
4951
+ switchInt(move _8) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9];
@@ -52,6 +54,8 @@
5254
bb1: {
5355
- _3 = &mut _4;
5456
- _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>::new(move _3) -> [return: bb2, unwind unreachable];
57+
+ StorageDead(_8);
58+
+ StorageDead(_7);
5559
+ StorageDead(_6);
5660
+ StorageDead(_2);
5761
+ drop(_4) -> [return: bb2, unwind unreachable];

tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff

+4
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@
5252
- _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
5353
+ StorageLive(_6);
5454
+ _6 = const false;
55+
+ StorageLive(_7);
56+
+ StorageLive(_8);
5557
+ _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
5658
+ _8 = discriminant((*_7));
5759
+ switchInt(move _8) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
5860
}
5961

6062
- bb3: {
6163
+ bb1: {
64+
+ StorageDead(_8);
65+
+ StorageDead(_7);
6266
+ StorageDead(_6);
6367
StorageDead(_2);
6468
- drop(_4) -> [return: bb4, unwind: bb6];

tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff

+10
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,14 @@
122122
+ _3 = const _;
123123
+ _2 = Vec::<u32> { buf: move _3, len: const 0_usize };
124124
+ StorageDead(_3);
125+
+ StorageLive(_4);
126+
+ StorageLive(_5);
127+
+ StorageLive(_6);
128+
+ StorageLive(_7);
125129
+ _4 = SizeOf(std::vec::Vec<u32>);
126130
+ _5 = AlignOf(std::vec::Vec<u32>);
127131
+ StorageLive(_8);
132+
+ StorageLive(_10);
128133
+ StorageLive(_11);
129134
+ StorageLive(_12);
130135
+ StorageLive(_13);
@@ -178,10 +183,15 @@
178183
+ StorageDead(_13);
179184
+ StorageDead(_12);
180185
+ StorageDead(_11);
186+
+ StorageDead(_10);
181187
+ StorageDead(_8);
182188
+ _1 = ShallowInitBox(move _6, std::vec::Vec<u32>);
183189
+ _7 = (((_1.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>);
184190
+ (*_7) = move _2;
191+
+ StorageDead(_7);
192+
+ StorageDead(_6);
193+
+ StorageDead(_5);
194+
+ StorageDead(_4);
185195
StorageDead(_2);
186196
_0 = const ();
187197
- drop(_1) -> [return: bb3, unwind unreachable];

0 commit comments

Comments
 (0)