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

fix!: Make ErrMode optional by using Result #712

Merged
merged 17 commits into from
Jan 24, 2025
Merged

Conversation

epage
Copy link
Collaborator

@epage epage commented Jan 24, 2025

To do this, we abstracted the design of ErrMode with ParserError and ModalError traits.

There might be a performance improvement when using ModalResult but definitely one when switching to Result:

$ cargo bench --bench arithmetic
   Compiling winnow v0.6.24 (/home/epage/src/personal/winnow)
    Finished `bench` profile [optimized + debuginfo] target(s) in 22.35s
     Running examples/arithmetic/bench.rs (target/release/deps/arithmetic-30e63a0cfdaed89e)
Gnuplot not found, using plotters backend
direct                  time:   [346.35 ns 347.73 ns 349.06 ns]
                        change: [-17.115% -16.596% -16.100%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

ast                     time:   [1.5312 µs 1.5389 µs 1.5478 µs]
                        change: [-7.3692% -6.9226% -6.4734%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  3 (3.00%) high mild
  4 (4.00%) high severe

lexer                   time:   [1.6899 µs 1.6951 µs 1.7003 µs]
                        change: [-18.013% -17.094% -16.141%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe

This is also being done to help with cases like #693

BREAKING CHANGE: Added more E: ParserError trait bounds

BREAKING CHANGE: Some error types may need to be wrapped in ErrMode

BREAKING CHANGE: Annotations for ErrMode need to be added when manually inspecting the ModalResult of a parser

BREAKING CHANGE: Parser<I, O, E> bounds need to be updated to Parser<I, O, ErrMode<E>> or ModalParser<I, O, E>

BREAKING CHANGE: ErrMode functions moved to ParserError and ModalError traits

Fixes #75

@epage epage marked this pull request as draft January 24, 2025 15:44
src/_topic/nom.rs Fixed Show fixed Hide fixed
src/_topic/nom.rs Fixed Show fixed Hide fixed
src/_tutorial/chapter_6.rs Fixed Show fixed Hide fixed
src/_tutorial/chapter_6.rs Fixed Show fixed Hide fixed
src/stream/mod.rs Fixed Show fixed Hide fixed
src/stream/mod.rs Fixed Show fixed Hide fixed
@coveralls
Copy link

coveralls commented Jan 24, 2025

Pull Request Test Coverage Report for Build 12953800605

Details

  • 129 of 296 (43.58%) changed or added relevant lines in 14 files are covered.
  • 16 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.4%) to 40.691%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/binary/mod.rs 20 21 95.24%
src/combinator/core.rs 8 10 80.0%
src/combinator/debug/internals.rs 0 5 0.0%
src/stream/mod.rs 0 5 0.0%
src/ascii/mod.rs 13 20 65.0%
src/binary/bits/mod.rs 8 16 50.0%
src/combinator/branch.rs 12 20 60.0%
src/token/mod.rs 18 28 64.29%
src/parser.rs 2 16 12.5%
src/combinator/impls.rs 14 33 42.42%
Files with Coverage Reduction New Missed Lines %
src/parser.rs 3 40.49%
src/error.rs 5 22.65%
src/stream/mod.rs 8 24.67%
Totals Coverage Status
Change from base Build 12934277890: 0.4%
Covered Lines: 1296
Relevant Lines: 3185

💛 - Coveralls

@epage epage marked this pull request as ready for review January 24, 2025 16:07
@epage
Copy link
Collaborator Author

epage commented Jan 24, 2025

typos ported over without a change

@epage epage force-pushed the modal branch 3 times, most recently from 7be6836 to 1550ff3 Compare January 24, 2025 16:42
@epage epage merged commit 8876c0a into winnow-rs:main Jan 24, 2025
15 of 16 checks passed
@epage epage deleted the modal branch January 24, 2025 17:13
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.

Give control over backtracking or not
2 participants