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

Nom nom #2480

Merged
merged 18 commits into from
Mar 4, 2024
Merged

Nom nom #2480

merged 18 commits into from
Mar 4, 2024

Conversation

stefnotch
Copy link
Contributor

  1. Update documentation to reflect any user-facing changes - in this repository.

  2. Make sure that the changes are covered by unit-tests.

  3. Run cargo clippy on the changes.

  4. Run cargo +nightly fmt on the changes.

  5. Please put changelog entries in the description of this Pull Request
    if knowledge of this change could be valuable to users. No need to put the
    entries to the changelog directly, they will be transferred to the changelog
    file by maintainers right after the Pull Request merge.

    Please remove any items from the template below that are not applicable.

  6. Describe in common words what is the purpose of this change, related
    Github Issues, and highlight important implementation aspects.

The regexes for parsing the vk.xml file have been replaced with equivalent nom constructions. The nom code I wrote is probably not optimal, since I was learning the library as I went along. That's also why one will find different "styles" of nom code.

Changelog:

### Public dependency updates
- [regex](https://crates.io/crates/regex) has been replaced with [nom](https://crates.io/crates/nom)

@stefnotch
Copy link
Contributor Author

And now the benchmarks, as promised.

I did them by running

cargo clean
cargo build --lib --timings

There are 3 benchmarks for before (regex), and 2 benchmarks for after migrating to nom
cargo-timing-before-and-after.zip

At the very least, compile times didn't regress. I think on average, they slightly improved, but I haven't done a statistically rigorous test.

@Rua
Copy link
Contributor

Rua commented Feb 29, 2024

Looks good! @marc0246 do you have anything more to add?

Cargo.toml Outdated Show resolved Hide resolved
vulkano/Cargo.toml Outdated Show resolved Hide resolved
@marc0246
Copy link
Contributor

marc0246 commented Mar 3, 2024

A couple nit picks regarding overall code structure.

I'm seeing value used as the variable name for parser input in a lot of places. I think it would be more self-documenting to use input or i in all cases.

This pattern:

parser(input).map(|(input, x)| (input, thing(x)))

Is what Parser::map is for, so that you don't have to string the input along manually and it's cleaner. Note that types implementing Parser also have Parser::parse. Not only functions are parsers. This applies to e.g. the Map parser:

parser.map(thing).parse(input)

Parsers are generally not prefixed with parse_, rather they are called the thing that they parse. (Think char or whatever.) This applies to parse_name, parse_expression_start and parse_expression_root, but not parse_depends for instance, because that one is not a parser just a function that parses. (It doesn't return the rest of the input alongside the result.)

@marc0246
Copy link
Contributor

marc0246 commented Mar 4, 2024

I love it, thanks! ❤️

@marc0246 marc0246 merged commit b34dbe9 into vulkano-rs:master Mar 4, 2024
5 checks passed
marc0246 added a commit that referenced this pull request Mar 4, 2024
@stefnotch
Copy link
Contributor Author

I must say I really enjoyed working on this, and then getting top tier feedback. It's been a while since I got to learn so much in such a short period of time. <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants