-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Introduce Maybe Capabilities #19500
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
Merged
Merged
Introduce Maybe Capabilities #19500
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b860100
Avoid forming intersections for dependent function types
odersky 11aabcf
Introduce maybe capabilities x?
odersky 8240523
Treat result of by-name closures as inferred
odersky 16cae11
Update scala2-library-cc to make use of inference fixes
odersky 6e7f5be
Make all closure results inferred types
odersky 2e0cf2e
Make maybeCapability a compiler-generated symbol without source
odersky 4cd72b7
Fix using source comment
odersky 3ef2514
Fix comments
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,9 +220,31 @@ extension (tp: Type) | |
* type of `x`. If `x` and `y` are different variables then `{x*}` and `{y*}` | ||
* are unrelated. | ||
*/ | ||
def reach(using Context): CaptureRef = | ||
assert(tp.isTrackableRef) | ||
AnnotatedType(tp, Annotation(defn.ReachCapabilityAnnot, util.Spans.NoSpan)) | ||
def reach(using Context): CaptureRef = tp match | ||
case tp: CaptureRef if tp.isTrackableRef => | ||
if tp.isReach then tp else ReachCapability(tp) | ||
|
||
/** If `x` is a capture ref, its maybe capability `x?`, represented internally | ||
* as `x @maybeCapability`. `x?` stands for a capability `x` that might or might | ||
* not be part of a capture set. We have `{} <: {x?} <: {x}`. Maybe capabilities | ||
* cannot be propagated between sets. If `a <: b` and `a` acquires `x?` then | ||
* `x` is propagated to `b` as a conservative approximation. | ||
* | ||
* Maybe capabilities should only arise for caoture sets that appear in invariant | ||
* position in their surrounding type. They are similar to TypeBunds types, but | ||
* restricted to capture sets. For instance, | ||
* | ||
* Array[C^{x?}] | ||
* | ||
* should be morally equivaelent to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: "equivalent" |
||
* | ||
* Array[_ >: C^{} <: C^{x}] | ||
* | ||
* but it has fewer issues with type inference. | ||
*/ | ||
def maybe(using Context): CaptureRef = tp match | ||
case tp: CaptureRef if tp.isTrackableRef => | ||
if tp.isMaybe then tp else MaybeCapability(tp) | ||
|
||
/** If `ref` is a trackable capture ref, and `tp` has only covariant occurrences of a | ||
* universal capture set, replace all these occurrences by `{ref*}`. This implements | ||
|
@@ -422,9 +444,14 @@ object ReachCapabilityApply: | |
/** An extractor for `ref @annotation.internal.reachCapability`, which is used to express | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation is out-dated |
||
* the reach capability `ref*` as a type. | ||
*/ | ||
object ReachCapability: | ||
class AnnotatedCapability(annot: Context ?=> ClassSymbol): | ||
def apply(tp: Type)(using Context) = | ||
AnnotatedType(tp, Annotation(annot, util.Spans.NoSpan)) | ||
def unapply(tree: AnnotatedType)(using Context): Option[SingletonCaptureRef] = tree match | ||
case AnnotatedType(parent: SingletonCaptureRef, ann) | ||
if ann.symbol == defn.ReachCapabilityAnnot => Some(parent) | ||
case AnnotatedType(parent: SingletonCaptureRef, ann) if ann.symbol == annot => Some(parent) | ||
case _ => None | ||
|
||
object ReachCapability extends AnnotatedCapability(defn.ReachCapabilityAnnot) | ||
object MaybeCapability extends AnnotatedCapability(defn.MaybeCapabilityAnnot) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "capture"