Skip to main content

rustc_mir_dataflow/impls/
initialized.rs

1use std::assert_matches;
2
3use rustc_abi::VariantIdx;
4use rustc_index::Idx;
5use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
6use rustc_middle::bug;
7use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
8use rustc_middle::ty::{self, TyCtxt};
9use smallvec::SmallVec;
10use tracing::{debug, instrument};
11
12use crate::drop_flag_effects::{DropFlagState, InactiveVariants};
13use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
14use crate::{
15    Analysis, GenKill, MaybeReachable, SwitchTargetIndex, drop_flag_effects,
16    drop_flag_effects_for_function_entry, drop_flag_effects_for_location, on_all_children_bits,
17    on_lookup_result_bits,
18};
19
20// Used by both `MaybeInitializedPlaces` and `MaybeUninitializedPlaces`.
21pub struct MaybePlacesSwitchIntData<'tcx> {
22    enum_place: mir::Place<'tcx>,
23
24    // Variant indices targeted by the SwitchInt. For example, if you have:
25    // ```
26    // enum E { A = 1, B = 3, C = 5, D = 7 }
27    // ```
28    // and a `SwitchInt(A -> bb1, C -> bb2, _ -> bb3)`, this vec will contain `[0, 2]` because
29    // those are the variant indices for `A` and `C`.
30    variants: SmallVec<[VariantIdx; 4]>,
31}
32
33impl<'tcx> MaybePlacesSwitchIntData<'tcx> {
34    fn new(
35        tcx: TyCtxt<'tcx>,
36        body: &Body<'tcx>,
37        block: mir::BasicBlock,
38        targets: &mir::SwitchTargets,
39        discr: &mir::Operand<'tcx>,
40    ) -> Option<Self> {
41        let Some(discr) = discr.place() else { return None };
42
43        // Inspect a `SwitchInt`-terminated basic block to see if the condition of that `SwitchInt`
44        // is an enum discriminant.
45        //
46        // We expect such blocks to have a call to `discriminant` as their last statement like so:
47        // ```text
48        // ...
49        // _42 = discriminant(_1)
50        // SwitchInt(_42, ..)
51        // ```
52        // If the basic block matches this pattern, this function gathers the place corresponding
53        // to the enum (`_1` in the example above) as well as the discriminants.
54        let block_data = &body[block];
55        for statement in block_data.statements.iter().rev() {
56            match statement.kind {
57                mir::StatementKind::Assign((lhs, mir::Rvalue::Discriminant(enum_place)))
58                    if lhs == discr =>
59                {
60                    match enum_place.ty(body, tcx).ty.kind() {
61                        ty::Adt(enum_def, _) => {
62                            // For each value in the SwitchInt, find the VariantIdx for the variant
63                            // with that value. This works because `discriminant_vals` and
64                            // `targets.all_values()` are guaranteed to list variants in the same
65                            // AdtDef order. (If that ever changes the `expect` will panic.)
66                            let mut discriminants = enum_def.discriminants(tcx);
67                            let variants = targets
68                                .all_values()
69                                .iter()
70                                .map(|value| {
71                                    // On each call to this closure `find` only consumes part of
72                                    // the `discriminants` iterator.
73                                    discriminants
74                                        .find(|(_, discr)| discr.val == value.get())
75                                        .expect("SwitchInt vals should match a variant")
76                                        .0
77                                })
78                                .collect();
79
80                            return Some(MaybePlacesSwitchIntData { enum_place, variants });
81                        }
82
83                        // `Rvalue::Discriminant` is also used to get the active yield point for a
84                        // coroutine, but we do not need edge-specific effects in that case. This
85                        // may change in the future.
86                        ty::Coroutine(..) => break,
87
88                        t => ::rustc_middle::util::bug::bug_fmt(format_args!("`discriminant` called on unexpected type {0:?}",
        t))bug!("`discriminant` called on unexpected type {:?}", t),
89                    }
90                }
91                mir::StatementKind::Coverage(_) => continue,
92                _ => break,
93            }
94        }
95        None
96    }
97}
98
99/// `MaybeInitializedPlaces` tracks all places that might be
100/// initialized upon reaching a particular point in the control flow
101/// for a function.
102///
103/// For example, in code like the following, we have corresponding
104/// dataflow information shown in the right-hand comments.
105///
106/// ```rust
107/// struct S;
108/// #[rustfmt::skip]
109/// fn foo(p: bool) {                           // maybe-init:
110///                                             // {p}
111///     let a = S; let mut b = S; let c; let d; // {p, a, b}
112///
113///     if p {
114///         drop(a);                            // {p,    b}
115///         b = S;                              // {p,    b}
116///
117///     } else {
118///         drop(b);                            // {p, a}
119///         d = S;                              // {p, a,       d}
120///
121///     }                                       // {p, a, b,    d}
122///
123///     c = S;                                  // {p, a, b, c, d}
124/// }
125/// ```
126///
127/// To determine whether a place is *definitely* initialized at a
128/// particular control-flow point, one can take the set-complement
129/// of the data from `MaybeUninitializedPlaces` at the corresponding
130/// control-flow point.
131///
132/// Similarly, at a given `drop` statement, the set-intersection
133/// between this data and `MaybeUninitializedPlaces` yields the set of
134/// places that would require a dynamic drop-flag at that statement.
135pub struct MaybeInitializedPlaces<'a, 'tcx> {
136    tcx: TyCtxt<'tcx>,
137    body: &'a Body<'tcx>,
138    move_data: &'a MoveData<'tcx>,
139    exclude_inactive_in_otherwise: bool,
140    skip_unreachable_unwind: bool,
141}
142
143impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
144    pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
145        MaybeInitializedPlaces {
146            tcx,
147            body,
148            move_data,
149            exclude_inactive_in_otherwise: false,
150            skip_unreachable_unwind: false,
151        }
152    }
153
154    /// Ensures definitely inactive variants are excluded from the set of initialized places for
155    /// blocks reached through an `otherwise` edge.
156    pub fn exclude_inactive_in_otherwise(mut self) -> Self {
157        self.exclude_inactive_in_otherwise = true;
158        self
159    }
160
161    pub fn skipping_unreachable_unwind(mut self) -> Self {
162        self.skip_unreachable_unwind = true;
163        self
164    }
165
166    pub fn is_unwind_dead(
167        &self,
168        place: mir::Place<'tcx>,
169        state: &<Self as Analysis<'tcx>>::Domain,
170    ) -> bool {
171        if let LookupResult::Exact(path) = self.move_data().rev_lookup.find(place.as_ref()) {
172            let mut maybe_live = false;
173            on_all_children_bits(self.move_data(), path, |child| {
174                maybe_live |= state.contains(child);
175            });
176            !maybe_live
177        } else {
178            false
179        }
180    }
181}
182
183impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> {
184    fn move_data(&self) -> &MoveData<'tcx> {
185        self.move_data
186    }
187}
188
189/// `MaybeUninitializedPlaces` tracks all places that might be
190/// uninitialized upon reaching a particular point in the control flow
191/// for a function.
192///
193/// For example, in code like the following, we have corresponding
194/// dataflow information shown in the right-hand comments.
195///
196/// ```rust
197/// struct S;
198/// #[rustfmt::skip]
199/// fn foo(p: bool) {                           // maybe-uninit:
200///                                             // {a, b, c, d}
201///     let a = S; let mut b = S; let c; let d; // {      c, d}
202///
203///     if p {
204///         drop(a);                            // {a,    c, d}
205///         b = S;                              // {a,    c, d}
206///
207///     } else {
208///         drop(b);                            // {   b, c, d}
209///         d = S;                              // {   b, c   }
210///
211///     }                                       // {a, b, c, d}
212///
213///     c = S;                                  // {a, b,    d}
214/// }
215/// ```
216///
217/// To determine whether a place is *definitely* uninitialized at a
218/// particular control-flow point, one can take the set-complement
219/// of the data from `MaybeInitializedPlaces` at the corresponding
220/// control-flow point.
221///
222/// Similarly, at a given `drop` statement, the set-intersection
223/// between this data and `MaybeInitializedPlaces` yields the set of
224/// places that would require a dynamic drop-flag at that statement.
225pub struct MaybeUninitializedPlaces<'a, 'tcx> {
226    tcx: TyCtxt<'tcx>,
227    body: &'a Body<'tcx>,
228    move_data: &'a MoveData<'tcx>,
229
230    mark_inactive_variants_as_uninit: bool,
231    skip_unreachable_unwind: DenseBitSet<mir::BasicBlock>,
232}
233
234impl<'a, 'tcx> MaybeUninitializedPlaces<'a, 'tcx> {
235    pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
236        MaybeUninitializedPlaces {
237            tcx,
238            body,
239            move_data,
240            mark_inactive_variants_as_uninit: false,
241            skip_unreachable_unwind: DenseBitSet::new_empty(body.basic_blocks.len()),
242        }
243    }
244
245    /// Causes inactive enum variants to be marked as "maybe uninitialized" after a switch on an
246    /// enum discriminant.
247    ///
248    /// This is correct in a vacuum but is not the default because it causes problems in the borrow
249    /// checker, where this information gets propagated along `FakeEdge`s.
250    pub fn mark_inactive_variants_as_uninit(mut self) -> Self {
251        self.mark_inactive_variants_as_uninit = true;
252        self
253    }
254
255    pub fn skipping_unreachable_unwind(
256        mut self,
257        unreachable_unwind: DenseBitSet<mir::BasicBlock>,
258    ) -> Self {
259        self.skip_unreachable_unwind = unreachable_unwind;
260        self
261    }
262}
263
264impl<'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
265    fn move_data(&self) -> &MoveData<'tcx> {
266        self.move_data
267    }
268}
269
270/// `EverInitializedPlaces` tracks all initializations that may have occurred
271/// upon reaching a particular point in the control flow for a function,
272/// without an intervening `StorageDead`.
273///
274/// This dataflow is used to determine if an immutable local variable may
275/// be assigned to.
276///
277/// For example, in code like the following, we have corresponding
278/// dataflow information shown in the right-hand comments. Underscored indices
279/// are used to distinguish between multiple initializations of the same local
280/// variable, e.g. `b_0` and `b_1`.
281///
282/// ```rust
283/// struct S;
284/// #[rustfmt::skip]
285/// fn foo(p: bool) {                           // ever-init:
286///                                             // {p,                  }
287///     let a = S; let mut b = S; let c; let d; // {p, a, b_0,          }
288///
289///     if p {
290///         drop(a);                            // {p, a, b_0,          }
291///         b = S;                              // {p, a, b_0, b_1,     }
292///
293///     } else {
294///         drop(b);                            // {p, a, b_0, b_1,     }
295///         d = S;                              // {p, a, b_0, b_1,    d}
296///
297///     }                                       // {p, a, b_0, b_1,    d}
298///
299///     c = S;                                  // {p, a, b_0, b_1, c, d}
300/// }
301/// ```
302pub struct EverInitializedPlaces<'a, 'tcx> {
303    body: &'a Body<'tcx>,
304    move_data: &'a MoveData<'tcx>,
305}
306
307impl<'a, 'tcx> EverInitializedPlaces<'a, 'tcx> {
308    pub fn new(body: &'a Body<'tcx>, move_data: &'a MoveData<'tcx>) -> Self {
309        EverInitializedPlaces { body, move_data }
310    }
311}
312
313impl<'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'_, 'tcx> {
314    fn move_data(&self) -> &MoveData<'tcx> {
315        self.move_data
316    }
317}
318
319impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
320    fn update_bits(
321        state: &mut <Self as Analysis<'tcx>>::Domain,
322        path: MovePathIndex,
323        dfstate: DropFlagState,
324    ) {
325        match dfstate {
326            DropFlagState::Absent => state.kill(path),
327            DropFlagState::Present => state.gen_(path),
328        }
329    }
330}
331
332impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
333    fn update_bits(
334        state: &mut <Self as Analysis<'tcx>>::Domain,
335        path: MovePathIndex,
336        dfstate: DropFlagState,
337    ) {
338        match dfstate {
339            DropFlagState::Absent => state.gen_(path),
340            DropFlagState::Present => state.kill(path),
341        }
342    }
343}
344
345impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
346    /// There can be many more `MovePathIndex` than there are locals in a MIR body.
347    /// We use a mixed bitset to avoid paying too high a memory footprint.
348    type Domain = MaybeReachable<MixedBitSet<MovePathIndex>>;
349
350    type SwitchIntData = MaybePlacesSwitchIntData<'tcx>;
351
352    const NAME: &'static str = "maybe_init";
353
354    fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
355        // bottom = uninitialized
356        MaybeReachable::Unreachable
357    }
358
359    fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
360        *state =
361            MaybeReachable::Reachable(MixedBitSet::new_empty(self.move_data().move_paths.len()));
362        drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
363            if !(s == DropFlagState::Present) {
    ::core::panicking::panic("assertion failed: s == DropFlagState::Present")
};assert!(s == DropFlagState::Present);
364            state.gen_(path);
365        });
366    }
367
368    fn apply_primary_statement_effect(
369        &self,
370        state: &mut Self::Domain,
371        statement: &mir::Statement<'tcx>,
372        location: Location,
373    ) {
374        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
375            Self::update_bits(state, path, s)
376        });
377
378        // Mark all places as "maybe init" if they are mutably borrowed. See #90752.
379        if self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration
380            && let Some((_, rvalue)) = statement.kind.as_assign()
381            && let mir::Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, place)
382                // FIXME: Does `&raw const foo` allow mutation? See #90413.
383                | mir::Rvalue::RawPtr(_, place) = rvalue
384            && let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref())
385        {
386            on_all_children_bits(self.move_data(), mpi, |child| {
387                state.gen_(child);
388            })
389        }
390    }
391
392    fn apply_primary_terminator_effect<'mir>(
393        &self,
394        state: &mut Self::Domain,
395        terminator: &'mir mir::Terminator<'tcx>,
396        location: Location,
397    ) -> TerminatorEdges<'mir, 'tcx> {
398        // Note: `edges` must be computed first because `drop_flag_effects_for_location` can change
399        // the result of `is_unwind_dead`.
400        let mut edges = terminator.edges();
401        if self.skip_unreachable_unwind
402            && let mir::TerminatorKind::Drop { target, unwind, place, replace: _, drop: _ } =
403                terminator.kind
404            && #[allow(non_exhaustive_omitted_patterns)] match unwind {
    mir::UnwindAction::Cleanup(_) => true,
    _ => false,
}matches!(unwind, mir::UnwindAction::Cleanup(_))
405            && self.is_unwind_dead(place, state)
406        {
407            edges = TerminatorEdges::Single(target);
408        }
409        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
410            Self::update_bits(state, path, s)
411        });
412        edges
413    }
414
415    fn apply_call_return_effect(
416        &self,
417        state: &mut Self::Domain,
418        _block: mir::BasicBlock,
419        return_places: CallReturnPlaces<'_, 'tcx>,
420    ) {
421        return_places.for_each(|place| {
422            // when a call returns successfully, that means we need to set
423            // the bits for that dest_place to 1 (initialized).
424            on_lookup_result_bits(
425                self.move_data(),
426                self.move_data().rev_lookup.find(place.as_ref()),
427                |mpi| {
428                    state.gen_(mpi);
429                },
430            );
431        });
432    }
433
434    fn get_switch_int_data(
435        &self,
436        block: mir::BasicBlock,
437        targets: &mir::SwitchTargets,
438        discr: &mir::Operand<'tcx>,
439    ) -> Option<Self::SwitchIntData> {
440        if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
441            return None;
442        }
443
444        MaybePlacesSwitchIntData::new(self.tcx, self.body, block, targets, discr)
445    }
446
447    fn apply_switch_int_edge_effect(
448        &self,
449        state: &mut Self::Domain,
450        data: &mut Self::SwitchIntData,
451        target_idx: SwitchTargetIndex,
452    ) {
453        let inactive_variants = match target_idx {
454            SwitchTargetIndex::Normal(target_idx) => {
455                InactiveVariants::Active(data.variants[target_idx])
456            }
457            SwitchTargetIndex::Otherwise if self.exclude_inactive_in_otherwise => {
458                InactiveVariants::Inactives(data.variants.clone())
459            }
460            _ => return,
461        };
462
463        // Kill all move paths that correspond to variants we know to be inactive along this
464        // particular outgoing edge of a `SwitchInt`.
465        drop_flag_effects::on_all_inactive_variants(
466            self.move_data,
467            data.enum_place,
468            &inactive_variants,
469            |mpi| state.kill(mpi),
470        );
471    }
472}
473
474/// There can be many more `MovePathIndex` than there are locals in a MIR body.
475/// We use a mixed bitset to avoid paying too high a memory footprint.
476pub type MaybeUninitializedPlacesDomain = MixedBitSet<MovePathIndex>;
477
478impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
479    type Domain = MaybeUninitializedPlacesDomain;
480
481    type SwitchIntData = MaybePlacesSwitchIntData<'tcx>;
482
483    const NAME: &'static str = "maybe_uninit";
484
485    fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
486        // bottom = initialized (`initialize_start_block` overwrites this on first entry)
487        MixedBitSet::new_empty(self.move_data().move_paths.len())
488    }
489
490    // sets state bits for Arg places
491    fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
492        // set all bits to 1 (uninit) before gathering counter-evidence
493        state.insert_all();
494
495        drop_flag_effects_for_function_entry(self.body, self.move_data, |path, s| {
496            if !(s == DropFlagState::Present) {
    ::core::panicking::panic("assertion failed: s == DropFlagState::Present")
};assert!(s == DropFlagState::Present);
497            state.remove(path);
498        });
499    }
500
501    fn apply_primary_statement_effect(
502        &self,
503        state: &mut Self::Domain,
504        _statement: &mir::Statement<'tcx>,
505        location: Location,
506    ) {
507        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
508            Self::update_bits(state, path, s)
509        });
510
511        // Unlike in `MaybeInitializedPlaces` above, we don't need to change the state when a
512        // mutable borrow occurs. Places cannot become uninitialized through a mutable reference.
513    }
514
515    fn apply_primary_terminator_effect<'mir>(
516        &self,
517        state: &mut Self::Domain,
518        terminator: &'mir mir::Terminator<'tcx>,
519        location: Location,
520    ) -> TerminatorEdges<'mir, 'tcx> {
521        drop_flag_effects_for_location(self.body, self.move_data, location, |path, s| {
522            Self::update_bits(state, path, s)
523        });
524        if self.skip_unreachable_unwind.contains(location.block) {
525            let mir::TerminatorKind::Drop { target, unwind, .. } = terminator.kind else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
526            {
    match unwind {
        mir::UnwindAction::Cleanup(_) => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "mir::UnwindAction::Cleanup(_)",
                ::core::option::Option::None);
        }
    }
};assert_matches!(unwind, mir::UnwindAction::Cleanup(_));
527            TerminatorEdges::Single(target)
528        } else {
529            terminator.edges()
530        }
531    }
532
533    fn apply_call_return_effect(
534        &self,
535        state: &mut Self::Domain,
536        _block: mir::BasicBlock,
537        return_places: CallReturnPlaces<'_, 'tcx>,
538    ) {
539        return_places.for_each(|place| {
540            // when a call returns successfully, that means we need to set
541            // the bits for that dest_place to 0 (initialized).
542            on_lookup_result_bits(
543                self.move_data(),
544                self.move_data().rev_lookup.find(place.as_ref()),
545                |mpi| {
546                    state.kill(mpi);
547                },
548            );
549        });
550    }
551
552    fn get_switch_int_data(
553        &self,
554        block: mir::BasicBlock,
555        targets: &mir::SwitchTargets,
556        discr: &mir::Operand<'tcx>,
557    ) -> Option<Self::SwitchIntData> {
558        if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
559            return None;
560        }
561
562        if !self.mark_inactive_variants_as_uninit {
563            return None;
564        }
565
566        MaybePlacesSwitchIntData::new(self.tcx, self.body, block, targets, discr)
567    }
568
569    fn apply_switch_int_edge_effect(
570        &self,
571        state: &mut Self::Domain,
572        data: &mut Self::SwitchIntData,
573        target_idx: SwitchTargetIndex,
574    ) {
575        let inactive_variants = match target_idx {
576            SwitchTargetIndex::Normal(target_idx) => {
577                InactiveVariants::Active(data.variants[target_idx])
578            }
579            SwitchTargetIndex::Otherwise => InactiveVariants::Inactives(data.variants.clone()),
580        };
581
582        // Mark all move paths that correspond to variants other than this one as maybe
583        // uninitialized (in reality, they are *definitely* uninitialized).
584        drop_flag_effects::on_all_inactive_variants(
585            self.move_data,
586            data.enum_place,
587            &inactive_variants,
588            |mpi| state.gen_(mpi),
589        );
590    }
591}
592
593/// There can be many more `InitIndex` than there are locals in a MIR body.
594/// We use a mixed bitset to avoid paying too high a memory footprint.
595pub type EverInitializedPlacesDomain = MixedBitSet<InitIndex>;
596
597impl<'tcx> Analysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
598    type Domain = EverInitializedPlacesDomain;
599
600    const NAME: &'static str = "ever_init";
601
602    fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
603        // bottom = no initialized variables by default
604        MixedBitSet::new_empty(self.move_data().inits.len())
605    }
606
607    fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) {
608        for arg_init in 0..body.arg_count {
609            state.insert(InitIndex::new(arg_init));
610        }
611    }
612
613    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("apply_primary_statement_effect",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(613u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("stmt")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("stmt");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("location");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stmt)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let move_data = self.move_data();
            let init_path_map = &move_data.init_path_map;
            let init_loc_map = &move_data.init_loc_map;
            let rev_lookup = &move_data.rev_lookup;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:625",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(625u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("initializes move_indexes {0:?}",
                                                                init_loc_map[location]) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            state.gen_all(init_loc_map[location].iter().copied());
            if let mir::StatementKind::StorageDead(local) = stmt.kind &&
                    let Some(move_path_index) = rev_lookup.find_local(local) {
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:633",
                                        "rustc_mir_dataflow::impls::initialized",
                                        ::tracing::Level::DEBUG,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                        ::tracing_core::__macro_support::Option::Some(633u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                        ::tracing_core::field::FieldSet::new(&["message"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("clears the ever initialized status of {0:?}",
                                                                    init_path_map[move_path_index]) as
                                                            &dyn ::tracing::field::Value))])
                            });
                    } else { ; }
                };
                state.kill_all(init_path_map[move_path_index].iter().copied());
            }
        }
    }
}#[instrument(skip(self, state), level = "debug")]
614    fn apply_primary_statement_effect(
615        &self,
616        state: &mut Self::Domain,
617        stmt: &mir::Statement<'tcx>,
618        location: Location,
619    ) {
620        let move_data = self.move_data();
621        let init_path_map = &move_data.init_path_map;
622        let init_loc_map = &move_data.init_loc_map;
623        let rev_lookup = &move_data.rev_lookup;
624
625        debug!("initializes move_indexes {:?}", init_loc_map[location]);
626        state.gen_all(init_loc_map[location].iter().copied());
627
628        if let mir::StatementKind::StorageDead(local) = stmt.kind
629            // End inits for StorageDead, so that an immutable variable can
630            // be reinitialized on the next iteration of the loop.
631            && let Some(move_path_index) = rev_lookup.find_local(local)
632        {
633            debug!("clears the ever initialized status of {:?}", init_path_map[move_path_index]);
634            state.kill_all(init_path_map[move_path_index].iter().copied());
635        }
636    }
637
638    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("apply_primary_terminator_effect",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(638u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("location");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: TerminatorEdges<'mir, 'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let move_data = self.move_data();
            let init_loc_map = &move_data.init_loc_map;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:647",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(647u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("terminator")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("terminator");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&terminator)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_dataflow/src/impls/initialized.rs:648",
                                    "rustc_mir_dataflow::impls::initialized",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_dataflow/src/impls/initialized.rs"),
                                    ::tracing_core::__macro_support::Option::Some(648u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::impls::initialized"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("initializes move_indexes {0:?}",
                                                                init_loc_map[location]) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            state.gen_all(init_loc_map[location].iter().filter(|init_index|
                            {
                                move_data.inits[**init_index].kind !=
                                    InitKind::NonPanicPathOnly
                            }).copied());
            terminator.edges()
        }
    }
}#[instrument(skip(self, state, terminator), level = "debug")]
639    fn apply_primary_terminator_effect<'mir>(
640        &self,
641        state: &mut Self::Domain,
642        terminator: &'mir mir::Terminator<'tcx>,
643        location: Location,
644    ) -> TerminatorEdges<'mir, 'tcx> {
645        let move_data = self.move_data();
646        let init_loc_map = &move_data.init_loc_map;
647        debug!(?terminator);
648        debug!("initializes move_indexes {:?}", init_loc_map[location]);
649        state.gen_all(
650            init_loc_map[location]
651                .iter()
652                .filter(|init_index| {
653                    move_data.inits[**init_index].kind != InitKind::NonPanicPathOnly
654                })
655                .copied(),
656        );
657        terminator.edges()
658    }
659
660    fn apply_call_return_effect(
661        &self,
662        state: &mut Self::Domain,
663        block: mir::BasicBlock,
664        _return_places: CallReturnPlaces<'_, 'tcx>,
665    ) {
666        let move_data = self.move_data();
667        let init_loc_map = &move_data.init_loc_map;
668
669        let call_loc = self.body.terminator_loc(block);
670        for init_index in &init_loc_map[call_loc] {
671            state.gen_(*init_index);
672        }
673    }
674}