#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub(crate) fn parse_workspace_siblings(content: &str) -> Vec<String> {
for line in content.lines() {
let trimmed = line.trim();
if let Some(rest) = trimmed.strip_prefix("siblings") {
let rest = rest.trim().strip_prefix('=').unwrap_or("").trim();
if let Some(inner) = rest.strip_prefix('[').and_then(|s| s.strip_suffix(']')) {
return inner
.split(',')
.map(|s| s.trim().trim_matches('"').trim_matches('\'').to_string())
.filter(|s| !s.is_empty())
.collect();
}
}
}
Vec::new()
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub(crate) fn build_corpus_entry(func: &FunctionEntry) -> String {
let doc = func.doc_comment.as_deref().unwrap_or("");
let cap = func.function_name.len() * 2
+ func.signature.len() * 2
+ doc.len() * 2
+ func.file_path.len()
+ func.source.len().min(4096) / 5
+ 8;
let mut s = String::with_capacity(cap);
s.push_str(&func.function_name);
s.push(' ');
s.push_str(&func.function_name);
s.push(' ');
s.push_str(&func.signature);
s.push(' ');
s.push_str(&func.signature);
s.push(' ');
s.push_str(doc);
s.push(' ');
s.push_str(doc);
s.push(' ');
s.push_str(&func.file_path);
s.push(' ');
append_identifiers(&func.source, &mut s);
s
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub(crate) fn build_indices(functions: &[FunctionEntry]) -> BuildIndicesResult {
build_indices_impl(functions, true)
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub(crate) fn build_indices_without_corpus(functions: &[FunctionEntry]) -> BuildIndicesResult {
build_indices_impl(functions, false)
}
fn build_indices_impl(functions: &[FunctionEntry], include_corpus: bool) -> BuildIndicesResult {
let name_cap = functions.len() * 3 / 5;
let file_cap = functions.len() / 5;
let mut result = BuildIndicesResult {
name_index: HashMap::with_capacity(name_cap),
file_index: HashMap::with_capacity(file_cap),
corpus: if include_corpus {
Vec::with_capacity(functions.len())
} else {
Vec::new()
},
};
for (idx, func) in functions.iter().enumerate() {
let name_entries = result
.name_index
.entry(func.function_name.clone())
.or_default();
if name_entries.len() < 100 {
name_entries.push(idx);
}
result
.file_index
.entry(func.file_path.clone())
.or_default()
.push(idx);
if include_corpus {
result.corpus.push(build_corpus_entry(func));
}
}
result
}
pub(super) fn compute_file_sha256(content: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(content.as_bytes());
format!("{:x}", hasher.finalize())
}