- Notifications
You must be signed in to change notification settings - Fork1.1k
Classifying capabilities#23463
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
The motivation for this is to come up with a type for objectTry:defapply[T](body:=>T):Try[T]^{???} The The problem is we are lacking a way to express those control capability slices, nor do we have a way to reason about them (i.e. know which ones subsume which other ones, or which ones can be discarded). The idea is to add a new kind of capability acting as a filter. If traitControlextendsClassifierCapability that is a base class of control capability classes such as objectTry:defapply[T](body:=>T):Try[T]^{body.only[Control]}
We now need to develop subsumption rules for filtered-capabilities. We clearly should have What about the other combinations? When is Another issue is how to detect disjointness. For instance, a particular operation op: ()->{lbl, m}Unit What is the type of Try[Unit]^{op.only[Control]} Replacing Try.apply(op()):Try[Unit]^{lbl} To get there, we introduce classifier capability classes. These are classes (or traits) that declare traitSharedCapabilityextendsClassifierCapabilitytraitControlextendsClassifierCapability,SharedCapabilitytraitMutableextendsClassifierCapability A class can not directly or indirectly extend two unrelated classifier capability classes. Now, looking at subsumption rules, we first need this one: if Definition Definition Thetransitive capture set Definition A capability
To make this sound, we have to restrict possible values of Example because the Furthermore, we have if So because |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 8 comments 1 reply
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
What this mans for the implementation
|
BetaWas this translation helpful?Give feedback.
All reactions
-
WIP PR is#23485 |
BetaWas this translation helpful?Give feedback.
All reactions
-
This looks like a lot of machinery to typecheck |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
One possible generalization would be to have besides |
BetaWas this translation helpful?Give feedback.
All reactions
-
One possible simplification is to specialize the treatment to control capabilites:
This would make sense if we can convince ourselves that the only capability masking operations we envision mask specifically control capabilities. Can we? |
BetaWas this translation helpful?Give feedback.
All reactions
-
One observation: [C<: {cap.as[Mutable]}]// all elements of the set must be transitively `Mutable`. [C<: {cap.as[Sharable]}// all elements of the set must be transitively `Sharable`. [C<: {cap.as[Control]}// all elements of the set must be transitively `Control` capabilties. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
And it is convenient to restrict capabilities of function types. For instance, when doing separation checking we might want to accept only functions over sharable capabilities. This can now be expressed: A->{cap.as[Sharable]}B We could probably make this nicer by defining capture set aliases: typesharable^= {cap.as[Sharable]}A->{sharable}B @bracevac Do you think this would work? Overall I am coming to believe that this is a fundamental addition to capture checking that solves multiple expressiveness problems we had so far. So I tend to think we should do a trial implementation. |
BetaWas this translation helpful?Give feedback.
All reactions
👀 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Maybe we need a more expressive language for what can go into an |
BetaWas this translation helpful?Give feedback.
All reactions
-
This is a mechanism that enables limiting what can be closed over up to a certain threshold, which is very useful. Without it, the next best thing one could do in the current system is using some form of branding through a variable in context (like we tried with the sub-regions example), but it's quite awkward and I don't think it scales well. Classifiers seem to be less ad hoc, and it'd be good if we allowed users to extend the classifier hierarchy. Ithink classifiers subsume the advanced use cases from the2nd-class values works. With finer-grainedclosure up to, we can emulate, e.g., Fig. 7 in the paper I linked: @classifiertraitReadextendsCapability@classifiertraitReadWriteextendsCapabilitytraitFileextendsCapability:typeR<:ReadtypeRW<:ReadWritegivenr:Rgivenrw:RW// operations guarded by capability membersdefread(usingthis.R):Bytedefwrite(usingthis.RW)(b:Byte):UnitdefwithFile[U](block:File^=>U):U// unrestricted use of files & other capabilitiesdefparReduce[U](xs:Seq[U])(op:U->{cap.only[Read]}U):U// only Read-classified allowedwithFile("foo.txt"): f=> parReduce(1 to1000): (a, b)=> f.write(a)// error ReadWrite is excluded a+ b+ f.read()// ok f.write(0x42)// ok access unrestricted We can understand the proposed forms in terms of set operations involving transitive capture closure, However, the E.g., // File1.scala:// Here, the universe of classifiers consists of the standard ones: Shareable, Mutable, ControldefmkPure(f: ()->{cap.except[Shareable,Mutable,Control]Unit): ()->{}Unit= f// everything except all the known classifiers means nothing, so we are "pure" can be subverted if we extend the classifiers elsewhere: // File2.scala@classifierSneakyextendsCapabilityvals:Sneaky= ...valfakePure: ()->Unit=File1.mkPure(()=> s.boom())// ok!, since {s}.except[Shareable,Mutable,Control] = {s} |
BetaWas this translation helpful?Give feedback.