Can rust compiler handle gigantic match statements?

115 points baehyunsol 59 comments

I'm making a hobbyist programming language. Currently it uses a bytecode interpreter, but I want to translate the bytecode to C or Rust.

There're no functions in my bytecode. There are only jumps and stack push/pops. My language heavily uses tail calls (it's necessary because it's purely functional) and I put a lot of effort in the bytecode optimization.

So, if I translate the bytecode to C, there would be a gigantic main function with a lot of goto labels. If I choose Rust, I'll use a single gigantic match statement to simulate jumps (I can't think of better solution). There will be at least thousands of match arms and some times hundreds of thousands of arms.

I haven't written such ridiculous rust code by hand. Can the rust compiler handle such thing? Has anyone tried similar approach?

EDIT: fix typo