Skip to content

Commit ad63e57

Browse files
committed
Refactor CaptureOps and RetainingType
1 parent bc574e5 commit ad63e57

File tree

2 files changed

+3
-31
lines changed

2 files changed

+3
-31
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,14 @@ def ccState(using Context): CCState =
4848

4949
extension (tree: Tree)
5050

51-
/** Map tree with CaptureRef type to its type,
52-
* map CapSet^{refs} to the `refs` references,
53-
* throw IllegalCaptureRef otherwise
54-
*/
55-
def toCaptureRefs(using Context): List[CaptureRef] = tree match
56-
// case ReachCapabilityApply(arg) =>
57-
// arg.toCaptureRefs.map(_.reach)
58-
// case ReadOnlyCapabilityApply(arg) =>
59-
// arg.toCaptureRefs.map(_.readOnly)
60-
// case CapsOfApply(arg) =>
61-
// arg.toCaptureRefs
62-
case _ => tree.tpe.dealiasKeepAnnots match
63-
case ref: CaptureRef if ref.isTrackableRef =>
64-
ref :: Nil
65-
case AnnotatedType(parent, ann)
66-
if ann.symbol.isRetains && parent.derivesFrom(defn.Caps_CapSet) =>
67-
ann.tree.toCaptureSet.elems.toList
68-
case tpe =>
69-
throw IllegalCaptureRef(tpe) // if this was compiled from cc syntax, problem should have been reported at Typer
70-
7151
/** Convert a @retains or @retainsByName annotation tree to the capture set it represents.
7252
* For efficience, the result is cached as an Attachment on the tree.
7353
*/
7454
def toCaptureSet(using Context): CaptureSet =
7555
tree.getAttachment(Captures) match
7656
case Some(refs) => refs
7757
case None =>
78-
val refs =
79-
tree match
80-
case Apply(_: TypeApply, _) =>
81-
CaptureSet(tree.retainedSet.retainedElements*)
82-
case _ =>
83-
CaptureSet(tree.retainedElems.flatMap(_.toCaptureRefs)*)
84-
// println(s"toCaptureSet: $tree -> $refs")
58+
val refs = CaptureSet(tree.retainedSet.retainedElements*)
8559
tree.putAttachment(Captures, refs)
8660
refs
8761

compiler/src/dotty/tools/dotc/cc/RetainingType.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import Decorators.i
1212
*/
1313
object RetainingType:
1414

15-
// def apply(tp: Type, refs: List[CaptureRef], byName: Boolean = false)(using Context): Type = ???
16-
17-
def apply(tp: Type, typeRefs: Type, byName: Boolean = false)(using Context): Type =
15+
def apply(tp: Type, typeElems: Type, byName: Boolean = false)(using Context): Type =
1816
val annotCls = if byName then defn.RetainsByNameAnnot else defn.RetainsAnnot
19-
val annotTree = New(AppliedType(annotCls.typeRef, typeRefs :: Nil), Nil)
17+
val annotTree = New(AppliedType(annotCls.typeRef, typeElems :: Nil), Nil)
2018
AnnotatedType(tp, Annotation(annotTree))
2119

2220
def unapply(tp: AnnotatedType)(using Context): Option[(Type, Type)] =

0 commit comments

Comments
 (0)