Skip to content

Commit e554ca5

Browse files
committed
New flag -Ycc-no-tasty drops capture checking annotations from TASTy
1 parent a9c214f commit e554ca5

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ object Feature:
137137
enabledBySetting(captureChecking)
138138
|| ctx.originalCompilationUnit.needsCaptureChecking
139139

140+
/** Are capture-checking annotations emitted in the resulting TASTy tree? */
141+
def ccAnnotationsEnabled(using Context) =
142+
ccEnabled && !ctx.settings.YccNoTasty.value
143+
140144
/** Is pureFunctions enabled for any of the currently compiled compilation units? */
141145
def pureFunsEnabledSomewhere(using Context) =
142146
enabledBySetting(pureFunctions)

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ private sealed trait YSettings:
459459
val YccLog: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycc-log", "Used in conjunction with captureChecking language import, print tracing and debug info")
460460
val YccVerbose: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycc-verbose", "Print root capabilities with more details")
461461
val YccPrintSetup: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycc-print-setup", "Used in conjunction with captureChecking language import, print trees after cc.Setup phase")
462+
val YccNoTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycc-no-tasty", "Used in conjunction with captureChecking language import, do not emit captureChecking-related TASTy annotations")
462463

463464
/** Area-specific debug output */
464465
val YexplainLowlevel: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,21 @@ class Definitions {
11461146
"reactor.util.annotation.NonNullApi" ::
11471147
"io.reactivex.annotations.NonNull" :: Nil)
11481148

1149+
// Capture checking annotations
1150+
@tu lazy val CCAnnots: Set[ClassSymbol] = Set(
1151+
ReachCapabilityAnnot,
1152+
RootCapabilityAnnot,
1153+
ReadOnlyCapabilityAnnot,
1154+
OnlyCapabilityAnnot,
1155+
RequiresCapabilityAnnot,
1156+
RetainsAnnot,
1157+
RetainsCapAnnot,
1158+
RetainsByNameAnnot,
1159+
RetainsArgAnnot,
1160+
UseAnnot,
1161+
)
1162+
1163+
11491164
// convenient one-parameter method types
11501165
def methOfAny(tp: Type): MethodType = MethodType(List(AnyType), tp)
11511166
def methOfAnyVal(tp: Type): MethodType = MethodType(List(AnyValType), tp)

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import collection.mutable
2020
import reporting.{Profile, NoProfile}
2121
import dotty.tools.tasty.TastyFormat.ASTsSection
2222
import quoted.QuotePatterns
23+
import dotty.tools.dotc.config.Feature
2324

2425
object TreePickler:
2526
class StackSizeExceeded(val mdef: tpd.MemberDef) extends Exception
@@ -282,9 +283,11 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
282283
pickleVariances(tpe.hi)
283284
}
284285
case tpe: AnnotatedType =>
285-
writeByte(ANNOTATEDtype)
286-
withLength { pickleType(tpe.parent, richTypes); pickleTree(tpe.annot.tree) }
287-
annotatedTypeTrees += tpe.annot.tree
286+
if !isSkippedCCAnnot(tpe.annot) then
287+
writeByte(ANNOTATEDtype)
288+
withLength { pickleType(tpe.parent, richTypes); pickleTree(tpe.annot.tree) }
289+
annotatedTypeTrees += tpe.annot.tree
290+
else pickleType(tpe.parent, richTypes)
288291
case tpe: AndType =>
289292
writeByte(ANDtype)
290293
withLength { pickleType(tpe.tp1, richTypes); pickleType(tpe.tp2, richTypes) }
@@ -749,8 +752,10 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
749752
writeByte(BYNAMEtpt)
750753
pickleTree(tp)
751754
case Annotated(tree, annot) =>
752-
writeByte(ANNOTATEDtpt)
753-
withLength { pickleTree(tree); pickleTree(annot) }
755+
if !isSkippedCCAnnot(annot.symbol) then
756+
writeByte(ANNOTATEDtpt)
757+
withLength { pickleTree(tree); pickleTree(annot) }
758+
else pickleTree(tree)
754759
case LambdaTypeTree(tparams, body) =>
755760
writeByte(LAMBDAtpt)
756761
withLength { pickleParams(tparams); pickleTree(body) }
@@ -927,8 +932,16 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
927932
ann.symbol == defn.BodyAnnot // inline bodies are reconstituted automatically when unpickling
928933
}
929934

935+
private def isSkippedCCAnnot(ann: Annotation)(using Context): Boolean = isSkippedCCAnnot(ann.symbol)
936+
private def isSkippedCCAnnot(ann: Symbol)(using Context): Boolean =
937+
if Feature.ccEnabled && !Feature.ccAnnotationsEnabled then
938+
// an annotation symbol can be either a class symbol or a constructor symbol
939+
val ccAnnot = defn.CCAnnots.find(annot => annot == ann || annot.primaryConstructor == ann)
940+
ccAnnot.isDefined
941+
else false
942+
930943
def pickleAnnotation(owner: Symbol, mdef: MemberDef, ann: Annotation)(using Context): Unit =
931-
if !isUnpicklable(owner, ann) then
944+
if !isUnpicklable(owner, ann) && !isSkippedCCAnnot(ann) then
932945
writeByte(ANNOTATION)
933946
withLength { pickleType(ann.symbol.typeRef); pickleTree(ann.tree) }
934947
var treeBuf = annotTrees.lookup(mdef)

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class Pickler extends Phase {
293293
sourceFile = sourceRelativePath,
294294
scala2StandardLibrary = Feature.shouldBehaveAsScala2,
295295
explicitNulls = ctx.settings.YexplicitNulls.value,
296-
captureChecked = Feature.ccEnabled,
296+
captureChecked = Feature.ccEnabled && Feature.ccAnnotationsEnabled,
297297
withPureFuns = Feature.pureFunsEnabled,
298298
isJava = isJavaAttr,
299299
isOutline = isOutline

0 commit comments

Comments
 (0)