Skip to content

Commit

Permalink
fix: fmt + clippy, unused util
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Nov 14, 2024
1 parent 3803e1d commit e04ad2b
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 89 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion book/developers/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The full command to profile should look something like this
TRACE_FILE=output.json TRACE_SAMPLE_RATE=100 cargo run ...
```

To view these profiles, we reccomened Samply.
To view these profiles, we reccomend Samply.
```sh
cargo install --locked samply
samply load output.json
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/bin/cargo-prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use clap::{Parser, Subcommand};
use sp1_cli::{
commands::{
build::BuildCmd, build_toolchain::BuildToolchainCmd,
install_toolchain::InstallToolchainCmd, new::NewCmd, prove::ProveCmd,
vkey::VkeyCmd,
install_toolchain::InstallToolchainCmd, new::NewCmd, prove::ProveCmd, vkey::VkeyCmd,
},
SP1_VERSION_MESSAGE,
};
Expand Down
37 changes: 0 additions & 37 deletions crates/cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::path::{Path, PathBuf};
use std::{fmt::Display, time::Duration};

pub(crate) fn write_status(style: &dyn Display, status: &str, msg: &str) {
Expand All @@ -14,39 +13,3 @@ pub(crate) fn elapsed(duration: Duration) -> String {
format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000)
}
}

/// Create a canonical path from a given path.
///
/// This function will create any necessary directories in the path if they do not exist.
///
/// This function does not guarntee that the file or directory exists, only that the path is valid.
/// (ie. [std::fs::File::create] and [std::fs::DirBuilder::create] will work)
pub(crate) fn canon_path(path: impl AsRef<Path>) -> Result<PathBuf, std::io::Error> {
let path = path.as_ref();

// in case this is a file, we only need to ensure its parent directorys are created
if path.components().count() > 1 {
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
// unwrap: we know we have a last component because we have a parent
let last_component = path.components().last().unwrap();

return Ok(parent
.canonicalize()
.inspect_err(|_| {
eprintln!("Failed to canonicalize parent directory: {:?}", parent);
})?
.join(last_component));
}
}

if !path.has_root() {
// we dont have a parent or a root,
// so lets just adjoin it to the currnet working dir
return Ok(std::env::current_dir()?.join(path));
}

// we didnt have a parent, and we have root
// so this can only be the root dir
Ok(path.to_path_buf())
}
20 changes: 8 additions & 12 deletions crates/core/executor/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
fs::File,
io::BufWriter,
sync::Arc,
};
use std::{fs::File, io::BufWriter, sync::Arc};

use hashbrown::HashMap;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -98,7 +94,7 @@ pub struct Executor<'a> {

/// A buffer for stdout and stderr IO.
pub io_buf: HashMap<u32, String>,

/// The ZKVM profiler. This is only available in debug mode.
pub profiler: Option<(Profiler, BufWriter<File>)>,

Expand Down Expand Up @@ -178,7 +174,7 @@ impl<'a> Executor<'a> {
pub fn new(program: Program, opts: SP1CoreOpts) -> Self {
Self::with_context(program, opts, SP1Context::default())
}

/// Crete a new runtime for the program, and setup the profiler if `TRACE_FILE` is set.
#[cfg(debug_assertions)]
#[must_use]
Expand Down Expand Up @@ -206,9 +202,10 @@ impl<'a> Executor<'a> {
})
.unwrap_or(1);

this.profiler = Some(
(Profiler::new(elf_bytes, sample_rate).expect("Failed to create profiler"), trace_buf)
);
this.profiler = Some((
Profiler::new(elf_bytes, sample_rate).expect("Failed to create profiler"),
trace_buf,
));
}

this
Expand Down Expand Up @@ -1485,7 +1482,6 @@ impl<'a> Executor<'a> {
}
}


Ok(())
}

Expand All @@ -1498,7 +1494,7 @@ impl<'a> Executor<'a> {
self.executor_mode = ExecutorMode::Trace;
self.print_report = true;
while !self.execute()? {}

#[cfg(debug_assertions)]
{
if let Some((profiler, writer)) = self.profiler.take() {
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ impl<C: SP1ProverComponents> SP1Prover<C> {
context.subproof_verifier.replace(Arc::new(self));
let program = self.get_program(elf).unwrap();
let opts = SP1CoreOpts::default();
let mut runtime = if cfg!(debug_assertions) {
let mut runtime = if cfg!(debug_assertions) {
Executor::with_context_and_elf(program, opts, context, elf)
} else {
Executor::with_context(program, opts, context)
};
};

runtime.write_vecs(&stdin.buffer);
for (proof, vkey) in stdin.proofs.iter() {
Expand Down
Loading

0 comments on commit e04ad2b

Please sign in to comment.