Skip to content

Commit fd955db

Browse files
committed
Update reference and member searching and tests
1 parent 86292bd commit fd955db

36 files changed

+98
-121
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
542542
annot.putAttachment(RetainsAnnot, ())
543543
Annotated(parent, annot)
544544

545-
def makeCapsOf(tp: RefTree)(using Context): Tree =
546-
TypeApply(capsInternalDot(nme.capsOf), tp :: Nil)
547-
548545
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(using Context): DefDef =
549546
DefDef(nme.CONSTRUCTOR, joinParams(tparams, vparamss), TypeTree(), rhs)
550547

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,6 @@ trait FollowAliasesMap(using Context) extends TypeMap:
674674
// case Apply(ro, arg :: Nil) if ro.symbol == defn.Caps_readOnlyCapability => Some(arg)
675675
// case _ => None
676676

677-
/** An extractor for `caps.capsOf[X]`, which is used to express a generic capture set
678-
* as a tree in a @retains annotation.
679-
*/
680-
object CapsOfApply:
681-
def unapply(tree: TypeApply)(using Context): Option[Tree] = tree match
682-
case TypeApply(capsOf, arg :: Nil) if capsOf.symbol == defn.Caps_capsOf => Some(arg)
683-
case _ => None
684-
685677
abstract class AnnotatedCapability(annotCls: Context ?=> ClassSymbol):
686678
def apply(tp: Type)(using Context): AnnotatedType =
687679
assert(tp.isTrackableRef, i"not a trackable ref: $tp")

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,6 @@ class Definitions {
10011001
@tu lazy val Caps_Capability: ClassSymbol = requiredClass("scala.caps.Capability")
10021002
@tu lazy val Caps_CapSet: ClassSymbol = requiredClass("scala.caps.CapSet")
10031003
@tu lazy val CapsInternalModule: Symbol = requiredModule("scala.caps.internal")
1004-
@tu lazy val Caps_reachCapability: TermSymbol = CapsInternalModule.requiredMethod("reachCapability")
1005-
@tu lazy val Caps_readOnlyCapability: TermSymbol = CapsInternalModule.requiredMethod("readOnlyCapability")
1006-
@tu lazy val Caps_capsOf: TermSymbol = CapsInternalModule.requiredMethod("capsOf")
10071004
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
10081005
@tu lazy val Caps_unsafeAssumePure: Symbol = CapsUnsafeModule.requiredMethod("unsafeAssumePure")
10091006
@tu lazy val Caps_unsafeAssumeSeparate: Symbol = CapsUnsafeModule.requiredMethod("unsafeAssumeSeparate")

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ object Flags {
380380
/** Tracked modifier for class parameter / a class with some tracked parameters */
381381
val (Tracked @ _, _, Dependent @ _) = newFlags(46, "tracked")
382382

383+
val (CaptureParam @ _, _, _) = newFlags(47, "capture-param")
384+
383385
// ------------ Flags following this one are not pickled ----------------------------------
384386

385387
/** Symbol is not a member of its owner */
@@ -449,7 +451,7 @@ object Flags {
449451

450452
/** Flags representing source modifiers */
451453
private val CommonSourceModifierFlags: FlagSet =
452-
commonFlags(Private, Protected, Final, Case, Implicit, Given, Override, JavaStatic, Transparent, Erased)
454+
commonFlags(Private, Protected, Final, Case, Implicit, Given, Override, JavaStatic, Transparent, Erased, CaptureParam)
453455

454456
val TypeSourceModifierFlags: FlagSet =
455457
CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque | Open
@@ -469,7 +471,7 @@ object Flags {
469471
val FromStartFlags: FlagSet = commonFlags(
470472
Module, Package, Deferred, Method, Case, Enum, Param, ParamAccessor,
471473
Scala2SpecialFlags, MutableOrOpen, Opaque, Touched, JavaStatic,
472-
OuterOrCovariant, LabelOrContravariant, CaseAccessor, Tracked,
474+
OuterOrCovariant, LabelOrContravariant, CaseAccessor, Tracked, CaptureParam,
473475
Extension, NonMember, Implicit, Given, Permanent, Synthetic, Exported,
474476
SuperParamAliasOrScala2x, Inline, Macro, ConstructorProxy, Invisible)
475477

compiler/src/dotty/tools/dotc/core/NamerOps.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,17 @@ object NamerOps:
315315
ann.tree match
316316
case ast.tpd.WitnessNamesAnnot(witnessNames) =>
317317
addContextBoundCompanionFor(sym, witnessNames, Nil)
318+
319+
/** Add a dummy term symbol for a type def that has capture parameter flag.
320+
* The dummy symbol has the same name as the original type symbol and is stable.
321+
*
322+
* @param param the original type symbol of the capture parameter
323+
*/
324+
def addDummyTermCaptureParam(param: Symbol)(using Context): Unit =
325+
val name = param.name.toTermName
326+
val flags = (param.flagsUNSAFE & AccessFlags).toTermFlags | CaptureParam | StableRealizable | Synthetic
327+
val dummy = newSymbol(param.owner, name, flags, param.typeRef)
328+
typr.println(i"Adding dummy term symbol $dummy for $param, flags = $flags")
329+
ctx.enter(dummy)
330+
318331
end NamerOps

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ object StdNames {
445445
val canEqual_ : N = "canEqual"
446446
val canEqualAny : N = "canEqualAny"
447447
val caps: N = "caps"
448-
val capsOf: N = "capsOf"
449448
val captureChecking: N = "captureChecking"
450449
val checkInitialized: N = "checkInitialized"
451450
val classOf: N = "classOf"

compiler/src/dotty/tools/dotc/core/SymUtils.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class SymUtils:
9090
def isContextBoundCompanion(using Context): Boolean =
9191
self.is(Synthetic) && self.infoOrCompleter.typeSymbol == defn.CBCompanion
9292

93+
def isDummyCaptureParam(using Context): Boolean =
94+
self.is(Synthetic) && self.is(CaptureParam)
95+
9396
/** Is this a case class for which a product mirror is generated?
9497
* Excluded are value classes, abstract classes and case classes with more than one
9598
* parameter section.

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ object Types extends TypeUtils {
747747
case tp: ClassInfo => tp.appliedRef
748748
case _ => widenIfUnstable
749749
}
750-
findMember(name, pre, required, excluded)
750+
val excluded1 = if ctx.mode.is(Mode.InCaptureSet) then excluded else excluded | CaptureParam
751+
findMember(name, pre, required, excluded1)
751752
}
752753

753754
/** The implicit members with given name. If there are none and the denotation

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
176176
private def toTextRetainedElem[T <: Untyped](ref: Tree[T]): Text = ref match
177177
case ref: RefTree[?] if ref.typeOpt.exists =>
178178
toTextCaptureRef(ref.typeOpt)
179-
case TypeApply(fn, arg :: Nil) if fn.symbol == defn.Caps_capsOf =>
180-
toTextRetainedElem(arg)
181-
// case ReachCapabilityApply(ref1) => toTextRetainedElem(ref1) ~ "*"
182-
// case ReadOnlyCapabilityApply(ref1) => toTextRetainedElem(ref1) ~ ".rd"
183179
case _ => toText(ref)
184180

185181
private def toTextRetainedElems[T <: Untyped](refs: List[Tree[T]]): Text =

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
350350
unusable(ConstructorProxyNotValue(_))
351351
else if tree.symbol.isContextBoundCompanion then
352352
unusable(ContextBoundCompanionNotValue(_))
353+
else if tree.symbol.isDummyCaptureParam then
354+
throw new Exception(s"Dummy capture param ${tree.symbol} should not be used as a value")
353355
else
354356
tree
355357

0 commit comments

Comments
 (0)