Skip to content

Commit 3674c7f

Browse files
committed
Classify SharedCapabilities as non-exclusive
1 parent a737c80 commit 3674c7f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,12 @@ object Capabilities:
434434

435435
/** An exclusive capability is a capability that derives
436436
* indirectly from a maximal capability without going through
437-
* a read-only capability first.
437+
* a read-only capability or a capability classified as SharedCapability first.
438438
*/
439439
final def isExclusive(using Context): Boolean =
440-
!isReadOnly && (isTerminalCapability || captureSetOfInfo.isExclusive)
440+
!isReadOnly
441+
&& !classifier.isSubClass(defn.Caps_SharedCapability)
442+
&& (isTerminalCapability || captureSetOfInfo.isExclusive)
441443

442444
/** Similar to isExlusive, but also includes capabilties with capture
443445
* set variables in their info whose status is still open.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import language.experimental.captureChecking
2+
import language.experimental.separationChecking
3+
import caps.*
4+
class Logger extends SharedCapability:
5+
def log(msg: String): Unit = ()
6+
class TracedRef(logger: Logger^{cap.only[SharedCapability]}) extends Mutable:
7+
private var _data: Int = 0
8+
update def set(newValue: Int): Unit =
9+
logger.log("set")
10+
_data = newValue
11+
def get: Int =
12+
logger.log("get") // error, but should it be allowed?
13+
_data
14+
15+
class TracedRef2(logger: Logger) extends Mutable:
16+
private var _data: Int = 0
17+
update def set(newValue: Int): Unit =
18+
logger.log("set")
19+
_data = newValue
20+
def get: Int =
21+
logger.log("get") // error, but should it be allowed?
22+
_data

0 commit comments

Comments
 (0)