Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #136331

Merged
merged 24 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
395f0c9
Stabilize `const_black_box`
tgross35 Jan 12, 2025
fdef34b
Add URL and `crate_name` to test cases
notriddle Jan 29, 2025
eb457da
rustdoc: rename `issue-\d+.rs` tests to have meaningful names
notriddle Jan 29, 2025
aeabd4b
ci: use windows 2025 for i686-mingw
marcoieni Jan 29, 2025
022c0ce
Remove `NamedVarMap`.
nnethercote Jan 29, 2025
d781933
add constraint graph to polonius MIR dump
lqd Jan 28, 2025
23fb08b
LLVM changed the nocapture attribute to captures(none)
zmodem Jan 30, 2025
9788aa0
remove redundant test
lcnr Jan 20, 2025
12f86ee
move non_lifetime_binder tests
lcnr Jan 20, 2025
fef480f
error pattern to correct line
lcnr Jan 20, 2025
8c078fd
merge tests
lcnr Jan 20, 2025
fa6b95f
update comment
lcnr Jan 20, 2025
6e457b8
use Attribute::getWithCaptureInfo
zmodem Jan 30, 2025
6b699cc
float::min/max: mention the non-determinism around signed 0
RalfJung Jan 30, 2025
a1a55a2
Give 104145, 103463, and 31948 more descriptive names
notriddle Jan 30, 2025
c17d568
Direct link 108459 to issues -> pull redirect
notriddle Jan 30, 2025
b249760
Rollup merge of #135414 - tgross35:stabilize-const_black_box, r=dtolnay
jhpratt Jan 31, 2025
7f05c7e
Rollup merge of #136150 - marcoieni:windows-25-i686-mingw, r=Kobzol
jhpratt Jan 31, 2025
1a5ebc9
Rollup merge of #136258 - notriddle:notriddle/issue-d, r=fmease
jhpratt Jan 31, 2025
dcf1134
Rollup merge of #136270 - nnethercote:rm-NamedVarMap, r=jackh726
jhpratt Jan 31, 2025
8b409e4
Rollup merge of #136278 - lqd:polonius-debugger-episode-3, r=matthewj…
jhpratt Jan 31, 2025
b87df23
Rollup merge of #136287 - zmodem:nocapture, r=nikic
jhpratt Jan 31, 2025
55512db
Rollup merge of #136291 - lcnr:compare-mode, r=oli-obk
jhpratt Jan 31, 2025
08dc8c9
Rollup merge of #136296 - RalfJung:float-min-max, r=tgross35
jhpratt Jan 31, 2025
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
110 changes: 101 additions & 9 deletions compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use std::io;

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_index::IndexVec;
use rustc_middle::mir::pretty::{
PassWhere, PrettyPrintMirOptions, create_dump_file, dump_enabled, dump_mir_to_writer,
};
use rustc_middle::mir::{Body, ClosureRegionRequirements};
use rustc_middle::mir::{Body, ClosureRegionRequirements, Location};
use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::points::PointIndex;
use rustc_session::config::MirIncludeSpans;

use crate::borrow_set::BorrowSet;
use crate::constraints::OutlivesConstraint;
use crate::polonius::{LocalizedOutlivesConstraint, LocalizedOutlivesConstraintSet};
use crate::region_infer::values::LivenessValues;
use crate::type_check::Locations;
use crate::{BorrowckInferCtxt, RegionInferenceContext};

@@ -80,30 +82,43 @@ fn emit_polonius_dump<'tcx>(
body,
regioncx,
borrow_set,
localized_outlives_constraints,
&localized_outlives_constraints,
closure_region_requirements,
out,
)?;
writeln!(out, "</code></pre>")?;
writeln!(out, "</div>")?;

// Section 2: mermaid visualization of the CFG.
// Section 2: mermaid visualization of the polonius constraint graph.
writeln!(out, "<div>")?;
writeln!(out, "Polonius constraint graph")?;
writeln!(out, "<pre class='mermaid'>")?;
let edge_count = emit_mermaid_constraint_graph(
borrow_set,
regioncx.liveness_constraints(),
&localized_outlives_constraints,
out,
)?;
writeln!(out, "</pre>")?;
writeln!(out, "</div>")?;

// Section 3: mermaid visualization of the CFG.
writeln!(out, "<div>")?;
writeln!(out, "Control-flow graph")?;
writeln!(out, "<pre class='mermaid'>")?;
emit_mermaid_cfg(body, out)?;
writeln!(out, "</pre>")?;
writeln!(out, "</div>")?;

// Section 3: mermaid visualization of the NLL region graph.
// Section 4: mermaid visualization of the NLL region graph.
writeln!(out, "<div>")?;
writeln!(out, "NLL regions")?;
writeln!(out, "<pre class='mermaid'>")?;
emit_mermaid_nll_regions(regioncx, out)?;
writeln!(out, "</pre>")?;
writeln!(out, "</div>")?;

// Section 4: mermaid visualization of the NLL SCC graph.
// Section 5: mermaid visualization of the NLL SCC graph.
writeln!(out, "<div>")?;
writeln!(out, "NLL SCCs")?;
writeln!(out, "<pre class='mermaid'>")?;
@@ -117,7 +132,11 @@ fn emit_polonius_dump<'tcx>(
"<script src='https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js'></script>"
)?;
writeln!(out, "<script>")?;
writeln!(out, "mermaid.initialize({{ startOnLoad: false, maxEdges: 100 }});")?;
writeln!(
out,
"mermaid.initialize({{ startOnLoad: false, maxEdges: {} }});",
edge_count.max(100),
)?;
writeln!(out, "mermaid.run({{ querySelector: '.mermaid' }})")?;
writeln!(out, "</script>")?;
writeln!(out, "</body>")?;
@@ -132,7 +151,7 @@ fn emit_html_mir<'tcx>(
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
borrow_set: &BorrowSet<'tcx>,
localized_outlives_constraints: LocalizedOutlivesConstraintSet,
localized_outlives_constraints: &LocalizedOutlivesConstraintSet,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
out: &mut dyn io::Write,
) -> io::Result<()> {
@@ -160,7 +179,7 @@ fn emit_html_mir<'tcx>(
regioncx,
closure_region_requirements,
borrow_set,
&localized_outlives_constraints,
localized_outlives_constraints,
pass_where,
out,
)
@@ -392,3 +411,76 @@ fn emit_mermaid_nll_sccs<'tcx>(

Ok(())
}

/// Emits a mermaid flowchart of the polonius localized outlives constraints, with subgraphs per
/// region, and loan introductions.
fn emit_mermaid_constraint_graph<'tcx>(
borrow_set: &BorrowSet<'tcx>,
liveness: &LivenessValues,
localized_outlives_constraints: &LocalizedOutlivesConstraintSet,
out: &mut dyn io::Write,
) -> io::Result<usize> {
let location_name = |location: Location| {
// A MIR location looks like `bb5[2]`. As that is not a syntactically valid mermaid node id,
// transform it into `BB5_2`.
format!("BB{}_{}", location.block.index(), location.statement_index)
};
let region_name = |region: RegionVid| format!("'{}", region.index());
let node_name = |region: RegionVid, point: PointIndex| {
let location = liveness.location_from_point(point);
format!("{}_{}", region_name(region), location_name(location))
};

// The mermaid chart type: a top-down flowchart, which supports subgraphs.
writeln!(out, "flowchart TD")?;

// The loans subgraph: a node per loan.
writeln!(out, " subgraph \"Loans\"")?;
for loan_idx in 0..borrow_set.len() {
writeln!(out, " L{loan_idx}")?;
}
writeln!(out, " end\n")?;

// And an edge from that loan node to where it enters the constraint graph.
for (loan_idx, loan) in borrow_set.iter_enumerated() {
writeln!(
out,
" L{} --> {}_{}",
loan_idx.index(),
region_name(loan.region),
location_name(loan.reserve_location),
)?;
}
writeln!(out, "")?;

// The regions subgraphs containing the region/point nodes.
let mut points_per_region: FxIndexMap<RegionVid, FxIndexSet<PointIndex>> =
FxIndexMap::default();
for constraint in &localized_outlives_constraints.outlives {
points_per_region.entry(constraint.source).or_default().insert(constraint.from);
points_per_region.entry(constraint.target).or_default().insert(constraint.to);
}
for (region, points) in points_per_region {
writeln!(out, " subgraph \"{}\"", region_name(region))?;
for point in points {
writeln!(out, " {}", node_name(region, point))?;
}
writeln!(out, " end\n")?;
}

// The constraint graph edges.
for constraint in &localized_outlives_constraints.outlives {
// FIXME: add killed loans and constraint kind as edge labels.
writeln!(
out,
" {} --> {}",
node_name(constraint.source, constraint.from),
node_name(constraint.target, constraint.to),
)?;
}

// Return the number of edges: this is the biggest graph in the dump and its edge count will be
// mermaid's max edge count to support.
let edge_count = borrow_set.len() + localized_outlives_constraints.outlives.len();
Ok(edge_count)
}
2 changes: 0 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/int.rs
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
// Run-time:
// status: 0

#![feature(const_black_box)]

/*
* Code
*/
Loading