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

Implement Chunk<'_> for slices larger than 32 #141

Closed
Luro02 opened this issue Apr 27, 2020 · 3 comments · Fixed by #221
Closed

Implement Chunk<'_> for slices larger than 32 #141

Luro02 opened this issue Apr 27, 2020 · 3 comments · Fixed by #221

Comments

@Luro02
Copy link
Contributor

Luro02 commented Apr 27, 2020

Currently regular expressions can not be larger than 32, because the trait logos::source::Chunk<'_> is not implemented for them:

use logos::Logos;

#[derive(Logos, Debug, Clone, PartialEq)]
pub enum TestLogos {
    #[regex(r"THIS IS A LONG REGEX STRING LONGER THAN 32")]
    Variant,
    #[error]
    Error,
}

fn main() {}
error[E0277]: the trait bound `&[u8; 41]: logos::source::Chunk<'_>` is not satisfied
 --> src/main.rs:3:10
  |
3 | #[derive(Logos, Debug, Clone, PartialEq)]
  |          ^^^^^ the trait `logos::source::Chunk<'_>` is not implemented for `&[u8; 41]`
  |
  = help: the following implementations were found:
            <&'source [u8; 10] as logos::source::Chunk<'source>>
            <&'source [u8; 11] as logos::source::Chunk<'source>>
            <&'source [u8; 12] as logos::source::Chunk<'source>>
            <&'source [u8; 13] as logos::source::Chunk<'source>>
          and 12 others
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `&[u8; 42]: logos::source::Chunk<'_>` is not satisfied
 --> src/main.rs:3:10
  |
3 | #[derive(Logos, Debug, Clone, PartialEq)]
  |          ^^^^^ the trait `logos::source::Chunk<'_>` is not implemented for `&[u8; 42]`
  |
  = help: the following implementations were found:
            <&'source [u8; 10] as logos::source::Chunk<'source>>
            <&'source [u8; 11] as logos::source::Chunk<'source>>
            <&'source [u8; 12] as logos::source::Chunk<'source>>
            <&'source [u8; 13] as logos::source::Chunk<'source>>
          and 12 others
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
error: could not compile `logos_fail`.

To learn more, run the command again with --verbose.

This is blocked on the stabilization of rust-lang/rust#44580

@Luro02

This comment has been minimized.

@Luro02

This comment has been minimized.

@Luro02 Luro02 changed the title the trait bound &[u8; 27]: Chunk<'_> is not satisfied Implement Chunk<'_> for slices larger than 32 Apr 27, 2020
@maciejhirsz
Copy link
Owner

For chunks > 32, the Chunk trait could expose it's own eq method that calls self[..].eq(&other[..]). I don't know if there are any optimizations done on array equality that this would block, or somehow make LLVM confused and disable optimizations here. I'm pretty sure it's fine, but it would be worth to check the asm this produces.

maciejhirsz pushed a commit that referenced this issue Jun 8, 2022
with min-const-generics stable we can implement `Chunk` for all sizes and not just up to 32

fixes #141
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 a pull request may close this issue.

2 participants