Auto merge of #116427 - cjgillot:no-internal, r=oli-obk · rust-lang/rust@5c3a0e9 (original) (raw)

38 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
237 237 if self.const_kind() == hir::ConstContext::ConstFn {
238 238 for (idx, local) in body.local_decls.iter_enumerated() {
239 239 // Handle the return place below.
240 -if idx == RETURN_PLACE |
240 +if idx == RETURN_PLACE {
241 241 continue;
242 242 }
243 243
Original file line number Diff line number Diff line change
@@ -830,22 +830,6 @@ pub struct LocalDecl<'tcx> {
830 830 // FIXME(matthewjasper) Don't store in this in `Body`
831 831 pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>,
832 832
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 -
849 833 /// The type of this local.
850 834 pub ty: Ty<'tcx>,
851 835
@@ -1058,7 +1042,7 @@ impl<'tcx> LocalDecl<'tcx> {
1058 1042 self.source_info.span.desugaring_kind().is_some()
1059 1043 }
1060 1044
1061 -/// Creates a new `LocalDecl` for a temporary: mutable, non-internal.
1045 +/// Creates a new `LocalDecl` for a temporary, mutable.
1062 1046 #[inline]
1063 1047 pub fn new(ty: Ty<'tcx>, span: Span) -> Self {
1064 1048 Self::with_source_info(ty, SourceInfo::outermost(span))
@@ -1070,20 +1054,12 @@ impl<'tcx> LocalDecl<'tcx> {
1070 1054 LocalDecl {
1071 1055 mutability: Mutability::Mut,
1072 1056 local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
1073 -internal: false,
1074 1057 ty,
1075 1058 user_ty: None,
1076 1059 source_info,
1077 1060 }
1078 1061 }
1079 1062
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 -
1087 1063 /// Converts `self` into same `LocalDecl` except tagged as immutable.
1088 1064 #[inline]
1089 1065 pub fn immutable(mut self) -> Self {
Original file line number Diff line number Diff line change
@@ -127,15 +127,15 @@ impl<'tcx> MirPatch<'tcx> {
127 127 Location { block: bb, statement_index: offset }
128 128 }
129 129
130 -pub fn new_internal_with_info(
130 +pub fn new_local_with_info(
131 131 &mut self,
132 132 ty: Ty<'tcx>,
133 133 span: Span,
134 134 local_info: LocalInfo<'tcx>,
135 135 ) -> Local {
136 136 let index = self.next_local;
137 137 self.next_local += 1;
138 -let mut new_decl = LocalDecl::new(ty, span).internal();
138 +let mut new_decl = LocalDecl::new(ty, span);
139 139 **new_decl.local_info.as_mut().assert_crate_local() = local_info;
140 140 self.new_locals.push(new_decl);
141 141 Local::new(index)
@@ -148,13 +148,6 @@ impl<'tcx> MirPatch<'tcx> {
148 148 Local::new(index)
149 149 }
150 150
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 -
158 151 pub fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
159 152 let block = BasicBlock::new(self.patch_map.len());
160 153 debug!("MirPatch: new_block: {:?}: {:?}", block, data);
Original file line number Diff line number Diff line change
@@ -815,7 +815,6 @@ macro_rules! make_mir_visitor {
815 815 ty,
816 816 user_ty,
817 817 source_info,
818 - internal: _,
819 818 local_info: _,
820 819 } = local_decl;
821 820
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
183 183 // The `Box` temporary created here is not a part of the HIR,
184 184 // and therefore is not considered during generator auto-trait
185 185 // 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));
187 187 this.cfg.push(
188 188 block,
189 189 Statement { source_info, kind: StatementKind::StorageLive(result) },
Original file line number Diff line number Diff line change
@@ -52,12 +52,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
52 52 let local_info = match expr.kind {
53 53 ExprKind::StaticRef { def_id, .. } => {
54 54 assert!(!this.tcx.is_thread_local_static(def_id));
55 - local_decl.internal = true;
56 55 LocalInfo::StaticRef { def_id, is_thread_local: false }
57 56 }
58 57 ExprKind::ThreadLocalRef(def_id) => {
59 58 assert!(this.tcx.is_thread_local_static(def_id));
60 - local_decl.internal = true;
61 59 LocalInfo::StaticRef { def_id, is_thread_local: true }
62 60 }
63 61 ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
Original file line number Diff line number Diff line change
@@ -1798,7 +1798,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1798 1798 let fake_borrow_ty =
1799 1799 Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, fake_borrow_deref_ty);
1800 1800 let mut fake_borrow_temp = LocalDecl::new(fake_borrow_ty, temp_span);
1801 - fake_borrow_temp.internal = self.local_decls[matched_place.local].internal;
1802 1801 fake_borrow_temp.local_info = ClearCrossCrate::Set(Box::new(LocalInfo::FakeBorrow));
1803 1802 let fake_borrow_temp = self.local_decls.push(fake_borrow_temp);
1804 1803
@@ -2268,7 +2267,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2268 2267 ty: var_ty,
2269 2268 user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
2270 2269 source_info,
2271 -internal: false,
2272 2270 local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
2273 2271 VarBindingForm {
2274 2272 binding_mode,
@@ -2298,7 +2296,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2298 2296 ty: Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, var_ty),
2299 2297 user_ty: None,
2300 2298 source_info,
2301 -internal: false,
2302 2299 local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(
2303 2300 BindingForm::RefForGuard,
2304 2301 ))),
Original file line number Diff line number Diff line change
@@ -15,9 +15,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15 15 /// N.B., **No cleanup is scheduled for this temporary.** You should
16 16 /// call `schedule_drop` once the temporary is initialized.
17 17 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));
21 19 let place = Place::from(temp);
22 20 debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty);
23 21 place
Original file line number Diff line number Diff line change
@@ -725,7 +725,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
725 725 // Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
726 726 // statement.
727 727 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);
729 729 let temp_place = Place::from(self.local_decls.push(local_decl));
730 730 self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
731 731 }
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
179 179 // Check the base local: it might be an unsafe-to-access static. We only check derefs of the
180 180 // temporary holding the static pointer to avoid duplicate errors
181 181 // 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) {
183 183 // If the projection root is an artificial local that we introduced when
184 184 // desugaring `static`, give a more specific error message
185 185 // (avoid the general "raw pointer" clause below, that would only be confusing).
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
37 37 for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() {
38 38 if !p_ref.projection.is_empty() && p_elem == ProjectionElem::Deref {
39 39 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(
41 41 ty,
42 42 self.local_decls[p_ref.local].source_info.span,
43 43 LocalInfo::DerefTemp,
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ impl<'tcx, 'a> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'tcx, 'a> {
69 69 let (unique_ty, nonnull_ty, ptr_ty) =
70 70 build_ptr_tys(tcx, base_ty.boxed_ty(), self.unique_did, self.nonnull_did);
71 71
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);
73 73
74 74 self.patch.add_assign(
75 75 location,
Original file line number Diff line number Diff line change
@@ -271,7 +271,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
271 271 let tcx = self.tcx;
272 272 let patch = &mut self.patch;
273 273 debug!("create_drop_flag({:?})", self.body.span);
274 -self.drop_flags[index].get_or_insert_with(|
274 +self.drop_flags[index].get_or_insert_with(|
275 275 }
276 276
277 277 fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {
Original file line number Diff line number Diff line change
@@ -321,7 +321,7 @@ impl<'tcx> TransformVisitor<'tcx> {
321 321
322 322 // Create a statement which reads the discriminant into a temporary
323 323 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);
325 325 let local_decls_len = body.local_decls.push(temp_decl);
326 326 let temp = Place::from(local_decls_len);
327 327
Original file line number Diff line number Diff line change
@@ -616,9 +616,7 @@ impl<'tcx> Inliner<'tcx> {
616 616 // If there are any locals without storage markers, give them storage only for the
617 617 // duration of the call.
618 618 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) {
622 620 let new_local = integrator.map_local(local);
623 621 caller_body[callsite.block].statements.push(Statement {
624 622 source_info: callsite.source_info,
@@ -641,9 +639,7 @@ impl<'tcx> Inliner<'tcx> {
641 639 n += 1;
642 640 }
643 641 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) {
647 643 let new_local = integrator.map_local(local);
648 644 caller_body[block].statements.push(Statement {
649 645 source_info: callsite.source_info,
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
20 20 _2 = const u8::MAX;
21 21 StorageLive(_3);
22 22 _3 = const 1_u8;
23 + StorageLive(_4);
23 24 - _4 = CheckedAdd(_2, _3);
24 25 - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
25 26 + _4 = const (0_u8, true);
@@ -29,6 +30,7 @@
29 30 bb1: {
30 31 - _1 = move (_4.0: u8);
31 32 + _1 = const 0_u8;
33 + StorageDead(_4);
32 34 StorageDead(_3);
33 35 StorageDead(_2);
34 36 StorageDead(_1);
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
20 20 _2 = const u8::MAX;
21 21 StorageLive(_3);
22 22 _3 = const 1_u8;
23 + StorageLive(_4);
23 24 - _4 = CheckedAdd(_2, _3);
24 25 - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue];
25 26 + _4 = const (0_u8, true);
@@ -29,6 +30,7 @@
29 30 bb1: {
30 31 - _1 = move (_4.0: u8);
31 32 + _1 = const 0_u8;
33 + StorageDead(_4);
32 34 StorageDead(_3);
33 35 StorageDead(_2);
34 36 StorageDead(_1);
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
20 20 _2 = const u8::MAX;
21 21 StorageLive(_3);
22 22 _3 = const 1_u8;
23 + StorageLive(_4);
23 24 - _4 = CheckedAdd(_2, _3);
24 25 - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
25 26 + _4 = CheckedAdd(const u8::MAX, const 1_u8);
@@ -29,6 +30,7 @@
29 30 bb1: {
30 31 - _1 = move (_4.0: u8);
31 32 + _1 = const 0_u8;
33 + StorageDead(_4);
32 34 StorageDead(_3);
33 35 StorageDead(_2);
34 36 StorageDead(_1);
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
20 20 _2 = const u8::MAX;
21 21 StorageLive(_3);
22 22 _3 = const 1_u8;
23 + StorageLive(_4);
23 24 - _4 = CheckedAdd(_2, _3);
24 25 - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue];
25 26 + _4 = CheckedAdd(const u8::MAX, const 1_u8);
@@ -29,6 +30,7 @@
29 30 bb1: {
30 31 - _1 = move (_4.0: u8);
31 32 + _1 = const 0_u8;
33 + StorageDead(_4);
32 34 StorageDead(_3);
33 35 StorageDead(_2);
34 36 StorageDead(_1);
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
41 41 _7 = (move _8,);
42 42 StorageLive(_9);
43 43 _9 = move (_7.0: i32);
44 +StorageLive(_10);
45 +StorageLive(_12);
44 46 StorageLive(_11);
45 47 _10 = ((*_6).0: &i32);
46 48 _11 = (*_10);
@@ -50,6 +52,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
50 52 _0 = (move _11, move _13);
51 53 StorageDead(_13);
52 54 StorageDead(_11);
55 +StorageDead(_12);
56 +StorageDead(_10);
53 57 StorageDead(_9);
54 58 StorageDead(_8);
55 59 StorageDead(_7);
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@
44 44 + StorageDead(_3);
45 45 + StorageLive(_6);
46 46 + _6 = const false;
47 ++ StorageLive(_7);
48 ++ StorageLive(_8);
47 49 + _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
48 50 + _8 = discriminant((*_7));
49 51 + switchInt(move _8) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9];
@@ -52,6 +54,8 @@
52 54 bb1: {
53 55 - _3 = &mut _4;
54 56 - _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);
55 59 + StorageDead(_6);
56 60 + StorageDead(_2);
57 61 + drop(_4) -> [return: bb2, unwind unreachable];
Original file line number Diff line number Diff line change
@@ -52,13 +52,17 @@
52 52 - _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
53 53 + StorageLive(_6);
54 54 + _6 = const false;
55 ++ StorageLive(_7);
56 ++ StorageLive(_8);
55 57 + _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
56 58 + _8 = discriminant((*_7));
57 59 + switchInt(move _8) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
58 60 }
59 61
60 62 - bb3: {
61 63 + bb1: {
64 ++ StorageDead(_8);
65 ++ StorageDead(_7);
62 66 + StorageDead(_6);
63 67 StorageDead(_2);
64 68 - drop(_4) -> [return: bb4, unwind: bb6];
Original file line number Diff line number Diff line change
@@ -122,9 +122,14 @@
122 122 + _3 = const _;
123 123 + _2 = Vec:: { buf: move _3, len: const 0_usize };
124 124 + StorageDead(_3);
125 ++ StorageLive(_4);
126 ++ StorageLive(_5);
127 ++ StorageLive(_6);
128 ++ StorageLive(_7);
125 129 + _4 = SizeOf(std::vec::Vec);
126 130 + _5 = AlignOf(std::vec::Vec);
127 131 + StorageLive(_8);
132 ++ StorageLive(_10);
128 133 + StorageLive(_11);
129 134 + StorageLive(_12);
130 135 + StorageLive(_13);
@@ -178,10 +183,15 @@
178 183 + StorageDead(_13);
179 184 + StorageDead(_12);
180 185 + StorageDead(_11);
186 ++ StorageDead(_10);
181 187 + StorageDead(_8);
182 188 + _1 = ShallowInitBox(move _6, std::vec::Vec);
183 189 + _7 = (((_1.0: std::ptr::Unique<std::vec::Vec>).0: std::ptr::NonNull<std::vec::Vec>).0: *const std::vec::Vec);
184 190 + (*_7) = move _2;
191 ++ StorageDead(_7);
192 ++ StorageDead(_6);
193 ++ StorageDead(_5);
194 ++ StorageDead(_4);
185 195 StorageDead(_2);
186 196 _0 = const ();
187 197 - drop(_1) -> [return: bb3, unwind unreachable];