-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Copy @use
and @consume
annotations to parameter types
#23324
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?
Conversation
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.
Pull Request Overview
This PR ensures that the @use and @consume annotations on parameter symbols are correctly copied to their parameter types so that they persist after tree copying. Key changes include:
- Updating error messages and test expectations in negative test cases.
- Modifying printers and type handling code to include the new annotations.
- Adjusting capture checking and transformation logic to accommodate the copied annotations.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/pos-custom-args/captures/cc-use-iterable.scala | Adds persistence of annotations in Iterable methods. |
tests/neg-custom-args/captures/unsound-reach-4.check | Updates expected error messages to reflect the annotations. |
tests/neg-custom-args/captures/unbox-overrides.check | Adjusts error messages in override scenarios. |
tests/neg-custom-args/captures/leak-problem-unboxed.scala | Reflects changes in function reference resolution. |
tests/neg-custom-args/captures/cc-annot-value-classes2.scala | Updates value class tests for annotation correctness. |
tests/neg-custom-args/captures/cc-annot-value-classes.scala | Updates tests regarding annotation use in value classes. |
compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala | Updates printing logic to include the new annotations. |
compiler/src/dotty/tools/dotc/core/Types.scala | Implements copying of @use and @consume annotations. |
compiler/src/dotty/tools/dotc/core/Definitions.scala | Adds the new annotations to silent annotations. |
compiler/src/dotty/tools/dotc/cc/SepCheck.scala | Updates capture checking to refer to the new isConsumeParam check. |
compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala | Refines annotation propagation and handling in capture checking. |
compiler/src/dotty/tools/dotc/cc/CaptureOps.scala | Adds methods for dropping and checking the new annotations. |
Comments suppressed due to low confidence (1)
compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala:381
- [nitpick] Consider revising the documentation comment for grammatical correctness. For example, change 'the annotation that are meant' to 'the annotations that are meant' and 'but was moved' to 'but were moved'.
/** Print the annotation that are meant to be on the parameter symbol but was moved
|| sym.is(TypeParam) | ||
&& sym.owner.rawParamss.nestedExists: param => | ||
param.is(TermParam) && param.hasAnnotation(defn.UseAnnot) | ||
&& param.info.deepCaptureSet.elems.exists: | ||
case c: TypeRef => c.symbol == sym | ||
case _ => false | ||
|
||
/** `sym` or its info is annotated with `@consume`. */ | ||
def isConsumeParam(using Context): Boolean = |
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.
Do we need the sym.hasAnnotation(...)
part? If not it's better to remove that clause.
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.
I tried to drop the check but the tests failed. I think we still need it because there are cases when we check whether a symbol is declared @use
(or @consume
) that comes directly from the original method, whose info is not adapted by the new logic.
@@ -490,18 +493,24 @@ extension (sym: Symbol) | |||
def hasTrackedParts(using Context): Boolean = | |||
!CaptureSet.ofTypeDeeply(sym.info).isAlwaysEmpty | |||
|
|||
/** `sym` is annotated @use or it is a type parameter with a matching | |||
/** `sym` itself or its info is annotated @use or it is a type parameter with a matching | |||
* @use-annotated term parameter that contains `sym` in its deep capture set. | |||
*/ | |||
def isUseParam(using Context): Boolean = | |||
sym.hasAnnotation(defn.UseAnnot) |
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.
Do we still need the sym.hasAnnotation(...)
part? If not it's better to remove that clause.
... so that they will persist after tree copying.
fixes #23302.