Skip to content

Commit a2ad591

Browse files
authored
Merge pull request #1105 from joroKr21/bincompat
Binary compatible and cross compiling 2.3 version
2 parents a928604 + f7ec99c commit a2ad591

File tree

14 files changed

+463
-254
lines changed

14 files changed

+463
-254
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ name: Continuous Integration
99

1010
on:
1111
pull_request:
12-
branches: ['*']
12+
branches: ['**']
1313
push:
14-
branches: ['*']
14+
branches: ['**']
1515
tags: [v*]
1616

1717
env:

build.sbt

+25-72
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
2-
import com.typesafe.tools.mima.core._
1+
import com.typesafe.sbt.SbtGit.GitKeys._
32
import com.typesafe.tools.mima.core.ProblemFilters._
4-
5-
import com.typesafe.sbt.SbtGit._
6-
import GitKeys._
7-
8-
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
3+
import com.typesafe.tools.mima.core._
4+
import sbtcrossproject.CrossPlugin.autoImport.crossProject
95
import sbtcrossproject.CrossProject
106

117
val Scala211 = "2.11.12"
@@ -27,11 +23,10 @@ ThisBuild / githubWorkflowBuildPreamble := Seq(
2723
WorkflowStep.Run(List("sudo apt install clang libunwind-dev libgc-dev libre2-dev"))
2824
)
2925
ThisBuild / githubWorkflowJavaVersions := Seq("[email protected]")
30-
ThisBuild / githubWorkflowBuildMatrixAdditions +=
31-
"platform" -> List("jvm", "js", "native")
32-
3326
ThisBuild / githubWorkflowArtifactUpload := false
27+
ThisBuild / githubWorkflowBuildMatrixAdditions += "platform" -> List("jvm", "js", "native")
3428
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)
29+
ThisBuild / githubWorkflowTargetBranches := Seq("**") // match all branches, including slashes
3530

3631
val JvmCond = s"matrix.platform == 'jvm'"
3732
val JsCond = s"matrix.platform == 'js'"
@@ -167,14 +162,18 @@ lazy val CrossTypeMixed: sbtcrossproject.CrossType = new sbtcrossproject.CrossTy
167162
Some(projectBase.getParentFile / "src" / conf / "scala")
168163
}
169164

165+
val boilerplate = Def.taskDyn {
166+
(sourceManaged in Compile).map(Boilerplate.gen(scalaBinaryVersion.value))
167+
}
168+
170169
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossTypeMixed)
171170
.configureCross(configureJUnit)
172171
.settings(moduleName := "shapeless")
173172
.settings(coreSettings:_*)
174173
.configureCross(buildInfoSetup)
175174
.enablePlugins(SbtOsgi)
176175
.settings(coreOsgiSettings:_*)
177-
.settings(sourceGenerators in Compile += (sourceManaged in Compile).map(Boilerplate.gen).taskValue)
176+
.settings(sourceGenerators in Compile += boilerplate.taskValue)
178177
.settings(mimaSettings:_*)
179178
.jsSettings(commonJsSettings:_*)
180179
.jvmSettings(commonJvmSettings:_*)
@@ -312,68 +311,22 @@ lazy val noPublishSettings =
312311

313312
enablePlugins(MimaPlugin)
314313
lazy val mimaSettings = Seq(
315-
mimaPreviousArtifacts := {
316-
val previousVersion = if(scalaVersion.value.startsWith("2.13.")) "2.3.3" else "2.3.2"
317-
Set(organization.value %% moduleName.value % previousVersion)
318-
},
319-
mimaBinaryIssueFilters := Seq(
314+
mimaPreviousArtifacts := Set(organization.value %% moduleName.value % "2.3.3"),
315+
mimaBinaryIssueFilters := {
320316
// Macro internals - ignore
321-
exclude[InheritedNewAbstractMethodProblem]("shapeless.CaseClassMacros.varargTC"),
322-
exclude[InheritedNewAbstractMethodProblem]("shapeless.CaseClassMacros.varargTpt"),
323-
exclude[InheritedNewAbstractMethodProblem]("shapeless.CaseClassMacros.shapeless$CaseClassMacrosVersionSpecifics$_setter_$varargTC_="),
324-
exclude[InheritedNewAbstractMethodProblem]("shapeless.CaseClassMacros.shapeless$CaseClassMacrosVersionSpecifics$_setter_$varargTpt_="),
325-
exclude[InheritedNewAbstractMethodProblem]("shapeless.IsCons1Macros.varargTC"),
326-
exclude[InheritedNewAbstractMethodProblem]("shapeless.IsCons1Macros.varargTpt"),
327-
exclude[InheritedNewAbstractMethodProblem]("shapeless.IsCons1Macros.shapeless$CaseClassMacrosVersionSpecifics$_setter_$varargTC_="),
328-
exclude[InheritedNewAbstractMethodProblem]("shapeless.IsCons1Macros.shapeless$CaseClassMacrosVersionSpecifics$_setter_$varargTpt_="),
329-
exclude[MissingClassProblem]("shapeless.CaseClassMacros$PatchedContext$2$PatchedLookupResult"),
330-
exclude[MissingTypesProblem]("shapeless.LazyMacros$"),
331-
exclude[MissingClassProblem]("shapeless.LazyMacrosCompat"),
332-
exclude[MissingClassProblem]("shapeless.LazyMacrosRef"),
333-
334-
// 2.13.x collections related - to eliminate somehow
335-
exclude[DirectMissingMethodProblem]("shapeless.AdditiveCollection.indexedSeqAdditiveCollection"),
336-
exclude[IncompatibleMethTypeProblem]("shapeless.SizedOps.++"),
337-
exclude[DirectMissingMethodProblem]("shapeless.Sized.apply"),
338-
exclude[DirectMissingMethodProblem]("shapeless.SizedBuilder.apply"),
339-
exclude[IncompatibleMethTypeProblem]("shapeless.SizedBuilder.apply"),
340-
exclude[IncompatibleMethTypeProblem]("shapeless.syntax.SizedConv.this"),
341-
exclude[IncompatibleMethTypeProblem]("shapeless.syntax.sized.genTraversableSizedConv"),
342-
exclude[IncompatibleMethTypeProblem]("shapeless.syntax.std.traversable.traversableOps2"),
343-
exclude[IncompatibleMethTypeProblem]("shapeless.syntax.std.TraversableOps2.this"),
344-
exclude[IncompatibleMethTypeProblem]("shapeless.ops.hlist#Repeat.apply"),
345-
exclude[IncompatibleMethTypeProblem]("shapeless.ops.traversable#ToSizedHList.instance"),
346-
exclude[DirectMissingMethodProblem]("shapeless.ops.hlist#ToSized.hlistToSized"),
347-
exclude[IncompatibleMethTypeProblem]("shapeless.ops.traversable#FromTraversable.apply"),
348-
exclude[ReversedMissingMethodProblem]("shapeless.ops.traversable#FromTraversable.apply"),
349-
350-
// Other
351-
exclude[IncompatibleResultTypeProblem]("shapeless.syntax.HListOps.toCoproduct"),
352-
exclude[InheritedNewAbstractMethodProblem]("shapeless.ops.hlist#Repeat.apply"),
353-
exclude[ReversedMissingMethodProblem]("shapeless.SingletonTypeUtils.isSymbolLiteral"),
354-
exclude[ReversedMissingMethodProblem]("shapeless.CaseClassMacros.numNonCaseParamLists"),
355-
356-
// All the following were present in 2.3.2 ...
357-
358-
// Filtering the methods that were added since the checked version
359-
// (these only break forward compatibility, not the backward one)
360-
exclude[ReversedMissingMethodProblem]("shapeless.ops.hlist#IsHCons.cons"),
361-
362-
// Filtering removals
363-
exclude[ReversedMissingMethodProblem]("shapeless.ops.coproduct#IsCCons.cons"),
364-
exclude[MissingClassProblem]("shapeless.ops.coproduct$ZipOne$"),
365-
exclude[MissingClassProblem]("shapeless.ops.coproduct$ZipOne"),
366-
exclude[DirectMissingMethodProblem]("shapeless.LazyMacros.dcRef"),
367-
exclude[DirectMissingMethodProblem]("shapeless.LazyMacros.dcRef_="),
368-
369-
// Implicit reorderings
370-
exclude[DirectMissingMethodProblem]("shapeless.LowPriorityUnaryTCConstraint.hnilConstUnaryTC"),
371-
exclude[ReversedMissingMethodProblem]("shapeless.LowPriorityUnaryTCConstraint.hnilUnaryTC"),
372-
373-
// Relaxed constraints
374-
exclude[IncompatibleMethTypeProblem]("shapeless.ops.traversable#ToSizedHList.apply"),
375-
exclude[ReversedMissingMethodProblem]("shapeless.ops.traversable#ToSizedHList.apply")
376-
)
317+
val macroFilters = List("CaseClassMacros", "IsCons1Macros", "LazyMacros")
318+
.map(macros => exclude[Problem](s"shapeless.$macros*"))
319+
320+
scalaBinaryVersion.value match {
321+
case "2.11" =>
322+
// Adding methods to traits in 2.11 is not binary compatible, but those traits shouldn't be subclassed.
323+
exclude[ReversedMissingMethodProblem]("shapeless.LowPriorityUnaryTCConstraint.hnilUnaryTC") ::
324+
exclude[ReversedMissingMethodProblem]("shapeless.SingletonTypeUtils.isSymbolLiteral") ::
325+
macroFilters
326+
case _ =>
327+
macroFilters
328+
}
329+
}
377330
)
378331

379332
def buildInfoSetup(crossProject: CrossProject): CrossProject = {

core/src/main/scala/shapeless/hlistconstraints.scala

+17-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package shapeless
1818

19-
import ops.hlist.Selector
19+
import shapeless.ops.hlist.Selector
2020

2121
import scala.annotation.implicitNotFound
2222

@@ -26,14 +26,21 @@ import scala.annotation.implicitNotFound
2626
trait UnaryTCConstraint[L <: HList, TC[_]] extends Serializable
2727

2828
trait LowPriorityUnaryTCConstraint0 {
29-
implicit def hlistIdUnaryTC[L <: HList] = new UnaryTCConstraint[L, Id] {}
29+
implicit def hlistIdUnaryTC[L <: HList]: UnaryTCConstraint[L, Id] =
30+
new UnaryTCConstraint[L, Id] {}
3031
}
3132

3233
trait LowPriorityUnaryTCConstraint extends LowPriorityUnaryTCConstraint0 {
3334

34-
implicit def hnilUnaryTC[TC[_]] = new UnaryTCConstraint[HNil, TC] {}
35+
def hnilConstUnaryTC[H]: UnaryTCConstraint[HNil, Const[H]#λ] =
36+
new UnaryTCConstraint[HNil, Const[H]#λ] {}
3537

36-
implicit def hlistConstUnaryTC[H, T <: HList](implicit utct : UnaryTCConstraint[T, Const[H]#λ]) =
38+
implicit def hnilUnaryTC[TC[_]]: UnaryTCConstraint[HNil, TC] =
39+
new UnaryTCConstraint[HNil, TC] {}
40+
41+
implicit def hlistConstUnaryTC[H, T <: HList](
42+
implicit utct: UnaryTCConstraint[T, Const[H]#λ]
43+
): UnaryTCConstraint[H :: T, Const[H]#λ] =
3744
new UnaryTCConstraint[H :: T, Const[H]#λ] {}
3845
}
3946

@@ -42,11 +49,14 @@ object UnaryTCConstraint extends LowPriorityUnaryTCConstraint {
4249

4350
type *->*[TC[_]] = {
4451
type λ[L <: HList] = UnaryTCConstraint[L, TC]
45-
}
52+
}
4653

47-
implicit def hnilConstUnaryTC[H] = new UnaryTCConstraint[HNil, Const[H]#λ] {}
54+
implicit override def hnilConstUnaryTC[H]: UnaryTCConstraint[HNil, Const[H]#λ] =
55+
super.hnilConstUnaryTC[H]
4856

49-
implicit def hlistUnaryTC[H, T <: HList, TC[_]](implicit utct : UnaryTCConstraint[T, TC]) =
57+
implicit def hlistUnaryTC[H, T <: HList, TC[_]](
58+
implicit utct: UnaryTCConstraint[T, TC]
59+
): UnaryTCConstraint[TC[H] :: T, TC] =
5060
new UnaryTCConstraint[TC[H] :: T, TC] {}
5161
}
5262

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

+2-21
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ object hlist {
736736
def apply(l: L): Out
737737
}
738738

739-
object ToSized {
739+
object ToSized extends ToSizedVersionSpecific {
740740
def apply[L <: HList, M[_]](implicit toSized: ToSized[L, M]): Aux[L, M, toSized.Lub, toSized.N] = toSized
741741

742742
type Aux[L <: HList, M[_], Lub0, N0 <: Nat] = ToSized[L, M] { type Lub = Lub0; type N = N0 }
@@ -761,23 +761,6 @@ object hlist {
761761
type N = Nat._1
762762
def apply(l : T :: HNil) = Sized[M](l.head)
763763
}
764-
765-
implicit def hlistToSized[H1, H2, T <: HList, LT, L, N0 <: Nat, M[_]]
766-
(implicit
767-
tts : Aux[H2 :: T, M, LT, N0],
768-
u : Lub[H1, LT, L],
769-
tvs2 : IsRegularIterable[M[LT]] { type A = LT }, // tvs2, tev, and tcbf are required for the call to map below
770-
tev : AdditiveCollection[M[LT]],
771-
f : Factory[L, M[L]],
772-
tcbf : BuildFrom[M[L], L, M[L]],
773-
tcbf2 : BuildFrom[M[LT], L, M[L]],
774-
tvs : IsRegularIterable[M[L]] { type A = L }, // tvs, tcbf2, and ev are required for the call to +: below
775-
ev : AdditiveCollection[M[L]]) : Aux[H1 :: H2 :: T, M, L, Succ[N0]] =
776-
new ToSized[H1 :: H2 :: T, M] {
777-
type Lub = L
778-
type N = Succ[N0]
779-
def apply(l : H1 :: H2 :: T) = u.left(l.head) +: tts(l.tail).map(u.right)
780-
}
781764
}
782765

783766
/**
@@ -2095,9 +2078,7 @@ object hlist {
20952078
*
20962079
* @author Jeremy Smith
20972080
*/
2098-
trait Repeat[L <: HList, N <: Nat] extends DepFn1[L] with Serializable {
2099-
type Out <: HList
2100-
}
2081+
trait Repeat[L <: HList, N <: Nat] extends RepeatVersionSpecific[L]
21012082

21022083
object Repeat {
21032084

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

+15-24
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ final class Sized[+Repr, L <: Nat] private (val unsized : Repr) {
4646
*
4747
* @author Miles Sabin
4848
*/
49-
class SizedOps[A0, Repr : AdditiveCollection, L <: Nat](s : Sized[Repr, L], itl: IsRegularIterable[Repr] { type A = A0 }) { outer =>
49+
class SizedOps[A0, Repr : AdditiveCollection, L <: Nat](s : Sized[Repr, L], itl: IsRegularIterable[Repr] { type A = A0 })
50+
extends SizedOpsVersionSpecific[A0, Repr, L] {
51+
5052
import nat._
5153
import ops.nat._
5254
import LT._
@@ -154,18 +156,6 @@ class SizedOps[A0, Repr : AdditiveCollection, L <: Nat](s : Sized[Repr, L], itl:
154156
builder += elem
155157
wrap[Repr, Succ[L]](builder.result())
156158
}
157-
158-
/**
159-
* Append the argument collection to this collection. The resulting collection will be statically known to have
160-
* ''m+n'' elements.
161-
*/
162-
def ++[B >: A0, That, M <: Nat](that : Sized[That, M])
163-
(implicit
164-
sum : Sum[L, M],
165-
convThat : IsRegularIterable[That] { type A = B },
166-
cbf : Factory[B, That],
167-
ev : AdditiveCollection[That]): Sized[That, sum.Out] =
168-
wrap[That, sum.Out](cbf.fromSpecific(underlying.iterator ++ convThat(that.unsized).iterator))
169159

170160
/**
171161
* Map across this collection. The resulting collection will be statically known to have the same number of elements
@@ -192,20 +182,21 @@ trait LowPrioritySized {
192182
implicit def sizedToRepr[Repr](s : Sized[Repr, _]) : Repr = s.unsized
193183
}
194184

195-
object Sized extends LowPrioritySized {
196-
implicit def sizedOps[Repr, L <: Nat](s : Sized[Repr, L])
197-
(implicit itl: IsRegularIterable[Repr], ev: AdditiveCollection[Repr]): SizedOps[itl.A, Repr, L] =
198-
new SizedOps[itl.A, Repr, L](s, itl)
185+
object Sized extends SizedVersionSpecific with LowPrioritySized {
186+
187+
implicit def sizedOps[Repr, L <: Nat](s: Sized[Repr, L])(
188+
implicit itl: IsRegularIterable[Repr],
189+
ev: AdditiveCollection[Repr]
190+
): SizedOps[itl.A, Repr, L] =
191+
new SizedOps[itl.A, Repr, L](s, itl)
199192

200193
def apply[CC[_]] = new SizedBuilder[CC]
201194

202-
def apply[CC[_]]()
203-
(implicit dis: DefaultToIndexedSeq[CC], cbf : Factory[Nothing, CC[Nothing]], ev : AdditiveCollection[CC[Nothing]]) =
204-
new Sized[CC[Nothing], _0](cbf.newBuilder.result())
205-
206-
def wrap[Repr, L <: Nat](r : Repr)(implicit ev : AdditiveCollection[Repr]) = new Sized[Repr, L](r)
195+
def wrap[Repr, L <: Nat](r : Repr)(implicit ev: AdditiveCollection[Repr]): Sized[Repr, L] =
196+
new Sized[Repr, L](r)
207197

208-
def unapplySeq[Repr, L <: Nat](x : Sized[Repr, L]) = Some(x.unsized)
198+
def unapplySeq[Repr, L <: Nat](x: Sized[Repr, L]): Some[Repr] =
199+
Some(x.unsized)
209200
}
210201

211202
/**
@@ -217,7 +208,7 @@ object Sized extends LowPrioritySized {
217208
*/
218209
trait AdditiveCollection[Repr] extends Serializable
219210

220-
object AdditiveCollection {
211+
object AdditiveCollection extends AdditiveCollectionVersionSpecific {
221212
import scala.collection.immutable.Queue
222213
import scala.collection.LinearSeq
223214

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ final class HListOps[L <: HList](l : L) extends Serializable {
609609
*
610610
* Note that the `M` container must extend `Traversable`, which means that `Array` cannot be used.
611611
*/
612-
def toCoproduct[M[_] <: Iterable[_]](implicit toCoproductTraversable: ToCoproductTraversable[L, M]): toCoproductTraversable.Out = toCoproductTraversable(l)
612+
def toCoproduct[M[_] <: TraversableOrIterable[_]](implicit toCoproductTraversable: ToCoproductTraversable[L, M]): toCoproductTraversable.Out = toCoproductTraversable(l)
613613

614614
/**
615615
* Converts this `HList` to a - sized - `M` of elements typed as the least upper bound of the types of the elements

core/src/main/scala/shapeless/syntax/std/traversables.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ package std
2828
* @author Rob Norris
2929
*/
3030
object traversable {
31-
implicit def traversableOps[T](t : T)(implicit ev: T => Iterable[_]) = new TraversableOps(t)
32-
implicit def traversableOps2[CC[T] <: Iterable[T], A](as: CC[A]) = new TraversableOps2(as)
31+
implicit def traversableOps[T](t: T)(implicit ev: T => GenTraversableOrIterable[_]): TraversableOps[T] = new TraversableOps(t)
32+
implicit def traversableOps2[CC[T] <: GenTraversableOrIterable[T], A](as: CC[A]): TraversableOps2[CC, A] = new TraversableOps2(as)
3333
}
3434

35-
final class TraversableOps[T](t : T)(implicit ev: T => Iterable[_]) {
35+
final class TraversableOps[T](t : T)(implicit ev: T => GenTraversableOrIterable[_]) {
3636
import ops.traversable._
3737

38-
def toHList[L <: HList](implicit fl : FromTraversable[L]) : Option[L] = fl(t)
38+
def toHList[L <: HList](implicit fl: FromTraversable[L]): Option[L] = fl(t)
3939
}
4040

41-
final class TraversableOps2[CC[T] <: Iterable[T], A](as: CC[A]) {
41+
final class TraversableOps2[CC[T] <: GenTraversableOrIterable[T], A](as: CC[A]) {
4242
import ops.traversable._
4343

4444
def toSizedHList(n: Nat)(implicit ts: ToSizedHList[CC, A, n.N]): ts.Out = ts(as)

0 commit comments

Comments
 (0)