Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support non-compressed proofs in axiom_use.rs #161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
79 changes: 51 additions & 28 deletions metamath-rs/src/axiom_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::segment::SegmentRef;
use crate::segment_set::SegmentSet;
use crate::statement::{CommandToken, StatementAddress, TokenPtr};
use crate::util::HashMap;
use crate::StatementType;
use crate::{as_str, database::time, Database};
use crate::{StatementRef, StatementType};

/// Diagnostics issued when checking axiom usage in the Database.
///
Expand Down Expand Up @@ -89,21 +89,7 @@ impl<'a> UsagePass<'a> {
}
StatementType::Provable => {
let label = stmt.label();
let mut usage = Bitset::new();
let mut i = 1;
loop {
let tk = stmt.proof_slice_at(i);
i += 1;
if tk == b")" {
break;
}
if let Some(usage2) = self.axiom_use_map.get(tk) {
usage |= usage2
}
if i == stmt.proof_len() {
break;
}
}
let usage = get_proof_usage(&stmt, &self.axiom_use_map);
self.axiom_use_map.insert(label, usage);
}
StatementType::Axiom => {
Expand Down Expand Up @@ -144,23 +130,13 @@ impl Database {
let mut stmt_list = vec![];
for sref in self.statements().filter(|stmt| stmt.is_assertion()) {
let label = sref.label();
let mut usage = Bitset::new();
if label_test(label) {
let mut usage = Bitset::new();
usage.set_bit(stmt_list.len());
stmt_list.push(as_str(label));
stmt_use_map.insert(label, usage);
} else if sref.statement_type() == StatementType::Provable {
let mut i = 1;
loop {
let tk = sref.proof_slice_at(i);
i += 1;
if tk == b")" {
break;
}
if let Some(usage2) = stmt_use_map.get(tk) {
usage |= usage2
}
}
let usage = get_proof_usage(&sref, &stmt_use_map);
write!(out, "{}:", as_str(label))?;
for i in &usage {
write!(out, " {}", stmt_list[i])?;
Expand All @@ -173,3 +149,50 @@ impl Database {
})
}
}

#[inline]
fn get_proof_usage(sref: &StatementRef<'_>, stmt_use_map: &HashMap<&[u8], Bitset>) -> Bitset {
let mut usage = Bitset::new();
if sref.proof_slice_at(0) == b"(" {
let mut i = 1;
loop {
let tk = sref.proof_slice_at(i);
i += 1;
if tk == b")" {
break;
}
if let Some(usage2) = stmt_use_map.get(tk) {
usage |= usage2
}
if i == sref.proof_len() {
break;
}
}
} else {
#[cold]
fn process_non_compressed(
sref: &StatementRef<'_>,
stmt_use_map: &HashMap<&[u8], Bitset>,
usage: &mut Bitset,
) {
let mut i = 0;
while i < sref.proof_len() {
let tk = sref.proof_slice_at(i);
if let Some(usage2) = stmt_use_map.get(tk) {
*usage |= usage2
} else if let Some(i) = tk
.iter()
.position(|&x| x == b'=')
.or_else(|| tk.iter().position(|&x| x == b':'))
{
if let Some(usage2) = stmt_use_map.get(&tk[i + 1..]) {
*usage |= usage2
}
}
i += 1;
}
}
process_non_compressed(sref, stmt_use_map, &mut usage)
}
usage
}
Loading