This page is no longer maintained — Please continue to the home page at www.scala-lang.org

2.9.1 elidable not eliding

3 replies
Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.

Hi All,

I've tried to use elidable to cut some code out for 2.9.1 but be
present in a 2.8.1 cross build without joy, the code declaring the
elidable annotation is in one compilation cycle and the code using the
method is in another (sbt subproject and used within a for
comprehension).

Is it a known limitation that it cannot be used across jars (could
make sense) or from within for comprehensions on a flatMap method?
The current SI's and googling shows many small examples of it working
or having seemingly unrelated problems, but I'm coming up short for an
explanation for this.

In particular:

trait FlatMapIterator[+A] extends Iterator[A] { self =>
/** Lifted from 2.9.Xs flatMap */
@elidable(FINEST)
def flatMap[B]( f : A => TraversableOnce[B] )(implicit ev :
FlatMapIteratorDummy) : Iterator[B] = new FlatMapIterator[B] {
// obvious implementation lifiting
}
}

then using -Xelide-below FINER I'd expect that the method disappears
(for 2.9.1) and allows the normal flatMap and its type inferencing to
be used in a for comprehension (2.8.1 code must annotate the type for
the iterator, but that's acceptable).

Cheers,
Chris

paulbutcher
Joined: 2010-03-08,
User offline. Last seen 10 weeks 5 days ago.
Re: 2.9.1 elidable not eliding

On 15 Dec 2011, at 10:06, Chris Twiner wrote:
> I've tried to use elidable to cut some code out for 2.9.1 but be
> present in a 2.8.1 cross build without joy

This isn't an answer to your question, but if you need to find another way to achieve the same effect, you might like to steal what I put together for ScalaMock.

I had a couple of problems that I needed to solve, that elidable couldn't solve (because elidable still requires that code compiles, even if it's subsequently removed). I needed to:

- cope with the fact that StaticAnnotation has moved packages between 2.8.x and 2.9.x

- avoid compiling and running a test which fails in Scala 2.9.1 due to a compiler bug.

The first, I solved by creating a version-specific source directory, so 2.8.x source goes in one, 2.9.x in the other:

> lazy val versionSpecificDirectory = SettingKey[File]("version-specific-directory", "Version specific source code")
>
> lazy val versionSpecificSettings = Seq(
> versionSpecificDirectory <<= (sourceDirectory, scalaVersion)((d, v) => d / "main" / ("scala-"+ majorVersion(v))),
> sources in Compile <++= collectSource(versionSpecificDirectory)
> )
>
> lazy val core = Project("core", file("core")) settings(versionSpecificSettings: _*)
>
> def majorVersion(scalaVersion: String) = if (scalaVersion startsWith "2.8") "2.8" else "2.9"

The second, I solved by filtering out source files that ended with "_not_2.9.1.scala":

> excludeFilter in unmanagedSources <<= scalaVersion( v => if (v == "2.9.1") "*_not_2.9.1.scala" else "")

The whole thing is here:

https://github.com/paulbutcher/ScalaMock

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: paul [at] paulbutcher [dot] com
AIM: paulrabutcher
Skype: paulrabutcher

Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: 2.9.1 elidable not eliding

thanks Paul, that was next on my list to try out, and now I've got a
usable solution to crib from, many thanks.

On Thu, Dec 15, 2011 at 11:39 AM, Paul Butcher wrote:
> On 15 Dec 2011, at 10:06, Chris Twiner wrote:
>> I've tried to use elidable to cut some code out for 2.9.1 but be
>> present in a 2.8.1 cross build without joy
>
> This isn't an answer to your question, but if you need to find another way to achieve the same effect, you might like to steal what I put together for ScalaMock.
>
> I had a couple of problems that I needed to solve, that elidable couldn't solve (because elidable still requires that code compiles, even if it's subsequently removed). I needed to:
>
> - cope with the fact that StaticAnnotation has moved packages between 2.8.x and 2.9.x
>
> - avoid compiling and running a test which fails in Scala 2.9.1 due to a compiler bug.
>
> The first, I solved by creating a version-specific source directory, so 2.8.x source goes in one, 2.9.x in the other:
>
>>   lazy val versionSpecificDirectory = SettingKey[File]("version-specific-directory", "Version specific source code")
>>
>>   lazy val versionSpecificSettings = Seq(
>>     versionSpecificDirectory <<= (sourceDirectory, scalaVersion)((d, v) => d / "main" / ("scala-"+ majorVersion(v))),
>>     sources in Compile <++= collectSource(versionSpecificDirectory)
>>   )
>>
>>   lazy val core = Project("core", file("core")) settings(versionSpecificSettings: _*)
>>
>>   def majorVersion(scalaVersion: String) = if (scalaVersion startsWith "2.8") "2.8" else "2.9"
>
> The second, I solved by filtering out source files that ended with "_not_2.9.1.scala":
>
>>       excludeFilter in unmanagedSources <<= scalaVersion( v => if (v == "2.9.1") "*_not_2.9.1.scala" else "")
>
>
> The whole thing is here:
>
> https://github.com/paulbutcher/ScalaMock
>
> --
> paul.butcher->msgCount++
>
> Snetterton, Castle Combe, Cadwell Park...
> Who says I have a one track mind?
>
> http://www.paulbutcher.com/
> LinkedIn: http://www.linkedin.com/in/paulbutcher
> MSN: paul [at] paulbutcher [dot] com
> AIM: paulrabutcher
> Skype: paulrabutcher
>

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: 2.9.1 elidable not eliding
On 15 Dec 2011, at 10:06, Chris Twiner wrote:
> I've tried to use elidable to cut some code out for 2.9.1 but be
> present in a 2.8.1 cross build without joy

This isn't an answer to your question, but if you need to find another way to achieve the same effect, you might like to steal what I put together for ScalaMock.

I had a couple of problems that I needed to solve, that elidable couldn't solve (because elidable still requires that code compiles, even if it's subsequently removed). I needed to:

- cope with the fact that StaticAnnotation has moved packages between 2.8.x and 2.9.x

- avoid compiling and running a test which fails in Scala 2.9.1 due to a compiler bug.

The first, I solved by creating a version-specific source directory, so 2.8.x source goes in one, 2.9.x in the other:

>   lazy val versionSpecificDirectory = SettingKey[File]("version-specific-directory", "Version specific source code")
>
>   lazy val versionSpecificSettings = Seq(
>     versionSpecificDirectory <<= (sourceDirectory, scalaVersion)((d, v) => d / "main" / ("scala-"+ majorVersion(v))),
>     sources in Compile <++= collectSource(versionSpecificDirectory)
>   )
>
>   lazy val core = Project("core", file("core")) settings(versionSpecificSettings: _*)
>
>   def majorVersion(scalaVersion: String) = if (scalaVersion startsWith "2.8") "2.8" else "2.9"

The second, I solved by filtering out source files that ended with "_not_2.9.1.scala":

>       excludeFilter in unmanagedSources <<= scalaVersion( v => if (v == "2.9.1") "*_not_2.9.1.scala" else "")


The whole thing is here:

https://github.com/paulbutcher/ScalaMock

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: paul [at] paulbutcher [dot] com
AIM: paulrabutcher
Skype: paulrabutcher


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland