You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive(Logos)]#[logos(source = [u8])]enumToken{// NOTE: This is needed because logos has dot_matches_newline(false) set for regex_syntax (which is the default)#[token("\n")]Newline,#[regex(b".", priority = 0)]UnknownByte,}
And this lexer should be impossible to error from so I use the error type enum LexerError {} which will cause a linker error in release mode like so
implDefaultforLexerError{#[cfg(not(debug_assertions))]fndefault() -> Self{extern"C"{fn__lexer_error_unreachable_default() -> !;}// force a linker errorunsafe{__lexer_error_unreachable_default()}}#[cfg(debug_assertions)]fndefault() -> Self{panic!("It is impossible for the lexer to error")}}
This would work if the LUT didn't generate the error branch. And for some reason LLVM is unable to optimize out this branch. I suspect it's because the LUT is stored in a static, which tends to be an optimization barrier.
To fix this, the error branch simply shouldn't be generated if it is unreachable.
The text was updated successfully, but these errors were encountered:
I have some code like this:
And this lexer should be impossible to error from so I use the error type
enum LexerError {}
which will cause a linker error in release mode like soThis would work if the LUT didn't generate the error branch. And for some reason LLVM is unable to optimize out this branch. I suspect it's because the LUT is stored in a
static
, which tends to be an optimization barrier.To fix this, the error branch simply shouldn't be generated if it is unreachable.
The text was updated successfully, but these errors were encountered: