-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Changes to Mutable #24352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes to Mutable #24352
Conversation
d8ec775 to
676b85f
Compare
2bc9435 to
d40f1f9
Compare
|
I am playing with this PR, and found the following code compile: import language.experimental.captureChecking
import language.experimental.separationChecking
import caps.*
class Logger extends SharedCapability, Mutable: // (1) does this make sense?
private var _state: Int = 0
update def log(msg: String): Unit = ()
def onlyShared(x: Object^{cap.only[SharedCapability]}): Unit = ()
def main(): Unit =
onlyShared(Logger()) // even if we allow (1), why would this type check?
val t: Logger^{} = Logger() // and this type checks too, thus the above line I guess
|
|
We currently have deep problems with Mutables carrying the empty capture set. I am trying to fix them but it turns out it's not easy. Also, no probably combining SharedCapability and Mutable should be forbidden. |
|
Another example: import language.experimental.captureChecking
import language.experimental.separationChecking
import caps.*
class Logger extends SharedCapability:
def log(msg: String): Unit = ()
class TracedRef(logger: Logger^{cap.only[SharedCapability]}) extends Mutable:
private var _data: Int = 0
update def set(newValue: Int): Unit =
logger.log("set")
_data = newValue
def get: Int =
logger.log("get") // error, but should it be allowed?
_dataRight now using a shared capability in a non-update method inside a |
This might be conflicting, since it would mean a However from a practical point of view I agree we should exempt this case |
bdecf4b to
acf9df6
Compare
acf9df6 to
e853b59
Compare
1. Mutable and ExclsuiveCapability are not longer classifiers. This means
Mutable classes can capture other capabilities. Red is still a classifier.
2. Update methods in nested classes can access exclsuive capabilities external
to enclosing classes.
- Allow to charge read-only set on unboxing (previously it was always the exclusive set that was charged). - Treat also methods outside Mutable types as read-only members. Previously we charged read-only when calling a read-only method of a mutable type, but not when calling an inherited method such as `eq`. - Use the same criterion for read-only everywhere. - Distinguish between read- and write-accesses to mutable fields.
…hecking We do get sometimes capabilities like `async.rd` where `async` is shared. It does not look straightforward to prevent that, so instead we count async.rd as shared if async is.
We need a way to distinguish C^{} and C^{cap} when printing. We
print C^{cap} as C is C is a capability class.
This fix removed quite a few spurious error notes.
Needed to invalidate the relation
C^{} <: C^
for Mutable types C
- New section in separation checking doc page - Slight generalization of expectsReadOnly - Lots of tests variations of scala#24373
e853b59 to
ae58dc2
Compare
We erroneously used Mutable as a classifier when calculating the implied capture set of a constructor.
Mutable and ExclsuiveCapability are not longer classifiers. This means Mutable classes can capture other capabilities. Read is still a classifier.
Update methods in nested classes can access exclusive capabilities external to enclosing classes.