1use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2use rustc_index::bit_set::DenseBitSet;
3use rustc_index::interval::IntervalSet;
4use rustc_infer::infer::canonical::QueryRegionConstraints;
5use rustc_infer::traits::TraitErrors;
6use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, HasLocalDecls, Local, Location};
7use rustc_middle::traits::query::DropckOutlivesResult;
8use rustc_middle::ty::relate::Relate;
9use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
10use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
11use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
12use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
13use rustc_mir_dataflow::{Analysis, ResultsCursor};
14use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
15use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
16use rustc_trait_selection::traits::ObligationCtxt;
17use rustc_trait_selection::traits::outlives_for_liveness::FreeRegionsVisitor;
18use rustc_trait_selection::traits::query::dropck_outlives;
19use rustc_trait_selection::traits::query::type_op::{DropckOutlives, TypeOpOutput};
20use tracing::debug;
2122use crate::polonius;
23use crate::region_infer::values;
24use crate::type_check::liveness::local_use_map::LocalUseMap;
25use crate::type_check::{NormalizeLocation, TypeChecker};
2627/// This is the heart of the liveness computation. For each variable X
28/// that requires a liveness computation, it walks over all the uses
29/// of X and does a reverse depth-first search ("trace") through the
30/// MIR. This search stops when we find a definition of that variable.
31/// The points visited in this search is the USE-LIVE set for the variable;
32/// of those points is added to all the regions that appear in the variable's
33/// type.
34///
35/// We then also walks through each *drop* of those variables and does
36/// another search, stopping when we reach a use or definition. This
37/// is the DROP-LIVE set of points. Each of the points in the
38/// DROP-LIVE set are to the liveness sets for regions found in the
39/// `dropck_outlives` result of the variable's type (in particular,
40/// this respects `#[may_dangle]` annotations).
41pub(super) fn trace<'tcx>(
42 typeck: &mut TypeChecker<'_, 'tcx>,
43 location_map: &DenseLocationMap,
44 move_data: &MoveData<'tcx>,
45 relevant_live_locals: Vec<Local>,
46 boring_locals: Vec<Local>,
47) {
48let _timer = typeck.tcx().prof.generic_activity("borrowck_liveness_trace");
4950let local_use_map = &LocalUseMap::build(&relevant_live_locals, location_map, typeck.body);
51let cx = LivenessContext {
52typeck,
53 flow_inits: None,
54location_map,
55local_use_map,
56move_data,
57 drop_data: FxIndexMap::default(),
58 };
5960let mut results = LivenessResults::new(cx);
6162results.add_extra_drop_facts(&relevant_live_locals);
6364results.compute_for_all_locals(relevant_live_locals);
6566results.dropck_boring_locals(boring_locals);
67}
6869/// Contextual state for the type-liveness coroutine.
70struct LivenessContext<'a, 'typeck, 'tcx> {
71/// Current type-checker, giving us our inference context etc.
72 ///
73 /// This also stores the body we're currently analyzing.
74typeck: &'a mut TypeChecker<'typeck, 'tcx>,
7576/// Defines the `PointIndex` mapping
77location_map: &'a DenseLocationMap,
7879/// Mapping to/from the various indices used for initialization tracking.
80move_data: &'a MoveData<'tcx>,
8182/// Cache for the results of `dropck_outlives` query.
83drop_data: FxIndexMap<Ty<'tcx>, DropData<'tcx>>,
8485/// Results of dataflow tracking which variables (and paths) have been
86 /// initialized. Computed lazily when needed by drop-liveness.
87flow_inits: Option<ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>>,
8889/// Index indicating where each variable is assigned, used, or
90 /// dropped.
91local_use_map: &'a LocalUseMap,
92}
9394struct DropData<'tcx> {
95 dropck_result: DropckOutlivesResult<'tcx>,
96 region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
97}
9899struct LivenessResults<'a, 'typeck, 'tcx> {
100 cx: LivenessContext<'a, 'typeck, 'tcx>,
101102/// Set of points that define the current local.
103defs: DenseBitSet<PointIndex>,
104105/// Points where the current variable is "use live" -- meaning
106 /// that there is a future "full use" that may use its value.
107use_live_at: IntervalSet<PointIndex>,
108109/// Points where the current variable is "drop live" -- meaning
110 /// that there is no future "full use" that may use its value, but
111 /// there is a future drop.
112drop_live_at: IntervalSet<PointIndex>,
113114/// Locations where drops may occur.
115drop_locations: Vec<Location>,
116117/// Stack used when doing (reverse) DFS.
118stack: Vec<PointIndex>,
119}
120121impl<'a, 'typeck, 'tcx> LivenessResults<'a, 'typeck, 'tcx> {
122fn new(cx: LivenessContext<'a, 'typeck, 'tcx>) -> Self {
123let num_points = cx.location_map.num_points();
124LivenessResults {
125cx,
126 defs: DenseBitSet::new_empty(num_points),
127 use_live_at: IntervalSet::new(num_points),
128 drop_live_at: IntervalSet::new(num_points),
129 drop_locations: ::alloc::vec::Vec::new()vec![],
130 stack: ::alloc::vec::Vec::new()vec![],
131 }
132 }
133134fn compute_for_all_locals(&mut self, relevant_live_locals: Vec<Local>) {
135for local in relevant_live_locals {
136self.reset_local_state();
137self.add_defs_for(local);
138self.compute_use_live_points_for(local);
139self.compute_drop_live_points_for(local);
140141let local_ty = self.cx.body().local_decls[local].ty;
142143if !self.use_live_at.is_empty() {
144self.cx.add_use_live_facts_for(local_ty, &self.use_live_at);
145 }
146147if !self.drop_live_at.is_empty() {
148self.cx.add_drop_live_facts_for(
149 local,
150 local_ty,
151&self.drop_locations,
152&self.drop_live_at,
153 );
154 }
155 }
156 }
157158/// Runs dropck for locals whose liveness isn't relevant. This is
159 /// necessary to eagerly detect unbound recursion during drop glue computation.
160 ///
161 /// These are all the locals which do not potentially reference a region local
162 /// to this body. Locals which only reference free regions are always drop-live
163 /// and can therefore safely be dropped.
164fn dropck_boring_locals(&mut self, boring_locals: Vec<Local>) {
165for local in boring_locals {
166let local_ty = self.cx.body().local_decls[local].ty;
167let local_span = self.cx.body().local_decls[local].source_info.span;
168let drop_data = self.cx.drop_data.entry(local_ty).or_insert_with({
169let typeck = &self.cx.typeck;
170move || LivenessContext::compute_drop_data(typeck, local_ty, local_span)
171 });
172173 drop_data.dropck_result.report_overflows(
174self.cx.typeck.infcx.tcx,
175self.cx.typeck.body.local_decls[local].source_info.span,
176 local_ty,
177 );
178 }
179 }
180181/// Add extra drop facts needed for Polonius.
182 ///
183 /// Add facts for all locals with free regions, since regions may outlive
184 /// the function body only at certain nodes in the CFG.
185fn add_extra_drop_facts(&mut self, relevant_live_locals: &[Local]) {
186// This collect is more necessary than immediately apparent
187 // because these facts go into `add_drop_live_facts_for()`,
188 // which also writes to `polonius_facts`, and so this is genuinely
189 // a simultaneous overlapping mutable borrow.
190 // FIXME for future hackers: investigate whether this is
191 // actually necessary; these facts come from Polonius
192 // and probably maybe plausibly does not need to go back in.
193 // It may be necessary to just pick out the parts of
194 // `add_drop_live_facts_for()` that make sense.
195let Some(facts) = self.cx.typeck.polonius_facts.as_ref() else { return };
196let facts_to_add: Vec<_> = {
197let relevant_live_locals: FxIndexSet<_> =
198relevant_live_locals.iter().copied().collect();
199200facts201 .var_dropped_at
202 .iter()
203 .filter_map(|&(local, location_index)| {
204let local_ty = self.cx.body().local_decls[local].ty;
205if relevant_live_locals.contains(&local) || !local_ty.has_free_regions() {
206return None;
207 }
208209let location = self.cx.typeck.location_table.to_location(location_index);
210Some((local, local_ty, location))
211 })
212 .collect()
213 };
214215let live_at = IntervalSet::new(self.cx.location_map.num_points());
216for (local, local_ty, location) in facts_to_add {
217self.cx.add_drop_live_facts_for(local, local_ty, &[location], &live_at);
218 }
219 }
220221/// Clear the value of fields that are "per local variable".
222fn reset_local_state(&mut self) {
223self.defs.clear();
224self.use_live_at.clear();
225self.drop_live_at.clear();
226self.drop_locations.clear();
227if !self.stack.is_empty() {
::core::panicking::panic("assertion failed: self.stack.is_empty()")
};assert!(self.stack.is_empty());
228 }
229230/// Adds the definitions of `local` into `self.defs`.
231fn add_defs_for(&mut self, local: Local) {
232for def in self.cx.local_use_map.defs(local) {
233{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:233",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(233u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("- defined at {0:?}",
def) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("- defined at {:?}", def);
234self.defs.insert(def);
235 }
236 }
237238/// Computes all points where local is "use live" -- meaning its
239 /// current value may be used later (except by a drop). This is
240 /// done by walking backwards from each use of `local` until we
241 /// find a `def` of local.
242 ///
243 /// Requires `add_defs_for(local)` to have been executed.
244fn compute_use_live_points_for(&mut self, local: Local) {
245{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:245",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(245u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_use_live_points_for(local={0:?})",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_use_live_points_for(local={:?})", local);
246247self.stack.extend(self.cx.local_use_map.uses(local));
248while let Some(p) = self.stack.pop() {
249// We are live in this block from the closest to us of:
250 //
251 // * Inclusively, the block start
252 // * Exclusively, the previous definition (if it's in this block)
253 // * Exclusively, the previous live_at setting (an optimization)
254let block_start = self.cx.location_map.to_block_start(p);
255let previous_defs = self.defs.last_set_in(block_start..=p);
256let previous_live_at = self.use_live_at.last_set_in(block_start..=p);
257258let exclusive_start = match (previous_defs, previous_live_at) {
259 (Some(a), Some(b)) => Some(std::cmp::max(a, b)),
260 (Some(a), None) | (None, Some(a)) => Some(a),
261 (None, None) => None,
262 };
263264if let Some(exclusive) = exclusive_start {
265self.use_live_at.insert_range(exclusive + 1..=p);
266267// If we have a bound after the start of the block, we should
268 // not add the predecessors for this block.
269continue;
270 } else {
271// Add all the elements of this block.
272self.use_live_at.insert_range(block_start..=p);
273274// Then add the predecessors for this block, which are the
275 // terminators of predecessor basic blocks. Push those onto the
276 // stack so that the next iteration(s) will process them.
277278let block = self.cx.location_map.to_location(block_start).block;
279self.stack.extend(
280self.cx.body().basic_blocks.predecessors()[block]
281 .iter()
282 .map(|&pred_bb| self.cx.body().terminator_loc(pred_bb))
283 .map(|pred_loc| self.cx.location_map.point_from_location(pred_loc)),
284 );
285 }
286 }
287 }
288289/// Computes all points where local is "drop live" -- meaning its
290 /// current value may be dropped later (but not used). This is
291 /// done by iterating over the drops of `local` where `local` (or
292 /// some subpart of `local`) is initialized. For each such drop,
293 /// we walk backwards until we find a point where `local` is
294 /// either defined or use-live.
295 ///
296 /// Requires `compute_use_live_points_for` and `add_defs_for` to
297 /// have been executed.
298fn compute_drop_live_points_for(&mut self, local: Local) {
299{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:299",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(299u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for(local={0:?})",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for(local={:?})", local);
300301let Some(mpi) = self.cx.move_data.rev_lookup.find_local(local) else { return };
302{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:302",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(302u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for: mpi = {0:?}",
mpi) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for: mpi = {:?}", mpi);
303304// Find the drops where `local` is initialized.
305for drop_point in self.cx.local_use_map.drops(local) {
306let location = self.cx.location_map.to_location(drop_point);
307if true {
{
match (&self.cx.body().terminator_loc(location.block), &location) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(self.cx.body().terminator_loc(location.block), location,);
308309if self.cx.initialized_at_terminator(location.block, mpi)
310 && self.drop_live_at.insert(drop_point)
311 {
312self.drop_locations.push(location);
313self.stack.push(drop_point);
314 }
315 }
316317{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:317",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(317u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for: drop_locations={0:?}",
self.drop_locations) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for: drop_locations={:?}", self.drop_locations);
318319// Reverse DFS. But for drops, we do it a bit differently.
320 // The stack only ever stores *terminators of blocks*. Within
321 // a block, we walk back the statements in an inner loop.
322while let Some(term_point) = self.stack.pop() {
323self.compute_drop_live_points_for_block(mpi, term_point);
324 }
325 }
326327/// Executes one iteration of the drop-live analysis loop.
328 ///
329 /// The parameter `mpi` is the `MovePathIndex` of the local variable
330 /// we are currently analyzing.
331 ///
332 /// The point `term_point` represents some terminator in the MIR,
333 /// where the local `mpi` is drop-live on entry to that terminator.
334 ///
335 /// This method adds all drop-live points within the block and --
336 /// where applicable -- pushes the terminators of preceding blocks
337 /// onto `self.stack`.
338fn compute_drop_live_points_for_block(&mut self, mpi: MovePathIndex, term_point: PointIndex) {
339{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:339",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(339u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block(mpi={0:?}, term_point={1:?})",
self.cx.move_data.move_paths[mpi].place,
self.cx.location_map.to_location(term_point)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
340"compute_drop_live_points_for_block(mpi={:?}, term_point={:?})",
341self.cx.move_data.move_paths[mpi].place,
342self.cx.location_map.to_location(term_point),
343 );
344345// We are only invoked with terminators where `mpi` is
346 // drop-live on entry.
347if true {
if !self.drop_live_at.contains(term_point) {
::core::panicking::panic("assertion failed: self.drop_live_at.contains(term_point)")
};
};debug_assert!(self.drop_live_at.contains(term_point));
348349// Otherwise, scan backwards through the statements in the
350 // block. One of them may be either a definition or use
351 // live point.
352let term_location = self.cx.location_map.to_location(term_point);
353if true {
{
match (&self.cx.body().terminator_loc(term_location.block),
&term_location) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(self.cx.body().terminator_loc(term_location.block), term_location,);
354let block = term_location.block;
355let entry_point = self.cx.location_map.entry_point(term_location.block);
356for p in (entry_point..term_point).rev() {
357{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:357",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(357u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: p = {0:?}",
self.cx.location_map.to_location(p)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
358"compute_drop_live_points_for_block: p = {:?}",
359self.cx.location_map.to_location(p)
360 );
361362if self.defs.contains(p) {
363{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:363",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(363u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: def site")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: def site");
364return;
365 }
366367if self.use_live_at.contains(p) {
368{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:368",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(368u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: use-live at {0:?}",
p) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: use-live at {:?}", p);
369return;
370 }
371372if !self.drop_live_at.insert(p) {
373{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:373",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(373u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: already drop-live")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: already drop-live");
374return;
375 }
376 }
377378let body = self.cx.typeck.body;
379for &pred_block in body.basic_blocks.predecessors()[block].iter() {
380{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:380",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(380u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: pred_block = {0:?}",
pred_block) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,);
381382// Check whether the variable is (at least partially)
383 // initialized at the exit of this predecessor. If so, we
384 // want to enqueue it on our list. If not, go check the
385 // next block.
386 //
387 // Note that we only need to check whether `live_local`
388 // became de-initialized at basic block boundaries. If it
389 // were to become de-initialized within the block, that
390 // would have been a "use-live" transition in the earlier
391 // loop, and we'd have returned already.
392 //
393 // NB. It's possible that the pred-block ends in a call
394 // which stores to the variable; in that case, the
395 // variable may be uninitialized "at exit" because this
396 // call only considers the *unconditional effects* of the
397 // terminator. *But*, in that case, the terminator is also
398 // a *definition* of the variable, in which case we want
399 // to stop the search anyhow. (But see Note 1 below.)
400if !self.cx.initialized_at_exit(pred_block, mpi) {
401{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:401",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(401u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: not initialized")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: not initialized");
402continue;
403 }
404405let pred_term_loc = self.cx.body().terminator_loc(pred_block);
406let pred_term_point = self.cx.location_map.point_from_location(pred_term_loc);
407408// If the terminator of this predecessor either *assigns*
409 // our value or is a "normal use", then stop.
410if self.defs.contains(pred_term_point) {
411{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:411",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(411u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: defined at {0:?}",
pred_term_loc) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: defined at {:?}", pred_term_loc);
412continue;
413 }
414415if self.use_live_at.contains(pred_term_point) {
416{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:416",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(416u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: use-live at {0:?}",
pred_term_loc) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: use-live at {:?}", pred_term_loc);
417continue;
418 }
419420// Otherwise, we are drop-live on entry to the terminator,
421 // so walk it.
422if self.drop_live_at.insert(pred_term_point) {
423{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:423",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(423u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_live_points_for_block: pushed to stack")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_live_points_for_block: pushed to stack");
424self.stack.push(pred_term_point);
425 }
426 }
427428// Note 1. There is a weird scenario that you might imagine
429 // being problematic here, but which actually cannot happen.
430 // The problem would be if we had a variable that *is* initialized
431 // (but dead) on entry to the terminator, and where the current value
432 // will be dropped in the case of unwind. In that case, we ought to
433 // consider `X` to be drop-live in between the last use and call.
434 // Here is the example:
435 //
436 // ```
437 // BB0 {
438 // X = ...
439 // use(X); // last use
440 // ... // <-- X ought to be drop-live here
441 // X = call() goto BB1 unwind BB2
442 // }
443 //
444 // BB1 {
445 // DROP(X)
446 // }
447 //
448 // BB2 {
449 // DROP(X)
450 // }
451 // ```
452 //
453 // However, the current code would, when walking back from BB2,
454 // simply stop and never explore BB0. This seems bad! But it turns
455 // out this code is flawed anyway -- note that the existing value of
456 // `X` would leak in the case where unwinding did *not* occur.
457 //
458 // What we *actually* generate is a store to a temporary
459 // for the call (`TMP = call()...`) and then a
460 // `Drop(X)` followed by `X = TMP` to swap that with `X`.
461}
462}
463464impl<'a, 'typeck, 'tcx> LivenessContext<'a, 'typeck, 'tcx> {
465/// Computes the `MaybeInitializedPlaces` dataflow analysis if it hasn't been done already.
466 ///
467 /// In practice, the results of this dataflow analysis are rarely needed but can be expensive to
468 /// compute on big functions, so we compute them lazily as a fast path when:
469 /// - there are relevant live locals
470 /// - there are drop points for these relevant live locals.
471 ///
472 /// This happens as part of the drop-liveness computation: it's the only place checking for
473 /// maybe-initializedness of `MovePathIndex`es.
474fn flow_inits(&mut self) -> &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>> {
475self.flow_inits.get_or_insert_with(|| {
476let tcx = self.typeck.tcx();
477let body = self.typeck.body;
478// FIXME: reduce the `MaybeInitializedPlaces` domain to the useful `MovePath`s.
479 //
480 // This dataflow analysis computes maybe-initializedness of all move paths, which
481 // explains why it can be expensive on big functions. But this data is only used in
482 // drop-liveness. Therefore, most of the move paths computed here are ultimately unused,
483 // even if the results are computed lazily and "no relevant live locals with drop
484 // points" is the common case.
485 //
486 // So we only need the ones for 1) relevant live locals 2) that have drop points. That's
487 // a much, much smaller domain: in our benchmarks, when it's not zero (the most likely
488 // case), there are a few dozens compared to e.g. thousands or tens of thousands of
489 // locals and move paths.
490let _timer = tcx.prof.generic_activity("borrowck_dataflow_maybe_inits");
491let flow_inits = MaybeInitializedPlaces::new(tcx, body, self.move_data)
492 .iterate_to_fixpoint(tcx, body, Some("borrowck"))
493 .into_results_cursor(body);
494flow_inits495 })
496 }
497}
498499impl<'tcx> LivenessContext<'_, '_, 'tcx> {
500fn body(&self) -> &Body<'tcx> {
501self.typeck.body
502 }
503504/// Returns `true` if the local variable (or some part of it) is initialized at the current
505 /// cursor position. Callers should call one of the `seek` methods immediately before to point
506 /// the cursor to the desired location.
507fn initialized_at_curr_loc(&mut self, mpi: MovePathIndex) -> bool {
508let flow_inits = self.flow_inits();
509let state = flow_inits.get();
510if state.contains(mpi) {
511return true;
512 }
513514let move_paths = &flow_inits.analysis().move_data().move_paths;
515move_paths[mpi].find_descendant(move_paths, |mpi| state.contains(mpi)).is_some()
516 }
517518/// Returns `true` if the local variable (or some part of it) is initialized in
519 /// the terminator of `block`. We need to check this to determine if a
520 /// DROP of some local variable will have an effect -- note that
521 /// drops, as they may unwind, are always terminators.
522fn initialized_at_terminator(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool {
523let terminator_location = self.body().terminator_loc(block);
524self.flow_inits().seek_before_primary_effect(terminator_location);
525self.initialized_at_curr_loc(mpi)
526 }
527528/// Returns `true` if the path `mpi` (or some part of it) is initialized at
529 /// the exit of `block`.
530 ///
531 /// **Warning:** Does not account for the result of `Call`
532 /// instructions.
533fn initialized_at_exit(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool {
534let terminator_location = self.body().terminator_loc(block);
535self.flow_inits().seek_after_primary_effect(terminator_location);
536self.initialized_at_curr_loc(mpi)
537 }
538539/// Stores the result that all regions in `value` are live for the
540 /// points `live_at`.
541fn add_use_live_facts_for(&mut self, value: Ty<'tcx>, live_at: &IntervalSet<PointIndex>) {
542{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:542",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(542u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("add_use_live_facts_for(value={0:?})",
value) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("add_use_live_facts_for(value={:?})", value);
543Self::make_all_regions_live(self.location_map, self.typeck, value, live_at);
544 }
545546/// Some variable with type `live_ty` is "drop live" at `location`
547 /// -- i.e., it may be dropped later. This means that *some* of
548 /// the regions in its type must be live at `location`. The
549 /// precise set will depend on the dropck constraints, and in
550 /// particular this takes `#[may_dangle]` into account.
551fn add_drop_live_facts_for(
552&mut self,
553 dropped_local: Local,
554 dropped_ty: Ty<'tcx>,
555 drop_locations: &[Location],
556 live_at: &IntervalSet<PointIndex>,
557 ) {
558{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:558",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(558u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("add_drop_live_constraint(dropped_local={0:?}, dropped_ty={1:?}, drop_locations={2:?}, live_at={3:?})",
dropped_local, dropped_ty, drop_locations,
values::pretty_print_points(self.location_map,
live_at.iter())) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
559"add_drop_live_constraint(\
560 dropped_local={:?}, \
561 dropped_ty={:?}, \
562 drop_locations={:?}, \
563 live_at={:?})",
564 dropped_local,
565 dropped_ty,
566 drop_locations,
567 values::pretty_print_points(self.location_map, live_at.iter()),
568 );
569570let local_span = self.body().local_decls()[dropped_local].source_info.span;
571let drop_data = self.drop_data.entry(dropped_ty).or_insert_with({
572let typeck = &self.typeck;
573move || Self::compute_drop_data(typeck, dropped_ty, local_span)
574 });
575576if let Some(data) = &drop_data.region_constraint_data {
577for &drop_location in drop_locations {
578self.typeck.push_region_constraints(
579 drop_location.to_locations(),
580 ConstraintCategory::Boring,
581 data,
582 );
583 }
584 }
585586drop_data.dropck_result.report_overflows(
587self.typeck.infcx.tcx,
588self.typeck.body.source_info(*drop_locations.first().unwrap()).span,
589dropped_ty,
590 );
591592// All things in the `outlives` array may be touched by
593 // the destructor and must be live at this point.
594for &kind in &drop_data.dropck_result.kinds {
595Self::make_all_regions_live(self.location_map, self.typeck, kind, live_at);
596 polonius::legacy::emit_drop_facts(
597self.typeck.tcx(),
598 dropped_local,
599&kind,
600self.typeck.universal_regions,
601self.typeck.polonius_facts,
602 );
603 }
604 }
605606fn make_all_regions_live(
607 location_map: &DenseLocationMap,
608 typeck: &mut TypeChecker<'_, 'tcx>,
609 value: impl TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,
610 live_at: &IntervalSet<PointIndex>,
611 ) {
612{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:612",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(612u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("make_all_regions_live(value={0:?})",
value) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("make_all_regions_live(value={:?})", value);
613{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:613",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(613u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("make_all_regions_live: live_at={0}",
values::pretty_print_points(location_map, live_at.iter()))
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
614"make_all_regions_live: live_at={}",
615 values::pretty_print_points(location_map, live_at.iter()),
616 );
617618value.visit_with(&mut FreeRegionsVisitor {
619 tcx: typeck.tcx(),
620 param_env: typeck.infcx.param_env,
621 op: |r| {
622let live_region_vid = typeck.universal_regions.to_region_vid(r);
623624typeck.constraints.liveness_constraints.add_points(live_region_vid, live_at);
625 },
626 });
627628// When using `-Zpolonius=next`, we record the variance of each live region.
629if let Some(polonius_context) = typeck.polonius_context.as_mut() {
630polonius_context.record_live_region_variance(
631typeck.infcx.tcx,
632typeck.universal_regions,
633value,
634 );
635 }
636 }
637638fn compute_drop_data(
639 typeck: &TypeChecker<'_, 'tcx>,
640 dropped_ty: Ty<'tcx>,
641 span: Span,
642 ) -> DropData<'tcx> {
643{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/liveness/trace.rs:643",
"rustc_borrowck::type_check::liveness::trace",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/liveness/trace.rs"),
::tracing_core::__macro_support::Option::Some(643u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::liveness::trace"),
::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!("compute_drop_data(dropped_ty={0:?})",
dropped_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("compute_drop_data(dropped_ty={:?})", dropped_ty);
644645let goal = DropckOutlives { dropped_ty };
646647match typeck.infcx.fully_perform(goal, DUMMY_SP) {
648Ok(TypeOpOutput { output, constraints, .. }) => {
649DropData { dropck_result: output, region_constraint_data: constraints }
650 }
651Err(ErrorGuaranteed { .. }) => {
652// We don't run dropck on HIR, and dropck looks inside fields of
653 // types, so there's no guarantee that it succeeds. We also
654 // can't rely on the `ErrorGuaranteed` from `fully_perform` here
655 // because it comes from delay_span_bug.
656 //
657 // Do this inside of a probe because we don't particularly care (or want)
658 // any region side-effects of this operation in our infcx.
659typeck.infcx.probe(|_| {
660let ocx = ObligationCtxt::new_with_diagnostics(&typeck.infcx);
661let errors = match dropck_outlives::compute_dropck_outlives_with_errors(
662&ocx,
663typeck.infcx.param_env.and(goal),
664span,
665 ) {
666Ok(_) => ocx.evaluate_obligations_error_on_ambiguity(),
667Err(e) => TraitErrors::HasErrors(e),
668 };
669670// Could have no errors if a type lowering error, say, caused the query
671 // to fail.
672if let TraitErrors::HasErrors(errors) = errors {
673typeck.infcx.err_ctxt().report_fulfillment_errors(errors);
674 }
675 });
676DropData { dropck_result: Default::default(), region_constraint_data: None }
677 }
678 }
679 }
680}