Skip to content

Commit bbcb4e6

Browse files
natsukagamiWojciechMazur
authored andcommitted
Drop captures from the capture set if the ref is pure, or the shape type is pure
[Cherry-picked ef2aa9d]
1 parent 087ffae commit bbcb4e6

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)
@@ -527,9 +528,19 @@ trait TypesSupport:
527528
case other => other.reduce((r, e) => r ++ (List(Plain(", ")) ++ e))
528529
Plain("{") :: (res1 ++ List(Plain("}")))
529530

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

534545
private def emitFunctionArrow(using Quotes)(funTy: reflect.TypeRepr, captures: Option[List[reflect.TypeRepr]], skipThisTypePrefix: Boolean)(using elideThis: reflect.ClassDef, originalOwner: reflect.Symbol): SSignature =
535546
import reflect._
@@ -557,4 +568,4 @@ trait TypesSupport:
557568
case refs => Keyword(prefix + "->") :: emitCaptureSet(refs, skipThisTypePrefix)
558569

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

0 commit comments

Comments
 (0)