@@ -16,9 +16,6 @@ object Deriving {
16
16
/** The mirrored *-type */
17
17
type _MonoType
18
18
}
19
- type MirrorOf [T ] = Mirror { type _MonoType = T }
20
- type ProductMirrorOf [T ] = Mirror .Product { type _MonoType = T }
21
- type SumMirrorOf [T ] = Mirror .Sum { type _MonoType = T }
22
19
23
20
object Mirror {
24
21
@@ -51,7 +48,10 @@ object Deriving {
51
48
type _MonoType = this .type
52
49
def _fromProduct (p : scala.Product ) = this
53
50
}
54
- }
51
+ type Of [T ] = Mirror { type _MonoType = T }
52
+ type ProductOf [T ] = Mirror .Product { type _MonoType = T }
53
+ type SumOf [T ] = Mirror .Sum { type _MonoType = T }
54
+ }
55
55
56
56
/** Helper class to turn arrays into products */
57
57
class ArrayProduct (val elems : Array [AnyRef ]) extends Product {
@@ -212,28 +212,28 @@ object Eq {
212
212
true
213
213
}
214
214
215
- inline def eqlProduct [T ](m : ProductMirrorOf [T ])(x : Any , y : Any ): Boolean =
215
+ inline def eqlProduct [T ](m : Mirror . ProductOf [T ])(x : Any , y : Any ): Boolean =
216
216
eqlElems[m.ElemTypes ](0 )(x, y)
217
217
218
218
inline def eqlCases [Alts ](n : Int )(x : Any , y : Any , ord : Int ): Boolean =
219
219
inline erasedValue[Alts ] match {
220
220
case _ : (alt *: alts1) =>
221
221
if (ord == n)
222
222
implicit match {
223
- case m : ProductMirrorOf [`alt`] => eqlElems[m.ElemTypes ](0 )(x, y)
223
+ case m : Mirror . ProductOf [`alt`] => eqlElems[m.ElemTypes ](0 )(x, y)
224
224
}
225
225
else eqlCases[alts1](n + 1 )(x, y, ord)
226
226
case _ : Unit =>
227
227
false
228
228
}
229
229
230
- inline def derived [T ](implicit ev : MirrorOf [T ]): Eq [T ] = new Eq [T ] {
230
+ inline def derived [T ](implicit ev : Mirror . Of [T ]): Eq [T ] = new Eq [T ] {
231
231
def eql (x : T , y : T ): Boolean =
232
232
inline ev match {
233
- case m : SumMirrorOf [T ] =>
233
+ case m : Mirror . SumOf [T ] =>
234
234
val ord = m.ordinal(x)
235
235
ord == m.ordinal(y) && eqlCases[m.ElemTypes ](0 )(x, y, ord)
236
- case m : ProductMirrorOf [T ] =>
236
+ case m : Mirror . ProductOf [T ] =>
237
237
eqlElems[m.ElemTypes ](0 )(x, y)
238
238
}
239
239
}
@@ -272,7 +272,7 @@ object Pickler {
272
272
case _ : (alt *: alts1) =>
273
273
if (ord == n)
274
274
implicit match {
275
- case m : ProductMirrorOf [`alt`] => pickleElems[m.ElemTypes ](0 )(buf, x)
275
+ case m : Mirror . ProductOf [`alt`] => pickleElems[m.ElemTypes ](0 )(buf, x)
276
276
}
277
277
else pickleCases[alts1](n + 1 )(buf, x, ord)
278
278
case _ : Unit =>
@@ -290,7 +290,7 @@ object Pickler {
290
290
case _ : Unit =>
291
291
}
292
292
293
- inline def unpickleCase [T , Elems <: Tuple ](buf : mutable.ListBuffer [Int ], m : ProductMirrorOf [T ]): T = {
293
+ inline def unpickleCase [T , Elems <: Tuple ](buf : mutable.ListBuffer [Int ], m : Mirror . ProductOf [T ]): T = {
294
294
inline val size = constValue[Tuple .Size [Elems ]]
295
295
inline if (size == 0 )
296
296
m._fromProduct(EmptyProduct )
@@ -306,30 +306,30 @@ object Pickler {
306
306
case _ : (alt *: alts1) =>
307
307
if (ord == n)
308
308
implicit match {
309
- case m : ProductMirrorOf [`alt` & T ] =>
309
+ case m : Mirror . ProductOf [`alt` & T ] =>
310
310
unpickleCase[`alt` & T , m.ElemTypes ](buf, m)
311
311
}
312
312
else unpickleCases[T , alts1](n + 1 )(buf, ord)
313
313
case _ : Unit =>
314
314
throw new IndexOutOfBoundsException (s " unexpected ordinal number: $ord" )
315
315
}
316
316
317
- inline def derived [T ](implicit ev : MirrorOf [T ]): Pickler [T ] = new {
317
+ inline def derived [T ](implicit ev : Mirror . Of [T ]): Pickler [T ] = new {
318
318
def pickle (buf : mutable.ListBuffer [Int ], x : T ): Unit =
319
319
inline ev match {
320
- case m : SumMirrorOf [T ] =>
320
+ case m : Mirror . SumOf [T ] =>
321
321
val ord = m.ordinal(x)
322
322
buf += ord
323
323
pickleCases[m.ElemTypes ](0 )(buf, x, ord)
324
- case m : ProductMirrorOf [T ] =>
324
+ case m : Mirror . ProductOf [T ] =>
325
325
pickleElems[m.ElemTypes ](0 )(buf, x)
326
326
}
327
327
def unpickle (buf : mutable.ListBuffer [Int ]): T =
328
328
inline ev match {
329
- case m : SumMirrorOf [T ] =>
329
+ case m : Mirror . SumOf [T ] =>
330
330
val ord = nextInt(buf)
331
331
unpickleCases[T , m.ElemTypes ](0 )(buf, ord)
332
- case m : ProductMirrorOf [T ] =>
332
+ case m : Mirror . ProductOf [T ] =>
333
333
unpickleCase[T , m.ElemTypes ](buf, m)
334
334
}
335
335
}
@@ -365,7 +365,7 @@ object Show {
365
365
Nil
366
366
}
367
367
368
- inline def showCase (x : Any , m : ProductMirrorOf [_]): String = {
368
+ inline def showCase (x : Any , m : Mirror . ProductOf [_]): String = {
369
369
val label = constValue[m.CaseLabel ]
370
370
inline m match {
371
371
case m : Mirror .Singleton => label
@@ -378,21 +378,21 @@ object Show {
378
378
case _ : (alt *: alts1) =>
379
379
if (ord == n)
380
380
implicit match {
381
- case m : ProductMirrorOf [`alt`] =>
381
+ case m : Mirror . ProductOf [`alt`] =>
382
382
showCase(x, m)
383
383
}
384
384
else showCases[alts1](n + 1 )(x, ord)
385
385
case _ : Unit =>
386
386
throw new MatchError (x)
387
387
}
388
388
389
- inline def derived [T ](implicit ev : MirrorOf [T ]): Show [T ] = new {
389
+ inline def derived [T ](implicit ev : Mirror . Of [T ]): Show [T ] = new {
390
390
def show (x : T ): String =
391
391
inline ev match {
392
- case m : SumMirrorOf [T ] =>
392
+ case m : Mirror . SumOf [T ] =>
393
393
val ord = m.ordinal(x)
394
394
showCases[m.ElemTypes ](0 )(x, ord)
395
- case m : ProductMirrorOf [T ] =>
395
+ case m : Mirror . ProductOf [T ] =>
396
396
showCase(x, m)
397
397
}
398
398
}
0 commit comments