Skip to content

Enum ordinals -> tableswitch #5537

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

Open
tpolecat opened this issue Nov 28, 2018 · 8 comments
Open

Enum ordinals -> tableswitch #5537

tpolecat opened this issue Nov 28, 2018 · 8 comments

Comments

@tpolecat
Copy link

Just following up on a conversation @odersky and I had at SBTB … I was wondering if we could use enum ordinals to emit tableswitches for eligible match expressions. I have had cases where I had to reorder cases as a performance optimization and something like this would have been really helpful.

@smarter
Copy link
Member

smarter commented Nov 29, 2018

We don't necessarily need to do the same, but for reference here's how Java does it: http://www.benf.org/other/cfr/switch-on-enum.html, it's complicated because it's designed to survive reordering and addition of fields to the enum.

@He-Pin
Copy link
Contributor

He-Pin commented Dec 1, 2018

@smarter
Copy link
Member

smarter commented Dec 2, 2018

@hepin1989 without benchmark results you won't convince us that it's a "must done"

@He-Pin
Copy link
Contributor

He-Pin commented Dec 2, 2018

Same patterns in scala future,zio, etc

@bishabosha
Copy link
Member

and we can't rely on mima because definitions are order sensitive

@nmichael44
Copy link

There is some discussion this issue that may help whoever picks this up in the now closed-as-duplicate ticket: #23314

@som-snytt
Copy link
Contributor

Even Kotlin does this.

Most damning of all.

@som-snytt som-snytt self-assigned this Jun 10, 2025
@nmichael44
Copy link

@som-snytt 😃 I didn't really mean it as a slight for the Kotlyn compiler. I just meant, it's a newer language so you wouldn't expect the compiler to be that mature and contain this kinds of optimizations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants