Skip to content

Commit b96a026

Browse files
Merge pull request #8077 from dotty-staging/workaround-lazy-ref-ciclic-ref-in-genDocs
Workaround LazyRef CyclicReference in genDocs
2 parents 385d698 + 3b35795 commit b96a026

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

library/src/scala/internal/quoted/Matcher.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ private[quoted] object Matcher {
259259
if (hasBindAnnotation(pattern.symbol)) bindingMatch(scrutinee.symbol)
260260
else matched
261261
def rhsEnv =
262-
summon[Env] + (scrutinee.symbol -> pattern.symbol) ++
263-
typeParams1.zip(typeParams2).map((tparam1, tparam2) => tparam1.symbol -> tparam2.symbol) ++
262+
val oldEnv: Env = summon[Env]
263+
val newEnv: List[(Symbol, Symbol)] =
264+
(scrutinee.symbol -> pattern.symbol) :: typeParams1.zip(typeParams2).map((tparam1, tparam2) => tparam1.symbol -> tparam2.symbol) :::
264265
paramss1.flatten.zip(paramss2.flatten).map((param1, param2) => param1.symbol -> param2.symbol)
266+
oldEnv ++ newEnv
265267

266268
bindMatch &&
267269
typeParams1 =?= typeParams2 &&

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

+4-4
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

+19-18
Original file line numberDiff line numberDiff line change
@@ -274,31 +274,29 @@ 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
291-
inline def copyToArray[T <: Tuple](tuple: T, array: Array[Object], offset: Int): Unit = (tuple: Any) match {
289+
inline def copyToArray[T <: Tuple](tuple: T, size: Int, array: Array[Object], offset: Int): Unit = (tuple: Any) match {
292290
case xxl: TupleXXL =>
293-
System.arraycopy(xxl.elems, 0, array, offset, tuple.size)
291+
System.arraycopy(xxl.elems, 0, array, offset, size)
294292
case _ =>
295293
tuple.asInstanceOf[Product].productIterator.asInstanceOf[Iterator[Object]]
296-
.copyToArray(array, offset, tuple.size)
294+
.copyToArray(array, offset, size)
297295
}
298296

299297
// In the general case, we copy the two tuples to an array, and convert it back to a tuple
300-
copyToArray(self, arr, 0)
301-
copyToArray(that, arr, self.size)
298+
copyToArray(self, selfSize, arr, 0)
299+
copyToArray(that, thatSize, arr, selfSize)
302300
dynamicFromIArray[Result](arr.asInstanceOf[IArray[Object]])
303301
}
304302

@@ -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)