Skip to content
Merged
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
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,23 @@ pub fn run_pcg<'a, 'tcx>(pcg_ctxt: &'a PcgCtxt<'_, 'tcx>) -> PcgOutput<'a, 'tcx>
if let Some(dir_path) = pcg_ctxt.visualization_output_path() {
generate_json_from_mir(&dir_path.join("mir.json"), pcg_ctxt.compiler_ctxt)
.expect("Failed to generate JSON from MIR");
{
use std::fmt::Write;
let loop_analysis = analysis_results.analysis().loop_analysis();
let mut loop_text = String::new();
for bb in body.basic_blocks.indices() {
let depth = loop_analysis.loop_depth(bb);
let loops: Vec<_> = loop_analysis.loops(bb).collect();
let loop_head = loop_analysis.loop_head_of(bb);
writeln!(
&mut loop_text,
"{bb:?} depth: {depth}, loops: {loops:?}, loop head?: {loop_head:?}"
)
.unwrap();
}
std::fs::write(dir_path.join("loop_analysis.txt"), &loop_text)
.expect("Failed to write loop analysis text");
}
let mut visualization_data = PcgVisualizationData::new();
for block in body.basic_blocks.indices() {
let Ok(Some(pcg_block)) = analysis_results.get_all_for_bb(block) else {
Expand Down
30 changes: 30 additions & 0 deletions test-files/222_aurea_loop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
fn foo() {
// bb0 {}
'la: loop {
'lb: loop {
// bb1 {
iter();
// }
// bb2 {
if choice_inner() {
// }
// bb3 {
continue; } // -> bb1
break; // -> bb4
// }
}
// bb4 {
if choice_outer() {
// }
// bb5 {
continue; } // -> bb1
break; // -> bb6
// }
}
// bb6 {}
}

fn choice_inner() -> bool { false }
fn choice_outer() -> bool { false }
fn iter() {}
fn main() {}
8 changes: 8 additions & 0 deletions visualization/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export abstract class Api {
async fetchDotFile(filePath: string): Promise<string> {
return await this.fetchTextFile(filePath);
}

async getLoopAnalysis(functionName: string): Promise<string | null> {
try {
return await this.fetchTextFile(`data/${functionName}/loop_analysis.txt`);
} catch {
return null;
}
}
}

class FetchApi extends Api {
Expand Down
25 changes: 25 additions & 0 deletions visualization/src/components/LoopResults.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useEffect, useState } from "react";
import { Api } from "../api";

interface LoopResultsProps {
selectedFunction: string;
api: Api;
}

export default function LoopResults({ selectedFunction, api }: LoopResultsProps) {
const [loopText, setLoopText] = useState<string | null>(null);

useEffect(() => {
api.getLoopAnalysis(selectedFunction).then(setLoopText);
}, [selectedFunction, api]);

if (loopText === null) {
return <p>No loop analysis data available.</p>;
}

return (
<pre style={{ fontSize: "12px", whiteSpace: "pre", margin: 0 }}>
{loopText}
</pre>
);
}
12 changes: 11 additions & 1 deletion visualization/src/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { Api } from "../api";
import { CurrentPoint, FunctionSlug } from "../types";
import BorrowCheckerGraphs from "./BorrowCheckerGraphs";
import LoopResults from "./LoopResults";

interface SettingsProps {
showSettings: boolean;
Expand Down Expand Up @@ -41,7 +42,8 @@ export default function Settings({
right: 0,
top: 0,
bottom: 0,
width: "300px",
minWidth: "300px",
width: "fit-content",
backgroundColor: "#f5f5f5",
borderLeft: "2px solid #ccc",
padding: "20px",
Expand Down Expand Up @@ -103,6 +105,14 @@ export default function Settings({
api={api}
/>
</div>

<div style={{ marginBottom: "20px" }}>
<h4>Loop Results</h4>
<LoopResults
selectedFunction={selectedFunction}
api={api}
/>
</div>
</div>
);
}
Expand Down
Loading