Skip to content

Commit 6009cce

Browse files
committed
Update reference and member searching and tests
1 parent d81ec1f commit 6009cce

37 files changed

+99
-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
// Capture set variable `[C^]` becomes: `[C >: CapSet <: CapSet^{cap}]`
549546
def makeCapsBound()(using Context): TypeBoundsTree =
550547
TypeBoundsTree(

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

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

810-
/** An extractor for `caps.capsOf[X]`, which is used to express a generic capture set
811-
* as a tree in a @retains annotation.
812-
*/
813-
object CapsOfApply:
814-
def unapply(tree: TypeApply)(using Context): Option[Tree] = tree match
815-
case TypeApply(capsOf, arg :: Nil) if capsOf.symbol == defn.Caps_capsOf => Some(arg)
816-
case _ => None
817-
818810
abstract class AnnotatedCapability(annotCls: Context ?=> ClassSymbol):
819811
def apply(tp: Type)(using Context): AnnotatedType =
820812
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
@@ -998,9 +998,6 @@ class Definitions {
998998
@tu lazy val Caps_Capability: ClassSymbol = requiredClass("scala.caps.Capability")
999999
@tu lazy val Caps_CapSet: ClassSymbol = requiredClass("scala.caps.CapSet")
10001000
@tu lazy val CapsInternalModule: Symbol = requiredModule("scala.caps.internal")
1001-
@tu lazy val Caps_reachCapability: TermSymbol = CapsInternalModule.requiredMethod("reachCapability")
1002-
@tu lazy val Caps_readOnlyCapability: TermSymbol = CapsInternalModule.requiredMethod("readOnlyCapability")
1003-
@tu lazy val Caps_capsOf: TermSymbol = CapsInternalModule.requiredMethod("capsOf")
10041001
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
10051002
@tu lazy val Caps_unsafeAssumePure: Symbol = CapsUnsafeModule.requiredMethod("unsafeAssumePure")
10061003
@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
@@ -317,4 +317,17 @@ object NamerOps:
317317
ann.tree match
318318
case ast.tpd.WitnessNamesAnnot(witnessNames) =>
319319
addContextBoundCompanionFor(sym, witnessNames, Nil)
320+
321+
/** Add a dummy term symbol for a type def that has capture parameter flag.
322+
* The dummy symbol has the same name as the original type symbol and is stable.
323+
*
324+
* @param param the original type symbol of the capture parameter
325+
*/
326+
def addDummyTermCaptureParam(param: Symbol)(using Context): Unit =
327+
val name = param.name.toTermName
328+
val flags = (param.flagsUNSAFE & AccessFlags).toTermFlags | CaptureParam | StableRealizable | Synthetic
329+
val dummy = newSymbol(param.owner, name, flags, param.typeRef)
330+
typr.println(i"Adding dummy term symbol $dummy for $param, flags = $flags")
331+
ctx.enter(dummy)
332+
320333
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
@@ -748,7 +748,8 @@ object Types extends TypeUtils {
748748
case tp: ClassInfo => tp.appliedRef
749749
case _ => widenIfUnstable
750750
}
751-
findMember(name, pre, required, excluded)
751+
val excluded1 = if ctx.mode.is(Mode.InCaptureSet) then excluded else excluded | CaptureParam
752+
findMember(name, pre, required, excluded1)
752753
}
753754

754755
/** 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
@@ -173,10 +173,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
173173
private def toTextRetainedElem[T <: Untyped](ref: Tree[T]): Text = ref match
174174
case ref: RefTree[?] if ref.typeOpt.exists =>
175175
toTextCaptureRef(ref.typeOpt)
176-
case TypeApply(fn, arg :: Nil) if fn.symbol == defn.Caps_capsOf =>
177-
toTextRetainedElem(arg)
178-
// case ReachCapabilityApply(ref1) => toTextRetainedElem(ref1) ~ "*"
179-
// case ReadOnlyCapabilityApply(ref1) => toTextRetainedElem(ref1) ~ ".rd"
180176
case _ => toText(ref)
181177

182178
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
@@ -348,6 +348,8 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
348348
unusable(ConstructorProxyNotValue(_))
349349
else if tree.symbol.isContextBoundCompanion then
350350
unusable(ContextBoundCompanionNotValue(_))
351+
else if tree.symbol.isDummyCaptureParam then
352+
throw new Exception(s"Dummy capture param ${tree.symbol} should not be used as a value")
351353
else
352354
tree
353355

0 commit comments

Comments
 (0)