disable NLL liveness optimization when using polonius

in NLLs some locals are marked live at all points if one of their
regions escapes the function but that doesn't work in a flow-sensitive
setting like polonius
This commit is contained in:
Rémy Rakic 2024-12-30 20:35:25 +00:00
parent 12445e0b2c
commit 5055864071

View file

@ -38,11 +38,19 @@ pub(super) fn generate<'a, 'tcx>(
) {
debug!("liveness::generate");
let free_regions = regions_that_outlive_free_regions(
typeck.infcx.num_region_vars(),
&typeck.universal_regions,
&typeck.constraints.outlives_constraints,
);
// NLLs can avoid computing some liveness data here because its constraints are
// location-insensitive, but that doesn't work in polonius: locals whose type contains a region
// that outlives a free region are not necessarily live everywhere in a flow-sensitive setting,
// unlike NLLs.
let free_regions = if !typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() {
regions_that_outlive_free_regions(
typeck.infcx.num_region_vars(),
&typeck.universal_regions,
&typeck.constraints.outlives_constraints,
)
} else {
typeck.universal_regions.universal_regions_iter().collect()
};
let (relevant_live_locals, boring_locals) =
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);