Skip to content

Commit 9d254a3

Browse files
authored
Merge pull request #1158 from joroKr21/jar-size
Reduce 2.12 / 2.13 Jar size by using instance constructors
2 parents a56beb7 + 8466a25 commit 9d254a3

File tree

7 files changed

+216
-287
lines changed

7 files changed

+216
-287
lines changed

build.sbt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.typesafe.sbt.SbtGit.GitKeys._
2-
import com.typesafe.tools.mima.core.ProblemFilters._
32
import com.typesafe.tools.mima.core._
43
import sbtcrossproject.CrossPlugin.autoImport.crossProject
54
import sbtcrossproject.CrossProject
@@ -97,8 +96,8 @@ lazy val commonSettings = Seq(
9796

9897
scalacOptions := scalacOptionsAll,
9998
Compile / compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
100-
case Some((2, y)) if y == 12 => scalacOptions212
101-
case Some((2, y)) if y >= 13 => scalacOptions213
99+
case Some((2, 12)) => scalacOptions212
100+
case Some((2, 13)) => scalacOptions213
102101
case _ => Nil
103102
}),
104103

core/src/main/scala/shapeless/lazy.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class LazyMacros(val c: whitebox.Context) extends CaseClassMacros with OpenImpli
344344
name: String,
345345
dict: ListMap[TypeWrapper, Instance],
346346
open: List[Instance],
347-
/** Types whose derivation must fail no matter what */
347+
// Types whose derivation must fail no matter what
348348
prevent: List[TypeWrapper]
349349
) {
350350
def addDependency(tpe: Type): State = {

core/src/main/scala/shapeless/ops/functions.scala

+12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ object function {
3030
}
3131

3232
object FnToProduct extends FnToProductInstances {
33+
type Aux[F, P] = FnToProduct[F] { type Out = P }
3334
def apply[F <: AnyRef](implicit fntop: FnToProduct[F]): Aux[F, fntop.Out] = fntop
35+
36+
private[shapeless] def instance[F, P](toProduct: F => P): Aux[F, P] = new FnToProduct[F] {
37+
type Out = P
38+
def apply(f: F) = toProduct(f)
39+
}
3440
}
3541

3642
/**
@@ -41,6 +47,12 @@ object function {
4147
trait FnFromProduct[F] extends DepFn1[F] with Serializable
4248

4349
object FnFromProduct extends FnFromProductInstances {
50+
type Aux[F, O] = FnFromProduct[F] { type Out = O }
4451
def apply[F](implicit fnfromp: FnFromProduct[F]): Aux[F, fnfromp.Out] = fnfromp
52+
53+
private[shapeless] def instance[P, F](fromProduct: P => F): Aux[P, F] = new FnFromProduct[P] {
54+
type Out = F
55+
def apply(f: P) = fromProduct(f)
56+
}
4557
}
4658
}

core/src/main/scala/shapeless/ops/hlists.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,16 @@ object hlist {
771771
trait Tupler[L <: HList] extends DepFn1[L] with Serializable
772772

773773
object Tupler extends TuplerInstances {
774+
type Aux[L <: HList, T] = Tupler[L] { type Out = T }
774775
def apply[L <: HList](implicit tupler: Tupler[L]): Aux[L, tupler.Out] = tupler
775776

777+
private[shapeless] def instance[L <: HList, T](tuple: L => T): Aux[L, T] = new Tupler[L] {
778+
type Out = T
779+
def apply(l: L) = tuple(l)
780+
}
781+
776782
implicit val hnilTupler: Aux[HNil, Unit] =
777-
new Tupler[HNil] {
778-
type Out = Unit
779-
def apply(l: HNil): Out = ()
780-
}
783+
instance(_ => ())
781784
}
782785

783786
/**

core/src/main/scala/shapeless/sized.scala

+11-8
Original file line numberDiff line numberDiff line change
@@ -212,29 +212,32 @@ object AdditiveCollection extends AdditiveCollectionVersionSpecific {
212212
import scala.collection.immutable.Queue
213213
import scala.collection.LinearSeq
214214

215+
private[this] val instance =
216+
new AdditiveCollection[Any] {}
217+
215218
implicit def linearSeqAdditiveCollection[T]: AdditiveCollection[LinearSeq[T]] =
216-
new AdditiveCollection[LinearSeq[T]] {}
219+
instance.asInstanceOf[AdditiveCollection[LinearSeq[T]]]
217220

218221
implicit def vectorAdditiveCollection[T]: AdditiveCollection[Vector[T]] =
219-
new AdditiveCollection[Vector[T]] {}
222+
instance.asInstanceOf[AdditiveCollection[Vector[T]]]
220223

221224
implicit def arrayAdditiveCollection[T]: AdditiveCollection[Array[T]] =
222-
new AdditiveCollection[Array[T]] {}
225+
instance.asInstanceOf[AdditiveCollection[Array[T]]]
223226

224227
implicit def stringAdditiveCollection: AdditiveCollection[String] =
225-
new AdditiveCollection[String] {}
228+
instance.asInstanceOf[AdditiveCollection[String]]
226229

227230
implicit def listAdditiveCollection[T]: AdditiveCollection[List[T]] =
228-
new AdditiveCollection[List[T]] {}
231+
instance.asInstanceOf[AdditiveCollection[List[T]]]
229232

230233
implicit def streamAdditiveCollection[T]: AdditiveCollection[LazyList[T]] =
231-
new AdditiveCollection[LazyList[T]] {}
234+
instance.asInstanceOf[AdditiveCollection[LazyList[T]]]
232235

233236
implicit def queueAdditiveCollection[T]: AdditiveCollection[Queue[T]] =
234-
new AdditiveCollection[Queue[T]] {}
237+
instance.asInstanceOf[AdditiveCollection[Queue[T]]]
235238

236239
implicit def defaultAdditiveCollection[T]: AdditiveCollection[collection.immutable.IndexedSeq[T]] =
237-
new AdditiveCollection[collection.immutable.IndexedSeq[T]] {}
240+
instance.asInstanceOf[AdditiveCollection[collection.immutable.IndexedSeq[T]]]
238241
}
239242

240243
class DefaultToIndexedSeq[CC[_]]

0 commit comments

Comments
 (0)