dragos / noboxing-plugin

A Scala compiler plugin that issues warnings when boxing occurs.
10 stars 2 forks source link

Better handling of higher-order functions #1

Open dragos opened 13 years ago

dragos commented 13 years ago

Function literals may confuse the plugin. For instance,

  val xs = List(1, 2, 3)
  xs map (x => x)

is translated to

  val xs = List(1, 2, 3)
  xs map (new anonfun extends AbstractFunction1$II {
    def apply(x: Object) = apply(x.toInt) // boxing
    def apply(x: Int) = x
  })

but, if map is specialized, no boxing will occur (the apply(Object) overload is never called).

dragos commented 13 years ago

Maybe suppress warnings when the closure is passed to a specialized method. More generally, for an application where the method is specialized and the argument is a a (matching) specialized instance, ignore generic forwarders.

magicgoose commented 11 years ago

I think the problem must be detected at runtime... One silly way is simply add a logging with stack trace in constructors of every primitive wrapper classes. Because is is not so easy to track whick methods of specialized classes will really be called. Correct me, if I'm wrong.