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

proc-macro derive panicked message: attempt to subtract with overflow #389

Closed
UnexDev opened this issue Apr 30, 2024 · 3 comments · Fixed by #405
Closed

proc-macro derive panicked message: attempt to subtract with overflow #389

UnexDev opened this issue Apr 30, 2024 · 3 comments · Fixed by #405

Comments

@UnexDev
Copy link

UnexDev commented Apr 30, 2024

I'm converting a YACC grammar file to a Logos lexer, and I'm getting this strange and very unhelpful error message. Every macro-debug process I have tried has literally yielded no additional output.

(All of the RegExps are not complete; I am going to find-and-replace all of the reocurring works like 'skip' and 'StringLiteralSingle')


#[derive(Debug, Logos)]
pub enum TokenKind {
    #[token("&")]
    Ampersand,
    #[token("&=")]
    AmpersandEqual,
    #[token("*")]
    Asterisk,
    #[token("**")]
    AsteriskAsterisk,
    #[token("*=")]
    AsteriskEqual,
    #[token("*%")]
    AsteriskPercent,
    #[token("*%=")]
    AsteriskPercentEqual,
    #[token("*|")]
    AsteriskPipe,
    #[token("*|=")]
    AsteriskPipeEqual,
    #[token("^")]
    Caret,
    #[token("^=")]
    CaretEqual,
    #[token(":")]
    Colon,
    #[token(",")]
    Comma,
    #[token(".")]
    Dot,
    #[token("..")]
    DotDot,
    #[token("...")]
    DotDotDot,
    #[token(".*")]
    DotAsterisk,
    #[token("=")]
    Equal,
    #[token("==")]
    EqualEqual,
    #[token("=>")]
    EqualRarrow,
    #[token("!")]
    Exclemation,
    #[token("!=")]
    ExclamationEqual,
    #[token("<")]
    LArrow,
    #[token("<<")]
    LArrowLArrow,
    #[token("<<=")]
    LArrowLArrowEqual,
    #[token("<<|")]
    LArrowLArrowPipe,
    #[token("<=")]
    LArrowEqual,
    #[token("{")]
    LBrace,
    #[token("[")]
    LBracket,
    #[token("(")]
    LParen,
    #[token("-")]
    Minus,
    #[token("-=")]
    MunisEqual,
    #[token("-%")]
    MinusPercent,
    #[token("-%=")]
    MinusPercentEqual,
    #[token("-|")]
    MinusPipe,
    #[token("->")]
    MinusRarrow,
    #[token("%")]
    Percent,
    #[token("%=")]
    PercentEqual,
    #[token("+")]
    Plus,
    #[token("++")]
    PlusPlus,
    #[token("+=")]
    PlusEqual,
    #[token("+%")]
    PlusPercent,
    #[token("+%=")]
    PlusPercentEqual,
    #[token("+|")]
    PlusPipe,
    #[token("+|=")]
    PlusPipeEqual,
    #[token("c", priority = 3)]
    LetterC,
    #[token("?")]
    QuestionMark,
    #[token(">")]
    RArrow,
    #[token(">>")]
    RArrowRArrow,
    #[token(">>=")]
    RArrowRArrowEqual,
    #[token("}")]
    RBrace,
    #[token("]")]
    RBracket,
    #[token(")")]
    RParen,
    #[token(";")]
    Semicolon,
    #[token("/")]
    Slash,
    #[token("/=")]
    SlashEqual,
    #[token("~")]
    Tilde,

    #[token("addrspace")]
    AddrspaceKw,
    #[token("align")]
    AlignKw,
    #[token("allowzero")]
    AllowzeroKw,
    #[token("and")]
    AndKw,
    #[token("anyframe")]
    AnyframeKw,
    #[token("anytype")]
    AnytypeKw,
    #[token("asm")]
    AsmKw,
    #[token("async")]
    AsyncKw,
    #[token("await")]
    AwaitKw,
    #[token("break")]
    BreakKw,
    #[token("callconv")]
    CallconvKw,
    #[token("catch")]
    CatchKw,
    #[token("comptime")]
    ComptimeKw,
    #[token("const")]
    ConstKw,
    #[token("continue")]
    ContinueKw,
    #[token("defer")]
    DeferKw,
    #[token("else")]
    ElseKw,
    #[token("enum")]
    EnumKw,
    #[token("errdefer")]
    ErrdeferKw,
    #[token("error")]
    ErrorKw,
    #[token("export")]
    ExportKw,
    #[token("extern")]
    ExternKw,
    #[token("fn")]
    FnKw,
    #[token("for")]
    ForKw,
    #[token("if")]
    IfKw,
    #[token("inline")]
    InlineKw,
    #[token("noalias")]
    NoaliasKw,
    #[token("nosuspend")]
    NosuspendKw,
    #[token("noinline")]
    NoinlineKw,
    #[token("opaque")]
    OpaqueKw,
    #[token("or")]
    OrKw,
    #[token("orelse")]
    OrelseKw,
    #[token("packed")]
    PackedKw,
    #[token("pub")]
    PubKw,
    #[token("resume")]
    ResumeKw,
    #[token("return")]
    ReturnKw,
    #[token("linksection")]
    LinksectionKw,
    #[token("struct")]
    StructKw,
    #[token("suspend")]
    SuspendKw,
    #[token("switch")]
    SwitchKw,
    #[token("test")]
    TestKw,
    #[token("threadlocal")]
    ThreadlocalKw,
    #[token("try")]
    TryKw,
    #[token("union")]
    UnionKw,
    #[token("unreachable")]
    UnreachableKw,
    #[token("usingnamespace")]
    UsingnamespaceKw,
    #[token("var")]
    VarKw,
    #[token("volatile")]
    VolatileKw,
    #[token("while")]
    WhileKw,

    #[regex("'char_char'")]
    CharLiteral,

    #[regex("0xhex_int.hex_int([pP][-+]?dec_int)?")]
    Float,

    #[regex("0bbin_intskip|0ooct_intskip|0xhex_intskip|dec_intskip")]
    Integer,

    #[regex("\"string_char*\"skip")]
    StringLiteralSingle,

    #[regex("__StringLiteralSingle__|(?:line_stringskip)+")]
    StringLiteral,

    #[regex("(?:[A-Za-z_][A-Za-z0-9_]*skip)|@__StringLiteralSingle__")]
    Identifier,

    #[regex("@[A-Za-z_][A-Za-z0-9_]*skip")]
    BuiltinIdentifier,
}
@jeertmans
Copy link
Collaborator

Hello @UnexDev, can you please provide the error message too?

the faulty line is probably showed in there :)

@UnexDev
Copy link
Author

UnexDev commented Apr 30, 2024

I do think I found the error. It's an enum length problem. When I comment out every line until the error goes away it compiles just fine. When I uncomment one line, it errors. The enum is too long I believe.

Hello @UnexDev, can you please provide the error message too?

the faulty line is probably showed in there :)

I omitted irrelevant details before, but here is the full error message.

  --> crates\parser\src\lexer.rs:41:49
   |
41 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Logos)]
   |                                                 ^^^^^
   |
   = help: message: attempt to subtract with overflow

error: could not compile `parser` (lib) due to 1 previous error

@LeoDog896
Copy link
Contributor

The problem seems to be an excessive amount of tokens combined with a repeating operator present somewhere in the string:

#[derive(Debug, Logos)]
pub enum TokenKind {
    #[regex("aaaaaaaaaaaaaa*")]
    SmallLiteral,
}

LeoDog896 added a commit to LeoDog896/logos that referenced this issue Jul 24, 2024
LeoDog896 added a commit to LeoDog896/logos that referenced this issue Jul 24, 2024
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.

3 participants