Skip to content

Commit 70074c4

Browse files
committed
Address review comments
1 parent b0c9b3d commit 70074c4

File tree

7 files changed

+17
-21
lines changed

7 files changed

+17
-21
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ object ccConfig:
5353
Feature.sourceVersion.stable != SourceVersion.`3.5`
5454

5555
/** If true, turn on separation checking */
56-
def useFresh(using Context): Boolean =
56+
def useSepChecks(using Context): Boolean =
5757
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.7`)
5858

5959
end ccConfig

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import CaptureSet.VarState
1717

1818
/** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs,
1919
* as well as three kinds of AnnotatedTypes representing readOnly, reach, and maybe capabilities.
20-
* If there are several annotations they come with an orderL
20+
* If there are several annotations they come with an order:
2121
* `*` first, `.rd` next, `?` last.
2222
*/
2323
trait CaptureRef extends TypeProxy, ValueType:

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ class CheckCaptures extends Recheck, SymTransformer:
14871487
* The unboxed condition ensures that the expected is not a type variable
14881488
* that's upper bounded by a read-only type. In this case it would not be sound
14891489
* to narrow to the read-only set, since that set can be propagated
1490-
* by the type variable instantiatiin.
1490+
* by the type variable instantiation.
14911491
*/
14921492
private def improveReadOnly(actual: Type, expected: Type)(using Context): Type = actual match
14931493
case actual @ CapturingType(parent, refs)
@@ -1816,7 +1816,7 @@ class CheckCaptures extends Recheck, SymTransformer:
18161816
end checker
18171817

18181818
checker.traverse(unit)(using ctx.withOwner(defn.RootClass))
1819-
if ccConfig.useFresh then SepChecker(this).traverse(unit)
1819+
if ccConfig.useSepChecks then SepChecker(this).traverse(unit)
18201820
if !ctx.reporter.errorsReported then
18211821
// We dont report errors here if previous errors were reported, because other
18221822
// errors often result in bad applied types, but flagging these bad types gives

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

+5-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object Fresh:
4242
object Cap:
4343

4444
def apply(initialHidden: Refs = emptySet)(using Context): CaptureRef =
45-
if ccConfig.useFresh then
45+
if ccConfig.useSepChecks then
4646
AnnotatedType(defn.captureRoot.termRef, Annot(CaptureSet.HiddenSet(initialHidden)))
4747
else
4848
defn.captureRoot.termRef
@@ -61,20 +61,13 @@ object Fresh:
6161
class FromCap(owner: Symbol)(using Context) extends BiTypeMap, FollowAliasesMap:
6262
thisMap =>
6363

64-
var reach = false
65-
66-
private def initHidden =
67-
val ref = owner.termRef
68-
if reach then
69-
if ref.isTrackableRef then SimpleIdentitySet(ref.reach) else emptySet
70-
else
71-
if ref.isTracked then SimpleIdentitySet(ref) else emptySet
64+
private var reach = false
7265

7366
override def apply(t: Type) =
7467
if variance <= 0 then t
7568
else t match
7669
case t: CaptureRef if t.isCap =>
77-
Cap(initHidden)
70+
Cap(ownerToHidden(owner, reach))
7871
case t @ CapturingType(_, refs) =>
7972
val savedReach = reach
8073
if t.isBoxed then reach = true
@@ -103,11 +96,11 @@ object Fresh:
10396

10497
/** Maps cap to fresh */
10598
def fromCap(tp: Type, owner: Symbol = NoSymbol)(using Context): Type =
106-
if ccConfig.useFresh then FromCap(owner)(tp) else tp
99+
if ccConfig.useSepChecks then FromCap(owner)(tp) else tp
107100

108101
/** Maps fresh to cap */
109102
def toCap(tp: Type)(using Context): Type =
110-
if ccConfig.useFresh then FromCap(NoSymbol).inverse(tp) else tp
103+
if ccConfig.useSepChecks then FromCap(NoSymbol).inverse(tp) else tp
111104

112105
/** If `refs` contains an occurrence of `cap` or `cap.rd`, the current context
113106
* with an added property PrintFresh. This addition causes all occurrences of

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
432432

433433
private val paramSigChange = util.EqHashSet[Tree]()
434434

435-
/** Transform type of tree, and remember the transformed type as the type the tree
435+
/** Transform type of tree, and remember the transformed type as the type of the tree
436436
* @pre !(boxed && sym.exists)
437437
*/
438438
private def transformTT(tree: TypeTree, sym: Symbol, boxed: Boolean)(using Context): Unit =
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package scala.annotation
22
package internal
33

4-
/** An annotation used internally for fresh capability wrappers of `cap`
4+
/** An annotation used internally for fresh capability wrappers of `cap`.
5+
* A fresh capability is encoded as `caps.cap @freshCapability(...)` where
6+
* `freshCapability(...)` is a special kind of annotation of type `Fresh.Annot`
7+
* that contains a hidden set.
58
*/
69
class freshCapability extends StaticAnnotation
710

library/src/scala/caps.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import annotation.{experimental, compileTimeOnly, retainsCap}
4343
*/
4444
extension (x: Any) def reachCapability: Any = x
4545

46-
/** Unique capabilities x! which appear as terms in @retains annotations are encoded
47-
* as `caps.uniqueCapability(x)`. When converted to CaptureRef types in capture sets
48-
* they are represented as `x.type @annotation.internal.uniqueCapability`.
46+
/** Read-only capabilities x.rd which appear as terms in @retains annotations are encoded
47+
* as `caps.readOnlyCapability(x)`. When converted to CaptureRef types in capture sets
48+
* they are represented as `x.type @annotation.internal.readOnlyCapability`.
4949
*/
5050
extension (x: Any) def readOnlyCapability: Any = x
5151

0 commit comments

Comments
 (0)