Skip to content

Commit 1732445

Browse files
add runtime.TupleMirror
Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com> Co-authored-by: Nicolas Stucki <nicolas.stucki@gmail.com>
1 parent 9be5a34 commit 1732445

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package scala.runtime
2+
3+
/** A concrete subclass of `scala.deriving.Mirror.Product`, enabling reduction of bytecode size.
4+
* as we do not need to synthesize an anonymous Mirror class at every callsite.
5+
*/
6+
final class TupleMirror(arity: Int) extends scala.deriving.Mirror.Product with Serializable:
7+
assert(arity > 0) // EmptyTuple is not a valid `MirroredType` for TupleMirror
8+
9+
override type MirroredMonoType <: NonEmptyTuple
10+
11+
final def fromProduct(product: Product): MirroredMonoType =
12+
if product.productArity != arity then
13+
throw IllegalArgumentException(s"expected Product with $arity elements, got ${product.productArity}")
14+
runtime.Tuples.fromProduct(product).asInstanceOf[MirroredMonoType]
15+
16+
override final def toString: String = s"<tuple-mirror@${Integer.toHexString(hashCode).nn.take(6)}>"

0 commit comments

Comments
 (0)