Skip to content

Commit 07f104e

Browse files
committed
Workaround ciclic reference issues
And avoid recomputing tuple sizes
1 parent f6bc23f commit 07f104e

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

library/src/scala/quoted/unsafe/UnsafeExpr.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ object UnsafeExpr {
4040
*/
4141
def open[T1, R, X](f: Expr[T1 => R])(content: (Expr[R], [t] => Expr[t] => Expr[T1] => Expr[t]) => X)(given qctx: QuoteContext): X = {
4242
import qctx.tasty.{given, _}
43-
val (params, bodyExpr) = paramsAndBody(f)
43+
val (params, bodyExpr) = paramsAndBody[R](f)
4444
content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](e.unseal, params, List(v.unseal)).seal.asInstanceOf[Expr[t]])
4545
}
4646

4747
def open[T1, T2, R, X](f: Expr[(T1, T2) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2]) => Expr[t]) => X)(given qctx: QuoteContext)(given DummyImplicit): X = {
4848
import qctx.tasty.{given, _}
49-
val (params, bodyExpr) = paramsAndBody(f)
49+
val (params, bodyExpr) = paramsAndBody[R](f)
5050
content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal)).seal.asInstanceOf[Expr[t]])
5151
}
5252

5353
def open[T1, T2, T3, R, X](f: Expr[(T1, T2, T3) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2], Expr[T3]) => Expr[t]) => X)(given qctx: QuoteContext)(given DummyImplicit, DummyImplicit): X = {
5454
import qctx.tasty.{given, _}
55-
val (params, bodyExpr) = paramsAndBody(f)
55+
val (params, bodyExpr) = paramsAndBody[R](f)
5656
content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2], v3: Expr[T3]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal, v3.unseal)).seal.asInstanceOf[Expr[t]])
5757
}
5858

59-
private def paramsAndBody[R](given qctx: QuoteContext)(f: Expr[Any]) = {
59+
private def paramsAndBody[R](given qctx: QuoteContext)(f: Expr[Any]): (List[qctx.tasty.ValDef], Expr[R]) = {
6060
import qctx.tasty.{given, _}
6161
val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = f.unseal.etaExpand
6262
(params, body.seal.asInstanceOf[Expr[R]])

library/src/scala/runtime/DynamicTuple.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,16 @@ object DynamicTuple {
274274
def dynamicConcat[This <: Tuple, That <: Tuple](self: This, that: That): Concat[This, That] = {
275275
type Result = Concat[This, That]
276276

277+
val selfSize: Int = self.size
277278
// If one of the tuples is empty, we can leave early
278-
(self: Any) match {
279-
case self: Unit => return that.asInstanceOf[Result]
280-
case _ =>
281-
}
279+
if selfSize == 0 then
280+
return that.asInstanceOf[Result]
282281

283-
(that: Any) match {
284-
case that: Unit => return self.asInstanceOf[Result]
285-
case _ =>
286-
}
282+
val thatSize: Int = that.size
283+
if thatSize == 0 then
284+
return self.asInstanceOf[Result]
287285

288-
val arr = new Array[Object](self.size + that.size)
286+
val arr = new Array[Object](selfSize + thatSize)
289287

290288
// Copies the tuple to an array, at the given offset
291289
inline def copyToArray[T <: Tuple](tuple: T, array: Array[Object], offset: Int): Unit = (tuple: Any) match {
@@ -401,9 +399,11 @@ object DynamicTuple {
401399
}
402400

403401
def dynamicZip[This <: Tuple, T2 <: Tuple](t1: This, t2: T2): Zip[This, T2] = {
404-
if (t1.size == 0 || t2.size == 0) return ().asInstanceOf[Zip[This, T2]]
405-
val size = Math.min(t1.size, t2.size)
406-
Tuple.fromIArray(
402+
val t1Size: Int = t1.size
403+
val t2Size: Int = t2.size
404+
val size = Math.min(t1Size, t2Size)
405+
if size == 0 then ().asInstanceOf[Zip[This, T2]]
406+
else Tuple.fromIArray(
407407
zipIterators(
408408
t1.asInstanceOf[Product].productIterator,
409409
t2.asInstanceOf[Product].productIterator,
@@ -475,7 +475,8 @@ object DynamicTuple {
475475

476476
def dynamicTake[This <: Tuple, N <: Int](self: This, n: N): Take[This, N] = {
477477
if (n < 0) throw new IndexOutOfBoundsException(n.toString)
478-
val actualN = Math.min(n, self.size)
478+
val selfSize: Int = self.size
479+
val actualN = Math.min(n, selfSize)
479480

480481
type Result = Take[This, N]
481482

0 commit comments

Comments
 (0)