Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,15 @@ fn emit_loan_reachability(
// It's useful to know whether the region we're reaching is live at this point.
let node_liveness =
if liveness.is_live_at(node.region, location) { "live" } else { "not live" };
writeln!(out, "<span class='trace-suffix'>")?;
writeln!(
out,
"/ at <code>{:?}</code>: <code>'{}</code> is {}",
location,
node.region.index(),
node_liveness,
)?;
writeln!(out, "</span>")?;
writeln!(out, "</li>")?;
}
writeln!(out, "</ul>")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<head>
<title>Polonius MIR dump</title>
<style>
.hidden {
display: none;
pre {
margin-top: 0;
white-space: pre-wrap;
}

.section + .section {
Expand All @@ -13,8 +14,8 @@
padding-top: 10px;
}

.traces .section-header {
margin-bottom: 10px;
.section-header {
margin-bottom: 6px;
}

.trace + .trace {
Expand All @@ -25,43 +26,63 @@
margin: 5px 0px;
padding-left: 15px;
}

.trace-suffix {
opacity: 0.8;
margin-left: 10px;
}

.hidden {
display: none;
}
</style>
</head>

<body>

<!-- The NLL + Polonius MIR -->
<!-- Links to the other sections -->
<div class="section">
<div class="section-header">Quick links</div>
<a href="#mir">Polonius MIR</a>
<a href="#polonius-region-graph">Polonius constraint graph</a>
<a href="#loan-traces">Loan traces</a>
<a href="#cfg-graph">Control-flow graph</a>
<a href="#nll-region-graph">NLL region graph</a>
<a href="#nll-scc-graph">NLL SCC graph</a>
</div>

<!-- The NLL + Polonius MIR -->
<div class="section" id="mir">
<div class="section-header">Raw MIR dump</div>
<pre><code>$SECTION_MIR</code></pre>
</div>

<!-- Mermaid visualization of the polonius constraint graph -->
<div class="section">
<div class="section" id="polonius-region-graph">
<div class="section-header">Polonius constraint graph</div>
<pre class='mermaid'>$SECTION_POLONIUS_CONSTRAINTS</pre>
</div>

<!-- The reachability of loans while traversing the polonius constraint graph -->
<div class="section traces">
<div class="section traces" id="loan-traces">
<div class="section-header">Loan Traces</div>
$SECTION_POLONIUS_REACHABILITY
</div>

<!-- Mermaid visualization of the CFG -->
<div class="section">
<div class="section" id="cfg-graph">
<div class="section-header">Control-flow graph</div>
<pre class='mermaid'>$SECTION_CFG</pre>
</div>

<!-- Mermaid visualization of the NLL region graph -->
<div class="section">
<div class="section" id="nll-region-graph">
<div class="section-header">NLL regions</div>
<pre class='mermaid'>$SECTION_NLL_CONSTRAINTS</pre>
</div>

<!-- Mermaid visualization of the NLL SCC graph -->
<div class="section">
<div class="section" id="nll-scc-graph">
<div class="section-header">NLL SCCs</div>
<pre class='mermaid'>$SECTION_NLL_SCCS</pre>
</div>
Expand Down
38 changes: 20 additions & 18 deletions compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::traits::TraitErrors;
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
use rustc_middle::traits::query::DropckOutlivesResult;
use rustc_middle::ty::{GenericArg, Ty, TypeVisitable, TypeVisitableExt};
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
Expand Down Expand Up @@ -553,8 +553,17 @@ impl<'tcx> LivenessContext<'_, '_, 'tcx> {
/// points `live_at`.
fn add_use_live_facts_for(&mut self, value: Ty<'tcx>, live_at: &IntervalSet<PointIndex>) {
debug!("add_use_live_facts_for(value={:?})", value);
Self::record_region_variance(self.typeck, value.into());
Self::make_all_regions_live(self.location_map, self.typeck, value.into(), live_at);
Self::make_all_regions_live(self.location_map, self.typeck, value, live_at);

// When using `-Zpolonius=next`, we also record the variance of regions in this live type.
if let Some(polonius_context) = self.typeck.polonius_context.as_mut() {
record_live_region_variance(
self.typeck.infcx.tcx,
&mut polonius_context.live_region_variances,
self.typeck.universal_regions,
value,
);
}
}

/// Some variable with type `live_ty` is "drop live" at `location`
Expand Down Expand Up @@ -595,9 +604,6 @@ impl<'tcx> LivenessContext<'_, '_, 'tcx> {
}
}

// Since the entire dropped local is live, record the variance of its regions.
Self::record_region_variance(self.typeck, dropped_ty.into());

// All things in the `outlives` array may be touched by
// the destructor and must be live at this point.
for &kind in &drop_data.dropck_result.kinds {
Expand All @@ -610,27 +616,24 @@ impl<'tcx> LivenessContext<'_, '_, 'tcx> {
self.typeck.polonius_facts,
);
}
}

/// `live_kind` is the type of a (use- or drop-) live local.
/// Record the variance of any region(s) appearing in it for Polonius. Does
/// nothing if Polonius is not active.
fn record_region_variance(typeck: &mut TypeChecker<'_, 'tcx>, live_kind: GenericArg<'tcx>) {
// When using `-Zpolonius=next`, we record the variance of each live region.
if let Some(polonius_context) = typeck.polonius_context.as_mut() {
// For polonius: since the local is drop live, record the variance of the regions in its
// type, not the ones in the type's live components seen in the dropck results above. See
// issue #160670.
if let Some(polonius_context) = self.typeck.polonius_context.as_mut() {
record_live_region_variance(
typeck.infcx.tcx,
self.typeck.infcx.tcx,
&mut polonius_context.live_region_variances,
typeck.universal_regions,
live_kind,
self.typeck.universal_regions,
dropped_ty,
);
}
}

fn make_all_regions_live(
location_map: &DenseLocationMap,
typeck: &mut TypeChecker<'_, 'tcx>,
value: GenericArg<'tcx>,
value: impl TypeVisitable<TyCtxt<'tcx>>,
live_at: &IntervalSet<PointIndex>,
) {
debug!("make_all_regions_live(value={:?})", value);
Expand All @@ -647,7 +650,6 @@ impl<'tcx> LivenessContext<'_, '_, 'tcx> {
typeck.constraints.liveness_constraints.add_points(live_region_vid, live_at);
},
});
Self::record_region_variance(typeck, value);
}
}

Expand Down
Loading