Skip to content

Commit

Permalink
Merge pull request #1158 from joroKr21/jar-size
Browse files Browse the repository at this point in the history
Reduce 2.12 / 2.13 Jar size by using instance constructors
  • Loading branch information
joroKr21 authored May 9, 2021
2 parents a56beb7 + 8466a25 commit 9d254a3
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 287 deletions.
5 changes: 2 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.typesafe.sbt.SbtGit.GitKeys._
import com.typesafe.tools.mima.core.ProblemFilters._
import com.typesafe.tools.mima.core._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbtcrossproject.CrossProject
Expand Down Expand Up @@ -97,8 +96,8 @@ lazy val commonSettings = Seq(

scalacOptions := scalacOptionsAll,
Compile / compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, y)) if y == 12 => scalacOptions212
case Some((2, y)) if y >= 13 => scalacOptions213
case Some((2, 12)) => scalacOptions212
case Some((2, 13)) => scalacOptions213
case _ => Nil
}),

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/shapeless/lazy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class LazyMacros(val c: whitebox.Context) extends CaseClassMacros with OpenImpli
name: String,
dict: ListMap[TypeWrapper, Instance],
open: List[Instance],
/** Types whose derivation must fail no matter what */
// Types whose derivation must fail no matter what
prevent: List[TypeWrapper]
) {
def addDependency(tpe: Type): State = {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/scala/shapeless/ops/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ object function {
}

object FnToProduct extends FnToProductInstances {
type Aux[F, P] = FnToProduct[F] { type Out = P }
def apply[F <: AnyRef](implicit fntop: FnToProduct[F]): Aux[F, fntop.Out] = fntop

private[shapeless] def instance[F, P](toProduct: F => P): Aux[F, P] = new FnToProduct[F] {
type Out = P
def apply(f: F) = toProduct(f)
}
}

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

object FnFromProduct extends FnFromProductInstances {
type Aux[F, O] = FnFromProduct[F] { type Out = O }
def apply[F](implicit fnfromp: FnFromProduct[F]): Aux[F, fnfromp.Out] = fnfromp

private[shapeless] def instance[P, F](fromProduct: P => F): Aux[P, F] = new FnFromProduct[P] {
type Out = F
def apply(f: P) = fromProduct(f)
}
}
}
11 changes: 7 additions & 4 deletions core/src/main/scala/shapeless/ops/hlists.scala
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,16 @@ object hlist {
trait Tupler[L <: HList] extends DepFn1[L] with Serializable

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

private[shapeless] def instance[L <: HList, T](tuple: L => T): Aux[L, T] = new Tupler[L] {
type Out = T
def apply(l: L) = tuple(l)
}

implicit val hnilTupler: Aux[HNil, Unit] =
new Tupler[HNil] {
type Out = Unit
def apply(l: HNil): Out = ()
}
instance(_ => ())
}

/**
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/scala/shapeless/sized.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,29 +212,32 @@ object AdditiveCollection extends AdditiveCollectionVersionSpecific {
import scala.collection.immutable.Queue
import scala.collection.LinearSeq

private[this] val instance =
new AdditiveCollection[Any] {}

implicit def linearSeqAdditiveCollection[T]: AdditiveCollection[LinearSeq[T]] =
new AdditiveCollection[LinearSeq[T]] {}
instance.asInstanceOf[AdditiveCollection[LinearSeq[T]]]

implicit def vectorAdditiveCollection[T]: AdditiveCollection[Vector[T]] =
new AdditiveCollection[Vector[T]] {}
instance.asInstanceOf[AdditiveCollection[Vector[T]]]

implicit def arrayAdditiveCollection[T]: AdditiveCollection[Array[T]] =
new AdditiveCollection[Array[T]] {}
instance.asInstanceOf[AdditiveCollection[Array[T]]]

implicit def stringAdditiveCollection: AdditiveCollection[String] =
new AdditiveCollection[String] {}
instance.asInstanceOf[AdditiveCollection[String]]

implicit def listAdditiveCollection[T]: AdditiveCollection[List[T]] =
new AdditiveCollection[List[T]] {}
instance.asInstanceOf[AdditiveCollection[List[T]]]

implicit def streamAdditiveCollection[T]: AdditiveCollection[LazyList[T]] =
new AdditiveCollection[LazyList[T]] {}
instance.asInstanceOf[AdditiveCollection[LazyList[T]]]

implicit def queueAdditiveCollection[T]: AdditiveCollection[Queue[T]] =
new AdditiveCollection[Queue[T]] {}
instance.asInstanceOf[AdditiveCollection[Queue[T]]]

implicit def defaultAdditiveCollection[T]: AdditiveCollection[collection.immutable.IndexedSeq[T]] =
new AdditiveCollection[collection.immutable.IndexedSeq[T]] {}
instance.asInstanceOf[AdditiveCollection[collection.immutable.IndexedSeq[T]]]
}

class DefaultToIndexedSeq[CC[_]]
Expand Down
Loading

0 comments on commit 9d254a3

Please sign in to comment.