Two Scala annotations

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 30 19:53:23 PDT 2012


On Saturday, June 30, 2012 19:00:29 Walter Bright wrote:
> On 6/30/2012 6:05 PM, bearophile wrote:
> > Walter Bright:
> >> It's not a bug. It's deliberate, and is there to support mechanical
> >> translation of Java code.
> > 
> > Is this stuff written somewhere in a D design rationales page?
> > 
> > Now that D is several years old, how much Java code was ported to D?
> > (Despite there is no mechanical Java->D translator yet).
> 
> Yes, a mechanical translator was used extensively to create dwt.
> 
> > Was this automatic translation
> > desire worth the troubles (like inner classes,
> 
> Yes.
> 
> > like the risk of killing switch optimizations by mistake)?
> 
> Calling it a "risk" and "killing" is way, way overstating things.
> 
> > This post is about two Scala annotations. If that's not a bug, is
> > something like that first Scala annotation useful in D too?
> 
> I don't really see any problem requiring a solution. If you're working on
> optimizations at that level, you ought to be comfortable examining the asm
> output for that and all the other stuff, too. Setting a store on just one
> aspect of switch implementations is a large mistake.

I would have thought that while having a variable as a case value rather than 
a compile-time constant may make the switch statement less efficient, it would 
have zero effect on switch statements which didn't use any variables for their 
cases. That being the case, it would only impact people who choose to use 
variables in their case statements, and anyone who would have preferred to 
have the be disallowed is unaffected by it (unless they use code from someone 
who does use variables in their case statements), since they're not using it 
in their code.

Personally, I would have preferred that case statement values all be constant, 
but it sounds like we have a good, technical reason for allowing them, and I 
don't see how they could negatively affect me as long as I don't use them. 
Anyone who thinks that the compiler is doing a poor job of optimizing switch 
statements is free to work on the compiler and provide a pull request with 
their improvements.

- Jonathan M Davis


More information about the Digitalmars-d mailing list