From 07f1292e290f35153fb91dad3324e7bdb9cd827a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 30 Jan 2025 13:54:49 -0600 Subject: [PATCH 1/5] chore: Upgrade to Winnow 0.6.26 --- Cargo.lock | 4 ++-- crates/typos/Cargo.toml | 2 +- crates/varcon-core/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7374554..06bc745 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1917,9 +1917,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.21" +version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f5bb5257f2407a5425c6e749bfd9692192a73e70a6060516ac04f889087d68" +checksum = "1e90edd2ac1aa278a5c4599b1d89cf03074b610800f866d4026dc199d7929a28" dependencies = [ "memchr", ] diff --git a/crates/typos/Cargo.toml b/crates/typos/Cargo.toml index 727fb54..fd81c29 100644 --- a/crates/typos/Cargo.toml +++ b/crates/typos/Cargo.toml @@ -16,7 +16,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] [dependencies] -winnow = "0.6.7" +winnow = "0.6.26" unicode-xid = "0.2.4" serde = { version = "1.0", features = ["derive"] } simdutf8 = "0.1.4" diff --git a/crates/varcon-core/Cargo.toml b/crates/varcon-core/Cargo.toml index a345878..e842a66 100644 --- a/crates/varcon-core/Cargo.toml +++ b/crates/varcon-core/Cargo.toml @@ -20,7 +20,7 @@ parser = ["dep:winnow"] flags = ["dep:enumflags2"] [dependencies] -winnow = { version = "0.6.7", optional = true } +winnow = { version = "0.6.26", optional = true } enumflags2 = { version = "0.7", optional = true } [lints] From 7830eb8730de84bf14bc14cadb996c0e52f9fe93 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 30 Jan 2025 13:55:32 -0600 Subject: [PATCH 2/5] refactor: Resolve deprecations --- crates/typos/src/tokens.rs | 41 +++++++++++++++----------------- crates/varcon-core/src/parser.rs | 24 +++++++++---------- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index fc3f42b..c5d5366 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -145,7 +145,7 @@ mod parser { /// later may cause it to fail. const NON_TERMINATING_CAP: usize = 1024; - pub(crate) fn next_identifier(input: &mut T) -> PResult<::Slice, ()> + pub(crate) fn next_identifier(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -155,7 +155,7 @@ mod parser { preceded(ignore, identifier).parse_next(input) } - fn identifier(input: &mut T) -> PResult<::Slice, ()> + fn identifier(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -173,7 +173,7 @@ mod parser { .parse_next(input) } - fn ignore(input: &mut T) -> PResult<::Slice, ()> + fn ignore(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -204,7 +204,7 @@ mod parser { .parse_next(input) } - fn sep1(input: &mut T) -> PResult<::Slice, ()> + fn sep1(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -217,7 +217,7 @@ mod parser { .parse_next(input) } - fn other(input: &mut T) -> PResult<::Slice, ()> + fn other(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -234,7 +234,7 @@ mod parser { .parse_next(input) } - fn ordinal_literal(input: &mut T) -> PResult<::Slice, ()> + fn ordinal_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -260,7 +260,7 @@ mod parser { .parse_next(input) } - fn dec_literal(input: &mut T) -> PResult<::Slice, ()> + fn dec_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -269,7 +269,7 @@ mod parser { trace("dec_literal", take_while(1.., is_dec_digit_with_sep)).parse_next(input) } - fn hex_literal(input: &mut T) -> PResult<::Slice, ()> + fn hex_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -281,7 +281,7 @@ mod parser { .parse_next(input) } - fn css_color(input: &mut T) -> PResult<::Slice, ()> + fn css_color(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -302,7 +302,7 @@ mod parser { .parse_next(input) } - fn jwt(input: &mut T) -> PResult<::Slice, ()> + fn jwt(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -337,7 +337,7 @@ mod parser { || c == '-' } - fn uuid_literal(input: &mut T) -> PResult<::Slice, ()> + fn uuid_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -375,7 +375,7 @@ mod parser { .parse_next(input) } - fn hash_literal(input: &mut T) -> PResult<::Slice, ()> + fn hash_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -401,7 +401,7 @@ mod parser { .parse_next(input) } - fn base64_literal(input: &mut T) -> PResult<::Slice, ()> + fn base64_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -425,10 +425,7 @@ mod parser { .iter() .all(|c| !['/', '+'].contains(&c.as_char())) { - return Err(winnow::error::ErrMode::from_error_kind( - input, - winnow::error::ErrorKind::Slice, - )); + return Err(winnow::error::ErrMode::from_input(input)); } take_while(padding_len..=padding_len, is_base64_padding).parse_next(input)?; @@ -440,7 +437,7 @@ mod parser { .parse_next(input) } - fn email_literal(input: &mut T) -> PResult<::Slice, ()> + fn email_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -459,7 +456,7 @@ mod parser { .parse_next(input) } - fn url_literal(input: &mut T) -> PResult<::Slice, ()> + fn url_literal(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -492,7 +489,7 @@ mod parser { .parse_next(input) } - fn url_userinfo(input: &mut T) -> PResult<::Slice, ()> + fn url_userinfo(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -510,7 +507,7 @@ mod parser { .parse_next(input) } - fn c_escape(input: &mut T) -> PResult<::Slice, ()> + fn c_escape(input: &mut T) -> ModalResult<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -531,7 +528,7 @@ mod parser { .parse_next(input) } - fn printf(input: &mut T) -> PResult<::Slice, ()> + fn printf(input: &mut T) -> ModalResult<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, diff --git a/crates/varcon-core/src/parser.rs b/crates/varcon-core/src/parser.rs index adc6bea..8da9b7b 100644 --- a/crates/varcon-core/src/parser.rs +++ b/crates/varcon-core/src/parser.rs @@ -546,7 +546,7 @@ impl Cluster { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("cluster", move |input: &mut &str| { let header = ( "#", @@ -966,7 +966,7 @@ impl Entry { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("entry", move |input: &mut &str| { let var_sep = (winnow::ascii::space0, '/', winnow::ascii::space0); let variants = @@ -987,7 +987,7 @@ impl Entry { .parse_next(input) } - fn parse_description(input: &mut &str) -> PResult { + fn parse_description(input: &mut &str) -> ModalResult { trace("description", move |input: &mut &str| { let mut entry = Self { variants: Vec::new(), @@ -1023,18 +1023,18 @@ impl Entry { } } -fn note(input: &mut &str) -> PResult { +fn note(input: &mut &str) -> ModalResult { let (_, _, note) = (NOTE_PREFIX, space1, description).parse_next(input)?; Ok(note) } const NOTE_PREFIX: &str = "--"; -fn archaic(input: &mut &str) -> PResult<(), ()> { +fn archaic(input: &mut &str) -> ModalResult<(), ()> { "(-)".void().parse_next(input) } -fn description(input: &mut &str) -> PResult { +fn description(input: &mut &str) -> ModalResult { let description = winnow::token::take_till(0.., ('\n', '\r', '#', '|')).parse_next(input)?; Ok(description.to_owned()) } @@ -1573,7 +1573,7 @@ impl Variant { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("variant", move |input: &mut &str| { let types = winnow::combinator::separated(1.., Type::parse_, space1); let columns = @@ -1592,7 +1592,7 @@ impl Variant { } } -fn word(input: &mut &str) -> PResult { +fn word(input: &mut &str) -> ModalResult { trace("word", move |input: &mut &str| { winnow::token::take_till(1.., |item: char| item.is_ascii_whitespace()) .map(|s: &str| s.to_owned().replace('_', " ")) @@ -1734,7 +1734,7 @@ impl Type { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("type", move |input: &mut &str| { let category = Category::parse_(input)?; let tag = opt(Tag::parse_).parse_next(input)?; @@ -1850,7 +1850,7 @@ impl Category { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("category", move |input: &mut &str| { let symbols = one_of(['A', 'B', 'Z', 'C', 'D', '_']); symbols @@ -1909,7 +1909,7 @@ impl Tag { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("tag", move |input: &mut &str| { let symbols = one_of(['.', 'v', 'V', '-', 'x']); symbols @@ -1967,7 +1967,7 @@ impl Pos { Self::parse_.parse(input).map_err(|_err| ParseError) } - fn parse_(input: &mut &str) -> PResult { + fn parse_(input: &mut &str) -> ModalResult { trace("pos", move |input: &mut &str| { alt(( "N".value(Pos::Noun), From 4c22f194b5c24cf2b7d0524df0857f0f8bbc32a5 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 30 Jan 2025 15:02:50 -0600 Subject: [PATCH 3/5] refactor: Migrate from Parser to ModalParser --- crates/typos/src/tokens.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index c5d5366..f1054b7 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -538,10 +538,10 @@ mod parser { trace("printf", ('%', take_while(1.., is_xid_continue)).take()).parse_next(input) } - fn take_many0(mut f: F) -> impl Parser::Slice, E> + fn take_many0(mut f: F) -> impl ModalParser::Slice, E> where I: Stream, - F: Parser::Slice, E>, + F: ModalParser::Slice, E>, E: ParserError, { move |i: &mut I| repeat(0.., f.by_ref()).map(|()| ()).take().parse_next(i) From 60452b5a81caa4f70c81282f2cdd2116fc045f52 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 30 Jan 2025 15:03:16 -0600 Subject: [PATCH 4/5] chore: Update to Winnow 0.7 --- Cargo.lock | 15 ++++++++++++--- crates/typos/Cargo.toml | 2 +- crates/varcon-core/Cargo.toml | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06bc745..1914fdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1451,7 +1451,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.26", ] [[package]] @@ -1508,7 +1508,7 @@ dependencies = [ "simdutf8", "snapbox", "unicode-xid", - "winnow", + "winnow 0.7.0", ] [[package]] @@ -1702,7 +1702,7 @@ version = "5.0.1" dependencies = [ "enumflags2", "snapbox", - "winnow", + "winnow 0.7.0", ] [[package]] @@ -1924,6 +1924,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e49d2d35d3fad69b39b94139037ecfb4f359f08958b9c11e7315ce770462419" +dependencies = [ + "memchr", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/crates/typos/Cargo.toml b/crates/typos/Cargo.toml index fd81c29..7e8871c 100644 --- a/crates/typos/Cargo.toml +++ b/crates/typos/Cargo.toml @@ -16,7 +16,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] [dependencies] -winnow = "0.6.26" +winnow = "0.7.0" unicode-xid = "0.2.4" serde = { version = "1.0", features = ["derive"] } simdutf8 = "0.1.4" diff --git a/crates/varcon-core/Cargo.toml b/crates/varcon-core/Cargo.toml index e842a66..edcfeb2 100644 --- a/crates/varcon-core/Cargo.toml +++ b/crates/varcon-core/Cargo.toml @@ -20,7 +20,7 @@ parser = ["dep:winnow"] flags = ["dep:enumflags2"] [dependencies] -winnow = { version = "0.6.26", optional = true } +winnow = { version = "0.7.0", optional = true } enumflags2 = { version = "0.7", optional = true } [lints] From ba04a1a0fd67a0e00ad36c5c5655b9740ee5e68a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 30 Jan 2025 15:05:14 -0600 Subject: [PATCH 5/5] perf: Remove ErrMode overhead --- crates/typos/src/tokens.rs | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index f1054b7..e715bf9 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -140,12 +140,13 @@ mod parser { use winnow::stream::Stream; use winnow::stream::StreamIsPartial; use winnow::token::{one_of, take_while}; + use winnow::Result; /// Avoid worst-case parse times by limiting how much a `take_while` can take if something /// later may cause it to fail. const NON_TERMINATING_CAP: usize = 1024; - pub(crate) fn next_identifier(input: &mut T) -> ModalResult<::Slice, ()> + pub(crate) fn next_identifier(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -155,7 +156,7 @@ mod parser { preceded(ignore, identifier).parse_next(input) } - fn identifier(input: &mut T) -> ModalResult<::Slice, ()> + fn identifier(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -173,7 +174,7 @@ mod parser { .parse_next(input) } - fn ignore(input: &mut T) -> ModalResult<::Slice, ()> + fn ignore(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -204,7 +205,7 @@ mod parser { .parse_next(input) } - fn sep1(input: &mut T) -> ModalResult<::Slice, ()> + fn sep1(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -217,7 +218,7 @@ mod parser { .parse_next(input) } - fn other(input: &mut T) -> ModalResult<::Slice, ()> + fn other(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -234,7 +235,7 @@ mod parser { .parse_next(input) } - fn ordinal_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn ordinal_literal(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -260,7 +261,7 @@ mod parser { .parse_next(input) } - fn dec_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn dec_literal(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -269,7 +270,7 @@ mod parser { trace("dec_literal", take_while(1.., is_dec_digit_with_sep)).parse_next(input) } - fn hex_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn hex_literal(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -281,7 +282,7 @@ mod parser { .parse_next(input) } - fn css_color(input: &mut T) -> ModalResult<::Slice, ()> + fn css_color(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -302,7 +303,7 @@ mod parser { .parse_next(input) } - fn jwt(input: &mut T) -> ModalResult<::Slice, ()> + fn jwt(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -337,7 +338,7 @@ mod parser { || c == '-' } - fn uuid_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn uuid_literal(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -375,7 +376,7 @@ mod parser { .parse_next(input) } - fn hash_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn hash_literal(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -401,7 +402,7 @@ mod parser { .parse_next(input) } - fn base64_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn base64_literal(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -425,7 +426,8 @@ mod parser { .iter() .all(|c| !['/', '+'].contains(&c.as_char())) { - return Err(winnow::error::ErrMode::from_input(input)); + #[allow(clippy::unit_arg)] + return Err(ParserError::from_input(input)); } take_while(padding_len..=padding_len, is_base64_padding).parse_next(input)?; @@ -437,7 +439,7 @@ mod parser { .parse_next(input) } - fn email_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn email_literal(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -456,7 +458,7 @@ mod parser { .parse_next(input) } - fn url_literal(input: &mut T) -> ModalResult<::Slice, ()> + fn url_literal(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -489,7 +491,7 @@ mod parser { .parse_next(input) } - fn url_userinfo(input: &mut T) -> ModalResult<::Slice, ()> + fn url_userinfo(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -507,7 +509,7 @@ mod parser { .parse_next(input) } - fn c_escape(input: &mut T) -> ModalResult<::Slice, ()> + fn c_escape(input: &mut T) -> Result<::Slice, ()> where T: Stream + StreamIsPartial + PartialEq, ::Slice: AsBStr + SliceLen + Default, @@ -528,7 +530,7 @@ mod parser { .parse_next(input) } - fn printf(input: &mut T) -> ModalResult<::Slice, ()> + fn printf(input: &mut T) -> Result<::Slice, ()> where T: Compare, T: Stream + StreamIsPartial + PartialEq, @@ -538,10 +540,10 @@ mod parser { trace("printf", ('%', take_while(1.., is_xid_continue)).take()).parse_next(input) } - fn take_many0(mut f: F) -> impl ModalParser::Slice, E> + fn take_many0(mut f: F) -> impl Parser::Slice, E> where I: Stream, - F: ModalParser::Slice, E>, + F: Parser::Slice, E>, E: ParserError, { move |i: &mut I| repeat(0.., f.by_ref()).map(|()| ()).take().parse_next(i)