Skip to content
Open
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
2 changes: 1 addition & 1 deletion tools/hermes/src/charon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo_metadata::{diagnostic::DiagnosticLevel, Message};

use crate::{
resolve::{Args, HermesTargetKind, Roots},
shadow::HermesArtifact,
scanner::HermesArtifact,
};

pub fn run_charon(args: &Args, roots: &Roots, packages: &[HermesArtifact]) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions tools/hermes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod diagnostics;
mod errors;
mod parse;
mod resolve;
mod shadow;
mod scanner;

mod ui_test_shim;

Expand Down Expand Up @@ -35,11 +35,11 @@ fn main() -> anyhow::Result<()> {
match args.command {
Commands::Verify(resolve_args) => {
let roots = resolve::resolve_roots(&resolve_args)?;
let entry_points = shadow::build_shadow_crate(&roots)?;
if entry_points.is_empty() {
let packages = scanner::scan_workspace(&roots)?;
if packages.is_empty() {
anyhow::bail!("No Hermes annotations (/// ```lean ...) found in the selected targets. Nothing to verify.");
}
charon::run_charon(&resolve_args, &roots, &entry_points)
charon::run_charon(&resolve_args, &roots, &packages)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions tools/hermes/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ pub struct Roots {
}

impl Roots {
pub fn shadow_root(&self) -> PathBuf {
self.hermes_run_root.join("shadow")
}

pub fn charon_root(&self) -> PathBuf {
self.hermes_run_root.join("charon")
}
Expand Down
36 changes: 6 additions & 30 deletions tools/hermes/src/shadow.rs → tools/hermes/src/scanner.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::{
collections::{HashMap, HashSet},
fs,
collections::HashMap,
hash::{Hash, Hasher as _},
path::{Path, PathBuf},
sync::mpsc::{self, Sender},
};

use anyhow::{Context, Result};
use dashmap::DashSet;
use walkdir::WalkDir;

use crate::{
parse,
Expand Down Expand Up @@ -45,13 +43,10 @@ impl HermesArtifact {
}
}

/// The main entry point for creating the shadow crate.
///
/// 1. Scans and transforms all reachable source files, printing any errors
/// 1. Scans and rules all reachable source files, printing any errors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The word "rules" in this comment appears to be a typo. Considering the function's purpose of scanning and parsing files, perhaps you meant "parses"?

Suggested change
/// 1. Scans and rules all reachable source files, printing any errors
/// 1. Scans and parses all reachable source files, printing any errors

/// encountered. Collects all items with Hermes annotations.
/// 2. Creates symlinks for the remaining skeleton.
pub fn build_shadow_crate(roots: &Roots) -> Result<Vec<HermesArtifact>> {
log::trace!("build_shadow_crate({:?})", roots);
pub fn scan_workspace(roots: &Roots) -> Result<Vec<HermesArtifact>> {
log::trace!("scan_workspace({:?})", roots);

let visited_paths = DashSet::new();
let (err_tx, err_rx) = mpsc::channel();
Expand Down Expand Up @@ -164,25 +159,10 @@ fn process_file_recursive<'a>(
return;
}

// shadow_root + (src_path - workspace_root)
let relative_path = match src_path.strip_prefix(&config.workspace) {
Ok(p) => p,
Err(e) => {
let _ = err_tx.send(anyhow::anyhow!("Source file outside workspace: {:?}", e));
return;
}
};
let dest_path = config.shadow_root().join(relative_path);

// Walking the AST is enough to collect new modules.
let result = (|| -> Result<Vec<(PathBuf, String)>> {
if let Some(parent) = dest_path.parent() {
// NOTE: `create_dir_all` is robust against TOCTOU, so it's fine
// that we're racing with other threads.
fs::create_dir_all(parent)?;
}

// Walk the AST, collecting new modules to process.
let (source_code, unloaded_modules) =
let (_source_code, unloaded_modules) =
parse::read_file_and_scan_compilation_unit(src_path, |_src, item_result| {
match item_result {
Ok(parsed_item) => {
Expand All @@ -206,10 +186,6 @@ fn process_file_recursive<'a>(
})
.context(format!("Failed to parse {:?}", src_path))?;

let buffer = source_code.into_bytes();
fs::write(&dest_path, &buffer)
.context(format!("Failed to write shadow file {:?}", dest_path))?;

// Resolve and queue child modules for processing.
let base_dir = src_path.parent().unwrap();
let mut next_paths = Vec::new();
Expand Down
Loading