Skip to content

Commit dcc5456

Browse files
committed
Auto merge of #542 - jyn514:refactor, r=pietroalbini
Reduce duplication in `Task::run` Previously, this would create a new `TaskCtx` for every task that needed to run. Now it only constructs it once. This also had the most confusing error message I've ever had the misfortune to see in Rust: ```rust error[E0308]: mismatched types --> src/runner/tasks.rs:255:38 | 255 | test::run_test(action, &ctx, test)?; | ^^^^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2> fn(&'r runner::tasks::TaskCtx<'s, DB>, &'t0 rustwide::Build<'t1>, &'t2 std::collections::HashSet<cargo_metadata::PackageId>) -> std::result::Result<_, _>` found fn pointer `fn(&runner::tasks::TaskCtx<'_, DB>, &rustwide::Build<'_>, &std::collections::HashSet<cargo_metadata::PackageId>) -> std::result::Result<_, _>` ``` The fix was to change ``` let (action, test, toolchain, quiet): (_, fn(_, _, _) -> _, _, _) = match self.step { ``` to ``` let (action, test, toolchain, quiet): (_, fn(&TaskCtx<_>, &Build, &_) -> _, _, _) = match self.step { ``` I have no idea why.
2 parents 966d5d6 + 8efe38a commit dcc5456

File tree

1 file changed

+92
-80
lines changed

1 file changed

+92
-80
lines changed

src/runner/tasks.rs

Lines changed: 92 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::runner::test::detect_broken;
77
use crate::runner::{test, RunnerState};
88
use crate::toolchain::Toolchain;
99
use crate::utils;
10-
use rustwide::{BuildDirectory, Workspace};
10+
use rustwide::{Build, BuildDirectory, Workspace};
1111
use std::sync::Mutex;
1212

1313
use rustwide::logging::{self, LogStorage};
@@ -170,88 +170,100 @@ impl Task {
170170
db: &'ctx DB,
171171
state: &'ctx RunnerState,
172172
) -> Fallible<()> {
173-
match self.step {
174-
TaskStep::Cleanup => {
175-
// Remove stored logs
176-
state.lock().prepare_logs.remove(&self.krate);
177-
}
178-
TaskStep::Prepare => {
179-
let storage = LogStorage::from(config);
180-
state
181-
.lock()
182-
.prepare_logs
183-
.insert(self.krate.clone(), storage.clone());
184-
logging::capture(&storage, || {
185-
let rustwide_crate = self.krate.to_rustwide();
186-
detect_broken(rustwide_crate.fetch(workspace))?;
187-
188-
if let Crate::GitHub(repo) = &self.krate {
189-
if let Some(sha) = rustwide_crate.git_commit(workspace) {
190-
let updated = GitHubRepo {
191-
sha: Some(sha),
192-
..repo.clone()
193-
};
194-
db.update_crate_version(
195-
ex,
196-
&Crate::GitHub(repo.clone()),
197-
&Crate::GitHub(updated),
198-
)
199-
.with_context(|_| {
200-
format!("failed to record the sha of GitHub repo {}", repo.slug())
201-
})?;
202-
} else {
203-
bail!("unable to capture sha for {}", repo.slug());
204-
}
205-
}
206-
Ok(())
207-
})?;
208-
}
209-
TaskStep::BuildAndTest { ref tc, quiet } => {
210-
let ctx = TaskCtx::new(build_dir, config, db, ex, tc, &self.krate, state, quiet);
211-
test::run_test("testing", &ctx, test::test_build_and_test)?;
212-
}
213-
TaskStep::BuildOnly { ref tc, quiet } => {
214-
let ctx = TaskCtx::new(build_dir, config, db, ex, tc, &self.krate, state, quiet);
215-
test::run_test("building", &ctx, test::test_build_only)?;
216-
}
217-
TaskStep::CheckOnly { ref tc, quiet } => {
218-
let ctx = TaskCtx::new(build_dir, config, db, ex, tc, &self.krate, state, quiet);
219-
test::run_test("checking", &ctx, test::test_check_only)?;
220-
}
221-
TaskStep::Clippy { ref tc, quiet } => {
222-
let ctx = TaskCtx::new(build_dir, config, db, ex, tc, &self.krate, state, quiet);
223-
test::run_test("linting", &ctx, test::test_clippy_only)?;
224-
}
225-
TaskStep::Rustdoc { ref tc, quiet } => {
226-
let ctx = TaskCtx::new(build_dir, config, db, ex, tc, &self.krate, state, quiet);
227-
test::run_test("documenting", &ctx, test::test_rustdoc)?;
228-
}
229-
TaskStep::UnstableFeatures { ref tc } => {
230-
let ctx = TaskCtx::new(build_dir, config, db, ex, tc, &self.krate, state, false);
231-
test::run_test(
173+
let (action, test, toolchain, quiet): (_, fn(&TaskCtx<_>, &Build, &_) -> _, _, _) =
174+
match self.step {
175+
TaskStep::BuildAndTest { ref tc, quiet } => {
176+
("testing", test::test_build_and_test, tc, quiet)
177+
}
178+
TaskStep::BuildOnly { ref tc, quiet } => {
179+
("building", test::test_build_only, tc, quiet)
180+
}
181+
TaskStep::CheckOnly { ref tc, quiet } => {
182+
("checking", test::test_check_only, tc, quiet)
183+
}
184+
TaskStep::Clippy { ref tc, quiet } => {
185+
("linting", test::test_clippy_only, tc, quiet)
186+
}
187+
TaskStep::Rustdoc { ref tc, quiet } => {
188+
("documenting", test::test_rustdoc, tc, quiet)
189+
}
190+
TaskStep::UnstableFeatures { ref tc } => (
232191
"checking unstable",
233-
&ctx,
234192
crate::runner::unstable_features::find_unstable_features,
235-
)?;
236-
}
237-
TaskStep::Skip { ref tc } => {
238-
// If a skipped crate is somehow sent to the agent (for example, when a crate was
239-
// added to the experiment and *then* blacklisted) report the crate as skipped
240-
// instead of silently ignoring it.
241-
db.record_result(
242-
ex,
243193
tc,
244-
&self.krate,
245-
None,
246-
config,
247-
EncodingType::Plain,
248-
|| {
249-
warn!("crate skipped");
250-
Ok(TestResult::Skipped)
251-
},
252-
)?;
253-
}
254-
}
194+
false,
195+
),
196+
TaskStep::Cleanup => {
197+
// Remove stored logs
198+
state.lock().prepare_logs.remove(&self.krate);
199+
return Ok(());
200+
}
201+
TaskStep::Prepare => {
202+
let storage = LogStorage::from(config);
203+
state
204+
.lock()
205+
.prepare_logs
206+
.insert(self.krate.clone(), storage.clone());
207+
logging::capture(&storage, || {
208+
let rustwide_crate = self.krate.to_rustwide();
209+
detect_broken(rustwide_crate.fetch(workspace))?;
210+
211+
if let Crate::GitHub(repo) = &self.krate {
212+
if let Some(sha) = rustwide_crate.git_commit(workspace) {
213+
let updated = GitHubRepo {
214+
sha: Some(sha),
215+
..repo.clone()
216+
};
217+
db.update_crate_version(
218+
ex,
219+
&Crate::GitHub(repo.clone()),
220+
&Crate::GitHub(updated),
221+
)
222+
.with_context(|_| {
223+
format!(
224+
"failed to record the sha of GitHub repo {}",
225+
repo.slug()
226+
)
227+
})?;
228+
} else {
229+
bail!("unable to capture sha for {}", repo.slug());
230+
}
231+
}
232+
Ok(())
233+
})?;
234+
return Ok(());
235+
}
236+
TaskStep::Skip { ref tc } => {
237+
// If a skipped crate is somehow sent to the agent (for example, when a crate was
238+
// added to the experiment and *then* blacklisted) report the crate as skipped
239+
// instead of silently ignoring it.
240+
db.record_result(
241+
ex,
242+
tc,
243+
&self.krate,
244+
None,
245+
config,
246+
EncodingType::Plain,
247+
|| {
248+
warn!("crate skipped");
249+
Ok(TestResult::Skipped)
250+
},
251+
)?;
252+
return Ok(());
253+
}
254+
};
255+
256+
let ctx = TaskCtx::new(
257+
build_dir,
258+
config,
259+
db,
260+
ex,
261+
toolchain,
262+
&self.krate,
263+
state,
264+
quiet,
265+
);
266+
test::run_test(action, &ctx, test)?;
255267

256268
Ok(())
257269
}

0 commit comments

Comments
 (0)