Skip to content

Commit d145f9e

Browse files
natsukagamibracevac
authored andcommitted
Drop captures from the capture set if the ref is pure, or the shape type is pure
1 parent 922af79 commit d145f9e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ trait TypesSupport:
141141
case t : Refinement if t.isFunctionType =>
142142
inner(base, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = skipTypeSuffix, inCC = Some(refs))
143143
case t if t.isCapSet => emitCaptureSet(refs, skipThisTypePrefix, omitCap = false)
144+
case t if t.isPureClass(elideThis) => inner(base, skipThisTypePrefix)
144145
case t => inner(base, skipThisTypePrefix) ++ emitCapturing(refs, skipThisTypePrefix)
145146
case AnnotatedType(tpe, _) =>
146147
inner(tpe, skipThisTypePrefix)
@@ -529,9 +530,19 @@ trait TypesSupport:
529530
case other => other.reduce((r, e) => r ++ (List(Plain(", ")) ++ e))
530531
Plain("{") :: (res1 ++ List(Plain("}")))
531532

533+
// Within the context of `elideThis`, some capabilities can actually be pure.
534+
private def isCapturedInContext(using Quotes)(ref: reflect.TypeRepr)(using elideThis: reflect.ClassDef): Boolean =
535+
import reflect._
536+
ref match
537+
case ReachCapability(c) => isCapturedInContext(c)
538+
case ReadOnlyCapability(c) => isCapturedInContext(c)
539+
case ThisType(tr) => !elideThis.symbol.typeRef.isPureClass(elideThis) /* is the current class pure? */
540+
case t => !t.isPureClass(elideThis)
541+
532542
private def emitCapturing(using Quotes)(refs: List[reflect.TypeRepr], skipThisTypePrefix: Boolean)(using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol): SSignature =
533543
import reflect._
534-
Keyword("^") :: emitCaptureSet(refs, skipThisTypePrefix)
544+
val refs0 = refs.filter(isCapturedInContext)
545+
if refs0.isEmpty then Nil else Keyword("^") :: emitCaptureSet(refs0, skipThisTypePrefix)
535546

536547
private def emitFunctionArrow(using Quotes)(funTy: reflect.TypeRepr, captures: Option[List[reflect.TypeRepr]], skipThisTypePrefix: Boolean)(using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol): SSignature =
537548
import reflect._
@@ -559,4 +570,4 @@ trait TypesSupport:
559570
case refs => Keyword(prefix + "->") :: emitCaptureSet(refs, skipThisTypePrefix)
560571

561572
private def emitByNameArrow(using Quotes)(captures: Option[List[reflect.TypeRepr]], skipThisTypePrefix: Boolean)(using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol): SSignature =
562-
emitFunctionArrow(CaptureDefs.Function1.typeRef, captures, skipThisTypePrefix)
573+
emitFunctionArrow(CaptureDefs.Function1.typeRef, captures, skipThisTypePrefix)

0 commit comments

Comments
 (0)