Skip to content

Commit

Permalink
add some debug info for includes and library resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
incertia committed Apr 4, 2024
1 parent c4bb707 commit c946bf3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
19 changes: 13 additions & 6 deletions parser/src/include_logic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::errors::FileOsError;

use log::debug;

use super::errors::IncludeError;
use program_structure::ast::Include;
use program_structure::report::{Report, ReportCollection};
Expand Down Expand Up @@ -85,9 +87,10 @@ impl FileStack {
pub fn add_include(&mut self, include: &Include) -> Result<(), Box<Report>> {
let mut location = self.current_location.clone().expect("parsing file");
location.push(include.path.clone());
match fs::canonicalize(location) {
match fs::canonicalize(&location) {
Ok(path) => {
if !self.black_paths.contains(&path) {
debug!("adding local or absolute include `{}`", location.display());
self.stack.push(path);
}
Ok(())
Expand All @@ -108,18 +111,22 @@ impl FileStack {
}

let libpath = lib.path.join(&include.path);
debug!("searching for `{}` in `{}`", include.path, lib.path.display());
if fs::canonicalize(&libpath).is_ok() {
debug!("adding include `{}` from directory", libpath.display());
self.stack.push(libpath);
return Ok(());
}
} else {
// only match include paths with a single component i.e. lib.circom and not dir/lib.circom or
// ./lib.circom
if include.path.find(std::path::MAIN_SEPARATOR) == None
&& lib.path.file_name().expect("good library file") == pathos
{
self.stack.push(lib.path.clone());
return Ok(());
if include.path.find(std::path::MAIN_SEPARATOR) == None {

Check failure on line 123 in parser/src/include_logic.rs

View workflow job for this annotation

GitHub Actions / Lints

binary comparison to literal `Option::None`
debug!("checking if `{}` matches `{}`", include.path, lib.path.display());
if lib.path.file_name().expect("good library file") == pathos {
debug!("adding include `{}` from file", lib.path.display());
self.stack.push(lib.path.clone());
return Ok(());
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub fn parse_files(
if let Some(main_component) = program.main_component {
main_components.push((file_id, main_component, program.custom_gates));
}
debug!(
"adding {} definitions from `{}`",
program.definitions.iter().map(|x| x.name()).collect::<Vec<_>>().join(", "),
file_path.display(),
);
definitions.insert(file_id, program.definitions);
reports.append(&mut warnings);
}
Expand Down
9 changes: 9 additions & 0 deletions program_structure/src/abstract_syntax_tree/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ pub fn build_function(
Definition::Function { meta, name, args, arg_location, body }
}

impl Definition {
pub fn name(&self) -> String {
match self {
Self::Template { name, .. } => name.clone(),
Self::Function { name, .. } => name.clone(),
}
}
}

#[derive(Clone)]
pub enum Statement {
IfThenElse {
Expand Down

0 comments on commit c946bf3

Please sign in to comment.