Two Scala annotations

bearophile bearophileHUGS at lycos.com
Sun May 27 07:47:13 PDT 2012


Alex Rønne Petersen:

> 1) Any half-decent compiler *will* optimize this thanks to a 
> wide array of standard dataflow analyses.

'y' was meant to be a value unknown at compile-time.


> I don't know from where people got this crazy idea that a 
> switch statement MUST compile to a jump table *no matter what*

I'd like portable computed gotos in D, but they are not coming 
soon in DMD, it seems.


> If someone is aware of the jump table optimization of switch 
> statements, then surely they know that using a runtime value 
> will kill that optimization.

That annotation doesn't introduce compiler optimizations (the 
compiler will optimize as much as possible in every cases). It 
just gives a compile-time error if you use a run-time value in a 
switch case. It's just meant to avoid mistakes, like using a 
run-time value instead of a D enum in a switch case, just like 
that Scala annotation.

Bye,
bearophile


More information about the Digitalmars-d mailing list