Skip to content

Commit 99f6d8c

Browse files
Introduce warning supression for problematic pattern-matches
This is a temporary workaround. The long term goal is to get rid of these nasty annotations again. This will need support form the Scala team though.
1 parent 9ec8852 commit 99f6d8c

16 files changed

Lines changed: 101 additions & 3 deletions

File tree

core/src/main/scala/libretto/CoreLib.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import libretto.lambda.util.SourcePos
55
import libretto.util.unapply.*
66
import libretto.util.{Equal, }
77
import scala.annotation.tailrec
8+
import scala.annotation.nowarn
89

910
object CoreLib {
1011
def apply(dsl: CoreDSL): CoreLib[dsl.type] =
@@ -1199,6 +1200,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib =>
11991200
def selectAgainstR[A](using A: SignalingJunction.Negative[A]): (A |&| A) -⚬ (A |*| Need) =
12001201
|&|.swap > selectAgainstL > swap
12011202

1203+
@nowarn("msg=match may not be exhaustive")
12021204
def racePreferred[A, B](using
12031205
A: Signaling.Positive[A],
12041206
B: Signaling.Positive[B],
@@ -1215,6 +1217,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib =>
12151217
}
12161218
}
12171219

1220+
@nowarn("msg=match may not be exhaustive")
12181221
def raceHandicap[A, B, C](f: (Ping |*| B) -⚬ C)(using
12191222
A: Signaling.Positive[A],
12201223
C: Signaling.Positive[C],
@@ -3533,6 +3536,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib =>
35333536
/** Merges the two lists as they unfold, i.e. as soon as the next element becomes available in one of the lists,
35343537
* it also becomes available as the next element of the result list.
35353538
*/
3539+
@nowarn("msg=match may not be exhaustive")
35363540
def merge[T]: (LList[T] |*| LList[T]) -⚬ LList[T] = rec { self =>
35373541
λ { case as |*| bs =>
35383542
race(as |*| bs) switch {
@@ -3557,6 +3561,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib =>
35573561
* their timely appearence in the input list is sufficient for them to come before
35583562
* the inserted element.
35593563
*/
3564+
@nowarn("msg=match may not be exhaustive")
35603565
def insertBySignal[T](using Signaling.Positive[T]): (T |*| LList[T]) -⚬ LList[T] =
35613566
rec { self =>
35623567
λ { case a |*| as =>
@@ -3892,6 +3897,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib =>
38923897
def mapSequentially[A, B](f: A -⚬ B)(using Signaling.Positive[B]): Endless[A] -⚬ Endless[B] =
38933898
mapSequence(f > notifyPosFst)
38943899

3900+
@nowarn("msg=match may not be exhaustive")
38953901
def foldLeftSequentially[B, A](f: (B |*| A) -⚬ B)(using
38963902
Signaling.Positive[B]
38973903
): (B |*| Endless[A]) -⚬ B =
@@ -3957,6 +3963,7 @@ class CoreLib[DSL <: CoreDSL](val dsl: DSL) { lib =>
39573963
def go: ((A |*| Endless[A]) |*| Endless[A]) -⚬ Endless[A] = rec { self =>
39583964
λ { case (a |*| as) |*| bs =>
39593965
val po |*| pi = constant(lInvertPongPing)
3966+
@nowarn("msg=match may not be exhaustive")
39603967
val res: $[One |&| (A |*| Endless[A])] =
39613968
race[Ping, A](pi |*| a) switch {
39623969
case Left(?(_) |*| a) =>

core/src/main/scala/libretto/InvertLib.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libretto
22

33
import libretto.lambda.util.SourcePos
4+
import scala.annotation.nowarn
45

56
object InvertLib {
67
def apply(
@@ -54,6 +55,7 @@ class InvertLib[
5455
): $[(A |*| B) |+| (A |*| B)] =
5556
coreLib.race[A, B](a |*| b)
5657

58+
@nowarn("msg=match may not be exhaustive")
5759
def race[B](using SourcePos, LambdaContext)(b: ??[B])(using
5860
Signaling.Positive[A],
5961
Signaling.Negative[B],

core/src/main/scala/libretto/scaletto/ScalettoLib.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import scala.annotation.targetName
88
import scala.concurrent.duration.*
99
import scala.reflect.TypeTest
1010
import scala.util.Random
11+
import scala.annotation.nowarn
1112

1213
object ScalettoLib {
1314
def apply(
@@ -117,6 +118,7 @@ class ScalettoLib[
117118
def delayValRandomMs[A](minMs: Int, maxMs: Int): Val[A] -⚬ Val[A] =
118119
delayVal(delayRandomMs(minMs, maxMs))
119120

121+
@nowarn("msg=match may not be exhaustive")
120122
def latestValue[A]: (Val[A] |*| LList[Val[A]]) -⚬ (Endless[Val[A]] |*| Done) = rec { self =>
121123
λ { case +(a) |*| as =>
122124
producing { case outAs |*| outDone =>

core/src/main/scala/libretto/scaletto/impl/futurebased/FutureExecutor.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import libretto.scaletto.ScalettoExecutor
88
import libretto.scaletto.impl.FreeScaletto
99
import libretto.util.Async
1010
import scala.concurrent.ExecutionContext
11+
import scala.annotation.nowarn
1112

1213
object FutureExecutor {
1314
def apply(
@@ -29,6 +30,7 @@ object FutureExecutor {
2930
override def scheduler(s: Scheduler): ExecutionParam[Unit] =
3031
ExecutionParams.Free.wrap(SchedulerParam(s))
3132

33+
@nowarn("msg=type test")
3234
def extract[A](pa: ExecutionParam[A]): (Option[Scheduler], A) = {
3335
import ExecutionParams.Free.{One, Zip, Ext}
3436
pa match {

examples/src/main/scala/libretto/examples/interactionNets/unaryArithmetic/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ object Wire {
2727
def dup : (Wire |*| Wire) -⚬ Proper = injectL injectR
2828
def eraser: One -⚬ Proper = injectR
2929

30+
@nowarn("msg=match may not be exhaustive")
3031
def switchWith[A, R](
3132
caseZero: A -⚬ R,
3233
caseSucc: (A |*| Wire) -⚬ R,
@@ -192,6 +193,7 @@ object Wire {
192193
}
193194

194195
import Wire.Outlet
196+
import scala.annotation.nowarn
195197

196198
enum Result {
197199
case Zero

examples/src/main/scala/libretto/examples/sunflowers/SunflowerProcessingFacility.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package libretto.examples.sunflowers
33
import libretto.scaletto.StarterKit.*
44
import libretto.stream.scaletto.DefaultStreams.ValSource
55
import libretto.stream.scaletto.DefaultStreams.ValSource.{Polled, fromChoice, notifyAction, poll}
6+
import scala.annotation.nowarn
67

78
object SunflowerProcessingFacility {
9+
@nowarn("msg=match may not be exhaustive")
810
def blueprint: ValSource[Sunflower] -⚬ (ValSource[SeedsPack] |*| ValSource[OilBottle]) = rec { self =>
911
λ { sunflowers =>
1012
// give names to the outputs

lambda/src/main/scala/libretto/lambda/Bin.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package libretto.lambda
22

33
import libretto.lambda.util.{BiInjective, Exists, Injective, Masked, TypeEq, UniqueTypeArg}
44
import libretto.lambda.util.TypeEq.Refl
5+
import scala.annotation.nowarn
56

67
/**
78
* Binary tree with leafs holding values of types `F[X]`, `F[Y]`, ...
@@ -92,6 +93,7 @@ sealed trait Bin[<*>[_, _], T[_], F[_], A] {
9293
) extends Partitioned[G, H, ~⚬]
9394
}
9495

96+
@nowarn("msg=type test")
9597
def deduplicateLeafs[->[_, _]](
9698
dup: [x] => F[x] => T[x] -> (T[x] <*> T[x]),
9799
)(using
@@ -294,6 +296,7 @@ object Bin {
294296
case class Branch[<*>[_, _], T[_], F[_], A, B](l: Bin[<*>, T, F, A], r: Bin[<*>, T, F, B]) extends Bin[<*>, T, F, A <*> B]
295297
case class Leaf[<*>[_, _], T[_], F[_], A](value: F[A]) extends Bin[<*>, T, F, T[A]]
296298

299+
@nowarn("msg=match may not be exhaustive")
297300
def branchesOf[<*>[_, _], T[_], F[_], A, B](tree: Bin[<*>, T, F, A <*> B])(using
298301
leafIsNotBranch: [x, y, z] => (T[x] =:= (y <*> z)) => Nothing,
299302
)(using
@@ -311,6 +314,7 @@ object Bin {
311314
}
312315
)
313316

317+
@nowarn("msg=match may not be exhaustive")
314318
def valueOf[<*>[_, _], T[_], F[_], A](tree: Bin[<*>, T, F, T[A]])(using
315319
leafIsNotBranch: [x, y, z] => (T[x] =:= (y <*> z)) => Nothing,
316320
)(using

lambda/src/main/scala/libretto/lambda/Lambdas.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import libretto.lambda.Lambdas.Error
44
import libretto.lambda.Lambdas.Error.LinearityViolation
55
import libretto.lambda.util.{Applicative, BiInjective, Exists, UniqueTypeArg}
66
import scala.annotation.targetName
7+
import scala.annotation.nowarn
78

89
trait Lambdas[-⚬[_, _], |*|[_, _], V] {
910
final type Tupled[F[_], A] = libretto.lambda.Tupled[|*|, F, A]
@@ -130,6 +131,7 @@ trait Lambdas[-⚬[_, _], |*|[_, _], V] {
130131
Context,
131132
): AbsRes[A, B]
132133

134+
@nowarn("msg=match may not be exhaustive")
133135
protected def switchImpl[<+>[_, _], A, B](
134136
cases: Sink[VFun, <+>, A, B],
135137
sum: [X, Y] => (X -⚬ B, Y -⚬ B) => (X <+> Y) -⚬ B,

lambda/src/main/scala/libretto/lambda/LambdasImpl.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import libretto.lambda.Lambdas.Error.LinearityViolation
66
import libretto.lambda.util.{Applicative, BiInjective, Exists, Injective, Masked, TypeEq, UniqueTypeArg}
77
import libretto.lambda.util.TypeEq.Refl
88
import scala.annotation.{tailrec, targetName}
9+
import scala.annotation.nowarn
910

1011
class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
1112
ssc: SymmetricSemigroupalCategory[-⚬, |*|],
@@ -631,6 +632,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
631632
override def cap2_gcd_this[T, Y](that: CaptureSnd[T, Y])(using ev: (Var[A1] |*| Var[A2]) =:= Var[T]): Option[Tail[Var[T], Var[T |*| Y] |*| Var[A1 |*| A2]]] =
632633
varIsNotPair(ev.flip)
633634

635+
@nowarn("msg=match may not be exhaustive")
634636
override def asZip[P1, P2](using
635637
ev: (Var[A1] |*| Var[A2]) =:= (P1 |*| P2),
636638
): Exists[[V1] =>> Exists[[V2] =>> (Zip[V1, V2], P1 =:= Var[V1], P2 =:= Var[V2], Var[A1 |*| A2] =:= Var[V1 |*| V2])]] =
@@ -702,6 +704,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
702704
case (None, Some(_)) =>
703705
bug(s"Variable ${that.resultVar} appeared as a result of two different projections")
704706

707+
@nowarn("msg=match may not be exhaustive")
705708
override def unzip_gcd_this[T1, T2](that: Unzip[T1, T2])(using
706709
ev: Var[A1 |*| A2] =:= Var[T1 |*| T2],
707710
): Option[Tail[Var[T1 |*| T2], (Var[T1] |*| Var[T2]) |*| Var[A1]]] =
@@ -855,6 +858,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
855858
override def unzip_gcd_this[T1, T2](that: Unzip[T1, T2])(using ev: Var[A] =:= Var[T1 |*| T2]): Option[Tail[Var[T1 |*| T2], (Var[T1] |*| Var[T2]) |*| Var[X |*| A]]] =
856859
UnhandledCase.raise(s"${this.getClass.getSimpleName}.unzip_gcd_this")
857860

861+
@nowarn("msg=match may not be exhaustive")
858862
override def cap1_gcd_this[T, Y](that: CaptureFst[T, Y])(using ev: Var[A] =:= Var[T]): Option[Tail[Var[T], Var[Y |*| T] |*| Var[X |*| A]]] =
859863
ev match { case Injective[Var](TypeEq(Refl())) =>
860864
(that.resultVar testEqual this.resultVar) map {
@@ -889,6 +893,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
889893
override def cap1_gcd_this[T, Y](that: CaptureFst[T, Y])(using Var[A] =:= Var[T]): Option[Tail[Var[T], Var[Y |*| T] |*| Var[A |*| X]]] =
890894
None
891895

896+
@nowarn("msg=match may not be exhaustive")
892897
override def cap2_gcd_this[T, Y](that: CaptureSnd[T, Y])(using ev: Var[A] =:= Var[T]): Option[Tail[Var[T], Var[T |*| Y] |*| Var[A |*| X]]] =
893898
ev match { case Injective[Var](TypeEq(Refl())) =>
894899
(that.resultVar testEqual this.resultVar) map {
@@ -935,6 +940,8 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
935940
}
936941
}
937942

943+
@nowarn("msg=match may not be exhaustive")
944+
@nowarn("msg=type test")
938945
def gcd[C[_], D[_], X, Y, Z](
939946
f: Op.Affine[C[Var[X]], Y],
940947
g: Op.Affine[D[Var[X]], Z],
@@ -964,6 +971,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
964971
}
965972
}
966973

974+
@nowarn("msg=match may not be exhaustive")
967975
private def gcdZips[A1, A2, B1, B2](
968976
z1: Zip[A1, A2],
969977
z2: Zip[B1, B2],
@@ -1070,6 +1078,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
10701078
case Op.Prj2(_, _) => None
10711079
}
10721080

1081+
@nowarn("msg=match may not be exhaustive")
10731082
def pullBumpDupVar[A, F[_], V, C[_], B, D[_], Y](
10741083
pre: Tail[A, F[Var[V]]],
10751084
post: Tail[F[C[Var[V]]], B],
@@ -1211,6 +1220,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
12111220
}
12121221
object Unvar {
12131222
case class SingleVar[V]() extends Unvar[Var[V], V] {
1223+
@nowarn("msg=match may not be exhaustive")
12141224
override def uniqueOutType[C](that: Unvar[Var[V], C]): V =:= C =
12151225
that.maskInput.visit([VV] => (that: Unvar[VV, C], ev: VV =:= Var[V]) => {
12161226
that match {
@@ -1225,6 +1235,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
12251235
}
12261236

12271237
case class Par[A1, A2, X1, X2](u1: Unvar[A1, X1], u2: Unvar[A2, X2]) extends Unvar[A1 |*| A2, X1 |*| X2] {
1238+
@nowarn("msg=match may not be exhaustive")
12281239
override def uniqueOutType[C](that: Unvar[A1 |*| A2, C]): (X1 |*| X2) =:= C =
12291240
that.maskInput.visit([A] => (that: Unvar[A, C], ev: A =:= (A1 |*| A2)) => {
12301241
that match {
@@ -1248,6 +1259,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
12481259
override def pair[A1, A2, X1, X2](f1: Unvar[A1, X1], f2: Unvar[A2, X2]): Unvar[A1 |*| A2, X1 |*| X2] =
12491260
Unvar.Par(f1, f2)
12501261

1262+
@nowarn("msg=match may not be exhaustive")
12511263
override def unpair[A1, A2, X](f: Unvar[A1 |*| A2, X]): Unpaired[A1, A2, X] =
12521264
f.maskInput.visit[Unpaired[A1, A2, X]]([A] => (u: Unvar[A, X], ev: A =:= (A1 |*| A2)) => {
12531265
u match {
@@ -1266,6 +1278,7 @@ class LambdasImpl[-⚬[_, _], |*|[_, _], V](using
12661278
[V, A, B] => (ev: Var[V] =:= (A |*| B)) => throw new AssertionError("Var[A] =:= (A |*| B)")
12671279

12681280
extension[F[_], V, U](ev: F[Var[V]] =:= (Var[U] |*| Var[U])) {
1281+
@nowarn("msg=match may not be exhaustive")
12691282
def deriveEquality(f: Focus[|*|, F]): V =:= U =
12701283
f match {
12711284
case f: Focus.Fst[pair, f1, q] =>

lambda/src/main/scala/libretto/lambda/Projection.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package libretto.lambda
22

33
import libretto.lambda.util.{BiInjective, Exists, TypeEq}
44
import libretto.lambda.util.TypeEq.Refl
5+
import scala.annotation.nowarn
56

67
sealed trait Projection[|*|[_, _], P, Q] {
78
def at[F[_]](f: Focus[|*|, F]): Projection[|*|, F[P], F[Q]]
@@ -73,6 +74,8 @@ object Projection {
7374
switchFromPair[P1, P2, R](caseDiscardFst, caseDiscardSnd, casePar)
7475
}
7576

77+
@nowarn("msg=match may not be exhaustive")
78+
@nowarn("msg=type test")
7679
def switchFromPair[P1, P2, R](using ev: P =:= (P1 |*| P2))(
7780
caseDiscardFst: (p2: Projection[|*|, P2, Q]) => R,
7881
caseDiscardSnd: (p1: Projection[|*|, P1, Q]) => R,

0 commit comments

Comments
 (0)