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

Verify definitions #116

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
66383c8
Add function to export theorem dependencies in GraphML format
tirix Jun 4, 2023
efd0db3
Remove unwanted file!
tirix Jun 4, 2023
2d388c2
Fix typo
tirix Jun 4, 2023
43b89d5
Skipping syntactic dependencies
tirix Jun 4, 2023
414fdd7
Definition check and definition graph export
tirix Jun 8, 2023
293fd6e
Clippy and more one more check
tirix Jun 8, 2023
5facc9d
Fmt
tirix Jun 8, 2023
91ed49f
Error handling
tirix Jun 8, 2023
bc0cd3a
Special malformed definition case
tirix Jun 8, 2023
4212498
Clppy
tirix Jun 8, 2023
7fdcbab
organizing the parts that have been done so far
digama0 Jun 10, 2023
1ce90bc
Remove unused diagnostic type
tirix Jun 11, 2023
b0e7f20
refactoring
digama0 Jun 12, 2023
4005a02
check that statements don't use pending defs
digama0 Jun 12, 2023
7e64ac3
check refl, symm, trans
digama0 Jun 12, 2023
fc812fd
Misc comments
tirix Jun 12, 2023
1dbb11a
starting on justification processing
digama0 Jun 12, 2023
eb7f27a
Mention the possible missing definition case
tirix Jun 12, 2023
ecfd2e9
Tests for the definition checker
tirix Jun 12, 2023
7a4a68c
Format
tirix Jun 12, 2023
ec62775
Oops
tirix Jun 12, 2023
8a5f967
Merge branch 'main' into verify_definitions
tirix Jun 12, 2023
d1cf04a
Typo
tirix Jun 12, 2023
b0ec8cc
add free dummy check
digama0 Jun 12, 2023
43c4f60
DV condition for justifications
digama0 Jun 13, 2023
5823b9c
parameter DV check
digama0 Jun 13, 2023
2cd7866
dummy DV check
digama0 Jun 13, 2023
c685f4f
check for definiendum on RHS
digama0 Jun 13, 2023
57a8bca
misnamed axiom/def warnings
digama0 Jun 13, 2023
aa1eae3
Merge branch 'main' into verify_definitions
tirix Jun 22, 2023
d21c13b
Merge branch 'main' into verify_definitions
tirix Jun 22, 2023
1b77b7a
Merge branch 'main' into verify_definitions
tirix Jul 2, 2023
aa4cafc
Merge branch 'main' into verify_definitions
tirix Nov 27, 2023
7011aef
Fix merge
tirix Nov 27, 2023
80490fe
Merge branch 'main' into verify_definitions
digama0 Nov 27, 2023
ca1e4af
Merge branch 'main' into verify_definitions
tirix Jun 1, 2024
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
21 changes: 19 additions & 2 deletions metamath-knife/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn main() {
(@arg split: --split "Processes files > 1 MiB in multiple segments")
(@arg timing: --time "Prints milliseconds after each stage")
(@arg verify: -v --verify "Checks proof validity")
(@arg verify_defs: --("verify-defs") "Checks definitions")
(@arg discouraged: -D --discouraged [FILE] "Regenerates `discouraged` file")
(@arg axiom_use: -X --("axiom-use") [FILE] "Generate `axiom-use` file")
(@arg stmt_use: --("stmt-use") value_names(&["FILE", "LABELS"]) "Outputs statements directly or indirectly using the given list of statements")
Expand Down Expand Up @@ -66,7 +67,9 @@ fn main() {
#[cfg(feature = "xml")]
let app = clap_app!(@app (app)
(@arg export_graphml_deps: --("export-graphml-deps") [FILE]
"Exports all theorem dependencies in the GraphML file format")
"Exports all theorem dependencies in the GraphML file format")
(@arg export_graphml_defs: --("export-graphml-defs") [FILE]
"Exports all definition dependencies in the GraphML file format")
);

#[cfg(feature = "verify_markup")]
Expand All @@ -84,9 +87,11 @@ fn main() {
|| matches.is_present("grammar")
|| matches.is_present("parse_stmt")
|| matches.is_present("verify_parse_stmt")
|| matches.is_present("verify_defs")
|| matches.is_present("export_grammar_dot")
|| matches.is_present("dump_grammar")
|| matches.is_present("dump_formula"),
|| matches.is_present("dump_formula")
|| matches.is_present("export_graphml_defs"),
jobs: usize::from_str(matches.value_of("jobs").unwrap_or("1"))
.expect("validator should check this"),
};
Expand Down Expand Up @@ -132,6 +137,10 @@ fn main() {
db.verify_parse_stmt();
}

if matches.is_present("verify_defs") {
db.definitions_pass();
}

if matches.is_present("verify_usage") {
db.verify_usage_pass();
}
Expand All @@ -152,6 +161,14 @@ fn main() {
.unwrap_or_else(|diag| diags.push((StatementAddress::default(), diag)));
}

#[cfg(feature = "xml")]
if matches.is_present("export_graphml_defs") {
File::create(matches.value_of("export_graphml_defs").unwrap())
.map_err(|err| err.into())
.and_then(|file| db.export_graphml_defs(&mut BufWriter::new(file)))
.unwrap_or_else(|diag| diags.push((StatementAddress::default(), diag)));
}

if matches.is_present("axiom_use") {
File::create(matches.value_of("axiom_use").unwrap())
.and_then(|file| {
Expand Down
42 changes: 38 additions & 4 deletions metamath-rs/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ impl Bitset {
}

fn tail_mut(&mut self) -> &mut Vec<usize> {
if self.tail.is_none() {
self.tail = Some(Box::default());
}
self.tail.as_mut().unwrap()
self.tail.get_or_insert_with(Box::default)
}

/// Adds a single bit to a set.
Expand All @@ -87,6 +84,28 @@ impl Bitset {
}
}

/// Removes a single bit from a set.
pub fn unset_bit(&mut self, bit: usize) {
if bit < bits_per_word() {
self.head &= !(1 << bit);
} else if let Some(tail) = &mut self.tail {
let mut word = bit / bits_per_word() - 1;
if word < tail.len() {
tail[word] &= !(1 << (bit & (bits_per_word() - 1)));
if word + 1 == tail.len() && tail[word] == 0 {
while tail[word] == 0 {
if word == 0 {
self.tail = None;
return;
}
word -= 1;
}
tail.truncate(word + 1);
}
}
}
}

/// Tests a set for a specific bit.
pub fn has_bit(&self, bit: usize) -> bool {
if bit < bits_per_word() {
Expand Down Expand Up @@ -120,6 +139,21 @@ impl Bitset {
}
}

pub fn is_subset_of(&self, rhs: &Self) -> bool {
!rhs.head & self.head == 0
&& match &self.tail {
Some(ltail) => (0..ltail.len()).all(|i| {
let rtail_i = rhs
.tail
.as_ref()
.and_then(|rtail| rtail.get(i).copied())
.unwrap_or(0);
!rtail_i & ltail[i] == 0
}),
_ => true,
}
}

/// Returns true if this bitset has no bits set.
pub fn is_empty(&self) -> bool {
self.head == 0
Expand Down
40 changes: 40 additions & 0 deletions metamath-rs/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

use crate::as_str;
use crate::axiom_use::UsageResult;
use crate::defck::DefResult;
use crate::diag;
use crate::diag::Diagnostic;
use crate::export;
Expand Down Expand Up @@ -404,6 +405,7 @@
outline: Option<Arc<Outline>>,
grammar: Option<Arc<Grammar>>,
stmt_parse: Option<Arc<StmtParse>>,
definitions: Option<Arc<DefResult>>,
}

impl Default for Database {
Expand Down Expand Up @@ -434,6 +436,7 @@
Arc::make_mut(&mut self.segments).clear();
self.typesetting = None;
self.outline = None;
self.definitions = None;
});
}
}
Expand All @@ -458,6 +461,7 @@
outline: None,
grammar: None,
stmt_parse: None,
definitions: None,
prev_nameset: None,
prev_scopes: None,
prev_verify: None,
Expand Down Expand Up @@ -503,6 +507,7 @@
self.typesetting = None;
self.outline = None;
self.grammar = None;
self.definitions = None;
});
}

Expand Down Expand Up @@ -776,6 +781,38 @@
)
}

/// Checks all definitions soundness.
pub fn definitions_pass(&mut self) -> &Arc<DefResult> {
if self.definitions.is_none() {
self.stmt_parse_pass();
time(&self.options.clone(), "defck_pass", || {
let parse = self.parse_result();
let mut definitions = DefResult::default();
self.verify_definitions(parse, &mut definitions);
self.definitions = Some(Arc::new(definitions));
})
}
self.definitions_result()
}

/// Returns the results of the definition check pass.
/// Returns `None` if [`Database::definitions_pass`] was not previously called.
#[inline]
#[must_use]
pub const fn try_definitions_result(&self) -> Option<&Arc<DefResult>> {
self.definitions.as_ref()
}

/// Returns the results of the definition check pass.
/// Panics if [`Database::definition_pass`] was not previously called.

Check warning on line 807 in metamath-rs/src/database.rs

View workflow job for this annotation

GitHub Actions / Rebuild and test (ubuntu-20.04, stable)

unresolved link to `Database::definition_pass`

Check warning on line 807 in metamath-rs/src/database.rs

View workflow job for this annotation

GitHub Actions / Rebuild and test (ubuntu-latest, stable)

unresolved link to `Database::definition_pass`

Check warning on line 807 in metamath-rs/src/database.rs

View workflow job for this annotation

GitHub Actions / Rebuild and test (windows-latest, stable)

unresolved link to `Database::definition_pass`

Check warning on line 807 in metamath-rs/src/database.rs

View workflow job for this annotation

GitHub Actions / Rebuild and test (macOS-latest, stable)

unresolved link to `Database::definition_pass`
#[inline]
#[must_use]
pub fn definitions_result(&self) -> &Arc<DefResult> {
self.try_definitions_result().expect(
"The database has not run `stmt_parse_pass()`. Please ensure it is run before calling depending methods."
)
}

/// A getter method which does not build the outline.
#[inline]
#[must_use]
Expand Down Expand Up @@ -1016,6 +1053,9 @@
if let Some(pass) = self.try_typesetting_result() {
diags.extend_from_slice(&pass.diagnostics)
}
if let Some(pass) = self.try_definitions_result() {
diags.extend(pass.diagnostics())
}
diags
}

Expand Down
Loading
Loading