improvements

This commit is contained in:
nora 2022-09-29 20:14:17 +02:00
parent f391b59f79
commit b95c9d4b44
3 changed files with 79 additions and 41 deletions

View file

@ -34,13 +34,28 @@
cols="80"
placeholder="// Rust code goes here..."
>
fn main() {}</textarea
struct Struct&lt;T&gt;(T);
impl&lt;T&gt; Struct&lt;T&gt; {
const CONST: fn() = || {
struct _Obligation where T:;
};
}
</textarea
>
<br />
<label for="start">Start</label>
<input id="start" value="2022-01-01" />
<label for="end">End (optional)</label>
<input id="end" />
<input id="end" value="2022-06-01" />
<label for="kind">Regression Kind</label>
<select id="kind">
<option>error</option>
<option>success</option>
<option selected="selected">ice</option>
<option>non-ice</option>
<option>non-error</option>
</select>
<br />
<br />
<button class="bisect-btn" onclick="bisect()">Bisect!</button>
@ -64,6 +79,7 @@ fn main() {}</textarea
const result = document.getElementById("result");
const start = document.getElementById("start");
const end = document.getElementById("end");
const kind = document.getElementById("kind");
let bisecting = false;
@ -84,14 +100,24 @@ fn main() {}</textarea
status.innerText = "Sending request...";
const params = new URLSearchParams();
params.append("start", start.value.trim());
params.append("kind", kind.value);
if (end.value.trim()) {
params.append("end", end.value.trim());
}
const body = code.value;
console.log("Bisecting", body);
const fetched = await fetch(`${BASE_URL}bisect?${params}`, {
method: "POST",
body: code.value,
body,
headers: {
"Content-Type": "application/text",
},
});
const { job_id } = await fetched.json();

View file

@ -5,7 +5,7 @@ use color_eyre::eyre::{Context, ContextCompat};
use color_eyre::Result;
use rusqlite::Connection;
use serde::Serialize;
use tracing::{error, info};
use tracing::{error, info, trace};
use uuid::Uuid;
use crate::{db, Options};
@ -67,41 +67,48 @@ pub fn bisect_worker(jobs: mpsc::Receiver<Job>, conn: Connection) {
Err(_) => return,
};
info!(id = %job.id, "Starting bisection job");
let mut bisect = Bisection {
id: job.id,
code: job.code.clone(),
status: BisectStatus::InProgress,
};
match db::add_bisection(&conn, &bisect).wrap_err("insert bisection") {
Ok(()) => {
let status = match bisect_job(job) {
Ok(status) => status,
Err(err) => {
error!(?err, "error processing bisection");
BisectStatus::Error {
output: err.to_string(),
}
}
};
bisect.status = status;
match db::update_bisection_status(&conn, &bisect) {
Ok(()) => {}
Err(err) => error!(?err, "error updating bisection"),
}
match process_job(job, &conn) {
Ok(()) => {}
Err(err) => {
error!(?err, "error processing bisection")
}
Err(err) => error!(?err, "error inserting bisection"),
}
}
}
#[tracing::instrument(skip(job), fields(id = %job.id))]
#[tracing::instrument(skip(job, conn), fields(id = %job.id))]
pub fn process_job(job: Job, conn: &Connection) -> Result<()> {
info!(id = %job.id, "Starting bisection job");
let mut bisect = Bisection {
id: job.id,
code: job.code.clone(),
status: BisectStatus::InProgress,
};
db::add_bisection(&conn, &bisect).wrap_err("insert bisection")?;
let status = match bisect_job(job) {
Ok(status) => status,
Err(err) => {
error!(?err, "error processing bisection");
BisectStatus::Error {
output: format!("Internal error"),
}
}
};
bisect.status = status;
db::update_bisection_status(&conn, &bisect).wrap_err("writing bisection result")?;
trace!(?bisect, "Finished bisection job");
Ok(())
}
fn bisect_job(job: Job) -> Result<BisectStatus> {
let (output, state) = run_bisect_for_file(job.code, job.options.start, job.options.end)?;
let (output, state) = run_bisect_for_file(job.code, &job.options)?;
info!(state = %state.status(), "Bisection finished");
process_result(output, state).wrap_err("process result")
@ -113,7 +120,9 @@ fn process_result(output: Output, state: JobState) -> Result<BisectStatus> {
match state {
JobState::Failed => {
let output = stderr.lines().rev().take(10).collect::<String>();
let mut output = stderr.lines().rev().take(30).collect::<Vec<_>>();
output.reverse();
let output = output.join("\n");
info!(?output, "output");
Ok(BisectStatus::Error { output })
}
@ -127,11 +136,7 @@ fn process_result(output: Output, state: JobState) -> Result<BisectStatus> {
}
}
fn run_bisect_for_file(
input: String,
start: chrono::NaiveDate,
end: Option<chrono::NaiveDate>,
) -> Result<(Output, JobState)> {
fn run_bisect_for_file(input: String, options: &Options) -> Result<(Output, JobState)> {
let temp_dir = tempdir::TempDir::new("bisect").wrap_err("creating tempdir")?;
let mut cargo_new = Command::new("cargo");
cargo_new
@ -156,12 +161,18 @@ fn run_bisect_for_file(
bisect.arg("--timeout").arg("30"); // don't hang
bisect.current_dir(&cargo_dir);
bisect.arg("--start").arg(start.to_string());
bisect.arg("--start").arg(options.start.to_string());
if let Some(end) = end {
if let Some(end) = options.end {
bisect.arg("--end").arg(end.to_string());
}
bisect
.arg("--regress")
.arg(options.kind.as_deref().unwrap_or("ice")); // FIXME Make this configurable
bisect.env("RUST_LOG", "error"); // overwrite RUST_LOG
let output = bisect.output().wrap_err("spawning cargo-bisect-rustc")?;
if output.status.success() {

View file

@ -97,6 +97,7 @@ async fn get_bisections(Extension(conn): Extension<Conn>) -> impl IntoResponse {
pub struct Options {
start: chrono::NaiveDate,
end: Option<chrono::NaiveDate>,
kind: Option<String>,
}
#[derive(Debug, Serialize)]