Skip to content

Commit 8fde1ad

Browse files
committed
Refactor CaptureOps and RetainingType
1 parent 8af1c14 commit 8fde1ad

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
@@ -190,40 +190,14 @@ def ccState(using Context): CCState =
190190

191191
extension (tree: Tree)
192192

193-
/** Map tree with CaptureRef type to its type,
194-
* map CapSet^{refs} to the `refs` references,
195-
* throw IllegalCaptureRef otherwise
196-
*/
197-
def toCaptureRefs(using Context): List[CaptureRef] = tree match
198-
// case ReachCapabilityApply(arg) =>
199-
// arg.toCaptureRefs.map(_.reach)
200-
// case ReadOnlyCapabilityApply(arg) =>
201-
// arg.toCaptureRefs.map(_.readOnly)
202-
// case CapsOfApply(arg) =>
203-
// arg.toCaptureRefs
204-
case _ => tree.tpe.dealiasKeepAnnots match
205-
case ref: CaptureRef if ref.isTrackableRef =>
206-
ref :: Nil
207-
case AnnotatedType(parent, ann)
208-
if ann.symbol.isRetains && parent.derivesFrom(defn.Caps_CapSet) =>
209-
ann.tree.toCaptureSet.elems.toList
210-
case tpe =>
211-
throw IllegalCaptureRef(tpe) // if this was compiled from cc syntax, problem should have been reported at Typer
212-
213193
/** Convert a @retains or @retainsByName annotation tree to the capture set it represents.
214194
* For efficience, the result is cached as an Attachment on the tree.
215195
*/
216196
def toCaptureSet(using Context): CaptureSet =
217197
tree.getAttachment(Captures) match
218198
case Some(refs) => refs
219199
case None =>
220-
val refs =
221-
tree match
222-
case Apply(_: TypeApply, _) =>
223-
CaptureSet(tree.retainedSet.retainedElements*)
224-
case _ =>
225-
CaptureSet(tree.retainedElems.flatMap(_.toCaptureRefs)*)
226-
// println(s"toCaptureSet: $tree -> $refs")
200+
val refs = CaptureSet(tree.retainedSet.retainedElements*)
227201
tree.putAttachment(Captures, refs)
228202
refs
229203

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)