Skip to content

Commit cf3b8ae

Browse files
committed
Transform infos of all symbols defined in current run in SymTransformer
(except if they are updated). This is the first step towards converting to capturing types in SymTransformer, where we have the context.
1 parent 2ea222a commit cf3b8ae

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def allowUniversalInBoxed(using Context) =
3232
Feature.sourceVersion.isAtLeast(SourceVersion.`3.3`)
3333

3434
/** An exception thrown if a @retains argument is not syntactically a CaptureRef */
35-
class IllegalCaptureRef(tpe: Type) extends Exception
35+
class IllegalCaptureRef(tpe: Type) extends Exception(tpe.toString)
3636

3737
/** Capture checking state, which is known to other capture checking components */
3838
class CCState:

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import CaptureSet.IdentityCaptRefMap
1515
import Synthetics.isExcluded
1616
import util.Property
1717
import printing.{Printer, Texts}, Texts.{Text, Str}
18+
import collection.mutable
1819

1920
/** Operations accessed from CheckCaptures */
2021
trait SetupAPI:
@@ -74,7 +75,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
7475
override def isRunnable(using Context) =
7576
super.isRunnable && Feature.ccEnabledSomewhere
7677

77-
def newFlagsFor(symd: SymDenotation)(using Context): FlagSet =
78+
private val toBeUpdated = new mutable.HashSet[Symbol]
79+
80+
private def newFlagsFor(symd: SymDenotation)(using Context): FlagSet =
7881
if symd.isAllOf(PrivateParamAccessor) && symd.owner.is(CaptureChecked) && !symd.hasAnnotation(defn.ConstructorOnlyAnnot)
7982
then symd.flags &~ Private | Recheck.ResetPrivate
8083
else symd.flags
@@ -89,7 +92,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
8992
def needsInfoTransform = newScheme || symd.isGetter
9093
if !pastRecheck && Feature.ccEnabledSomewhere then
9194
val sym = symd.symbol
92-
atPhase(thisPhase.next)(symd.maybeOwner.info) // ensure owner is completed
95+
val needsInfoTransform = sym.isDefinedInCurrentRun && !toBeUpdated.contains(sym)
9396
// if sym is class && level owner: add a capture root
9497
// translate cap/capIn to local roots
9598
// create local roots if necessary
@@ -98,15 +101,17 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
98101
else if symd.owner.isTerm || symd.is(CaptureChecked) || symd.owner.is(CaptureChecked) then
99102
val newFlags = newFlagsFor(symd)
100103
val newInfo =
101-
if needsInfoTransform
102-
then transformExplicitType(sym.info, rootTarget = if newScheme then sym else NoSymbol)
104+
if needsInfoTransform then
105+
atPhase(thisPhase.next)(symd.maybeOwner.info) // ensure owner is completed
106+
transformExplicitType(sym.info, rootTarget = if newScheme then sym else NoSymbol)
103107
else sym.info
104108

105109
if newFlags != symd.flags || (newInfo ne sym.info)
106110
then symd.copySymDenotation(initFlags = newFlags, info = newInfo)
107111
else symd
108112
else symd
109113
else symd
114+
end transformSym
110115

111116
/** Create dependent function with underlying function class `tycon` and given
112117
* arguments `argTypes` and result `resType`.
@@ -404,7 +409,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
404409

405410
/** Update info of `sym` for CheckCaptures phase only */
406411
private def updateInfo(sym: Symbol, info: Type)(using Context) =
412+
toBeUpdated += sym
407413
sym.updateInfo(thisPhase, info, newFlagsFor(sym))
414+
toBeUpdated -= sym
408415
sym.namedType match
409416
case ref: CaptureRef => ref.invalidateCaches() // TODO: needed?
410417
case _ =>
@@ -514,7 +521,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
514521
else tree.tpt.knownType
515522

516523
def paramSignatureChanges = tree.match
517-
case tree: DefDef => tree.termParamss.nestedExists(_.tpt.hasRememberedType)
524+
case tree: DefDef => tree.paramss.nestedExists:
525+
case param: ValDef => param.tpt.hasRememberedType
526+
case param: TypeDef => param.rhs.hasRememberedType
518527
case _ => false
519528

520529
def signatureChanges =

0 commit comments

Comments
 (0)