gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.22k stars 146 forks source link

`record!` macro reaches recursion limit #763

Open lePerdu opened 5 years ago

lePerdu commented 5 years ago

Having more than 29 fields in the record! macro gives this error:

error: recursion limit reached while expanding the macro `stringify`
...
   = help: consider adding a `#![recursion_limit="128"]` attribute to your crate

Increasing the recursion limit as suggested by the compiler makes the error go away, but I assume the macro can be re-written in a non-recursive way to avoid this (I'm not well-versed in rust macros, though, so maybe not). On one hand though, having more than 29 fields is probably a good indication that it's time to split up modules, so maybe this should just stay as it is :).

Code Example

record! {
    value1 => 1,
    value2 => 2,
    value3 => 3,
    value4 => 4,
    value5 => 5,
    value6 => 6,
    value7 => 7,
    value8 => 8,
    value9 => 9,
    value10 => 10,
    value11 => 11,
    value12 => 12,
    value13 => 13,
    value14 => 14,
    value15 => 15,
    value16 => 16,
    value17 => 17,
    value18 => 18,
    value19 => 19,
    value20 => 20,
    value21 => 21,
    value22 => 22,
    value23 => 23,
    value24 => 24,
    value25 => 25,
    value26 => 26,
    value27 => 27,
    value28 => 28,
    value29 => 29,
    value30 => 30, // Having this triggers the error
}
Marwes commented 5 years ago

Would be nice but might be hard to improve much. It is written as a "tt-muncher" https://danielkeep.github.io/tlborm/book/pat-incremental-tt-munchers.html and I don't think that can be avoided :(