metamath / metamath-knife

Metamath-knife can rapidly verify Metamath proofs, providing strong confidence that the proofs are correct.
Apache License 2.0
26 stars 11 forks source link

API issues #35

Open digama0 opened 2 years ago

digama0 commented 2 years ago

This is a collection of issues I notice while looking at the docs.

tirix commented 2 years ago

Thanks Mario! As for issues on my contributions:

Database::print_grammar, Database::print_formula etc. look like debugging tools, they shouldn't be in the public API. If they are, they should have a return value or write to an impl Write or something.

Yes, they indeed are debugging tools. Ok with that change for Grammar. For Formula, this could be done on the proposed FormulaRef:

Substitutions implements Index<&Label>, which uses an unnecessary indirection since Label is a 4 byte Copy type.

Fix in #34

Grammar::parse_formula takes a &mut dyn Iterator but it could take &mut impl Iterator

Fix in #34

Formula::build_syntax_proof has an unused A type parameter.

Fix in #34

outline says it is not stable, so it should probably not be public at all.

Actually is it just as (un)stable as the rest, and I've also used it in a toy dependent project. I'd say we keep it like that! :-)

For the rest - some of them would be included in an API revamp around Database as proposed in #24 . Snippet looks very interesting!

tirix commented 2 years ago

OutlineNode::get_name is unsound because OutlineNode::name is public

Fix in #56

Database::diag_notations is a weird API. types could be a config struct with boolean fields, and the output could be provided by a callback to allow for incremental rendering and doing whatever the user wants to do with the diagnostics.

The output of Database::diag_notations is now indeed provided through a callback since #49, but the types parameter has not been changed yet.

tirix commented 2 years ago

util should not be public

Fix in #42

Why are filename, fnv and regex being re-exported?

Fix in #42

tirix commented 2 years ago

parser::as_str is unsound and should at least be private

It is used in mm-web-rs, metamath-vspa, rumm, and metamath-web, that's all 4 current dependencies. I think we shall keep it public.

What's your opinion, @digama0 ?

tirix commented 2 years ago

Diagnostic doesn't have docstrings for the variants.

Yes but are the names and the messages in to_snippet not self-explanatory already? In any case, this would be easy to add.

digama0 commented 2 years ago

parser::as_str is unsound and should at least be private

It is used in mm-web-rs, metamath-vspa, rumm, and metamath-web, that's all 4 current dependencies. I think we shall keep it public.

What's your opinion, @digama0 ?

Well yes, it is unsound but convenient so I'm not surprised it is used. To avoid breakage, I think it would be fine to replace the existing as_str with one that does from_utf8().unwrap() instead of from_utf8_unchecked(), and those dependents can either make their own private version that does the unsound thing or just use the runtime check. We can also add statement_as_str() type methods on getters that both retrieve a string and convert it to a &str so that they can make use of the invariant to soundly use from_utf8_unchecked. (Be careful that this is actually correct though; the parser doesn't just bail on non-ascii input, so non-ascii can end up in some data structures.)

Diagnostic doesn't have docstrings for the variants.

Yes but are the names and the messages in to_snippet not self-explanatory already? In any case, this would be easy to add.

Not quite; the main purpose of the docs on the variants would be to explain what the arguments to the variants are. Beyond that, copying the first line "short" message from the error report is probably sufficient.

tirix commented 2 years ago

as_str

Actually the definition of as_str is

/// Transmutes this token into a Rust string.
#[must_use]
pub fn as_str(ptr: TokenPtr<'_>) -> &str {
    std::str::from_utf8(ptr).expect("TokenPtr is supposed to be UTF8")
}

So it is not unsafe. It'd rather the other way around: it might be an optimization to use from_utf8_unchecked() internally.

Diagnostic doesn't have docstrings for the variants.

Ok, agreed.

digama0 commented 2 years ago

@tirix Oh, if that is as_str then I guess the problem has already been addressed at some point. I will mark it as done.