Skip to content

Commit 6da745b

Browse files
committed
Simplification: Generate annotations for .rd and * directly
No more detour via PostfixOps of compiler-generated names.
1 parent 74d7ae0 commit 6da745b

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,10 +2268,6 @@ object desugar {
22682268
Annotated(
22692269
AppliedTypeTree(ref(defn.SeqType), t),
22702270
New(ref(defn.RepeatedAnnot.typeRef), Nil :: Nil))
2271-
else if op.name == nme.CC_REACH then
2272-
Annotated(t, New(ref(defn.ReachCapabilityAnnot.typeRef), Nil :: Nil))
2273-
else if op.name == nme.CC_READONLY then
2274-
Annotated(t, New(ref(defn.ReadOnlyCapabilityAnnot.typeRef), Nil :: Nil))
22752271
else
22762272
assert(ctx.mode.isExpr || ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), ctx.mode)
22772273
Select(t, op.name)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
550550
annot.putAttachment(RetainsAnnot, ())
551551
Annotated(parent, annot)
552552

553+
def makeReachAnnot()(using Context): Tree =
554+
New(ref(defn.ReachCapabilityAnnot.typeRef), Nil :: Nil)
555+
556+
def makeReadOnlyAnnot()(using Context): Tree =
557+
New(ref(defn.ReadOnlyCapabilityAnnot.typeRef), Nil :: Nil)
558+
553559
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(using Context): DefDef =
554560
DefDef(nme.CONSTRUCTOR, joinParams(tparams, vparamss), TypeTree(), rhs)
555561

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ object StdNames {
120120
val BITMAP_TRANSIENT: N = s"${BITMAP_PREFIX}trans$$" // initialization bitmap for transient lazy vals
121121
val BITMAP_CHECKINIT: N = s"${BITMAP_PREFIX}init$$" // initialization bitmap for checkinit values
122122
val BITMAP_CHECKINIT_TRANSIENT: N = s"${BITMAP_PREFIX}inittrans$$" // initialization bitmap for transient checkinit values
123-
val CC_REACH: N = "$reach"
124-
val CC_READONLY: N = "$readOnly"
125123
val DEFAULT_GETTER: N = str.DEFAULT_GETTER
126124
val DEFAULT_GETTER_INIT: N = "$lessinit$greater"
127125
val DO_WHILE_PREFIX: N = "doWhile$"

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,20 +1593,20 @@ object Parsers {
15931593
*/
15941594
def captureRef(): Tree =
15951595

1596-
def derived(ref: Tree, name: TermName) =
1596+
def derived(ref: Tree, ann: () => Tree) =
15971597
in.nextToken()
1598-
atSpan(startOffset(ref)) { PostfixOp(ref, Ident(name)) }
1598+
atSpan(startOffset(ref)) { Annotated(ref, ann()) }
15991599

16001600
def recur(ref: Tree): Tree =
16011601
if in.token == DOT then
16021602
in.nextToken()
1603-
if in.isIdent(nme.rd) then derived(ref, nme.CC_READONLY)
1603+
if in.isIdent(nme.rd) then derived(ref, makeReadOnlyAnnot)
16041604
else recur(selector(ref))
16051605
else if in.isIdent(nme.raw.STAR) then
1606-
val reachRef = derived(ref, nme.CC_REACH)
1606+
val reachRef = derived(ref, makeReachAnnot)
16071607
if in.token == DOT && in.lookahead.isIdent(nme.rd) then
16081608
in.nextToken()
1609-
derived(reachRef, nme.CC_READONLY)
1609+
derived(reachRef, makeReadOnlyAnnot)
16101610
else reachRef
16111611
else ref
16121612

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,12 +762,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
762762
val opPrec = parsing.precedence(op.name)
763763
changePrec(opPrec) { toText(l) ~ " " ~ toText(op) ~ " " ~ toText(r) }
764764
case PostfixOp(l, op) =>
765-
if op.name == nme.CC_REACH then
766-
changePrec(DotPrec) { toText(l) ~ "*" }
767-
else if op.name == nme.CC_READONLY then
768-
changePrec(DotPrec) { toText(l) ~ ".rd" }
769-
else
770-
changePrec(InfixPrec) { toText(l) ~ " " ~ toText(op) }
765+
changePrec(InfixPrec) { toText(l) ~ " " ~ toText(op) }
771766
case PrefixOp(op, r) =>
772767
changePrec(DotPrec) { toText(op) ~ " " ~ toText(r) }
773768
case Parens(t) =>

0 commit comments

Comments
 (0)