Skip to content

Commit 17a4a8c

Browse files
committed
Stop markFree at nested methods
Use sets of nested methods are anyway charged on call.
1 parent 2747f03 commit 17a4a8c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ class CheckCaptures extends Recheck, SymTransformer:
365365
else
366366
i"\nof the enclosing ${owner.showLocated}"
367367

368+
def isOfNestedMethod(env: Env | Null)(using Context) =
369+
env != null
370+
&& env.owner.is(Method)
371+
&& env.owner.owner.isTerm
372+
&& !env.owner.isAnonymousFunction
373+
368374
/** Include `sym` in the capture sets of all enclosing environments nested in the
369375
* the environment in which `sym` is defined.
370376
*/
@@ -377,7 +383,8 @@ class CheckCaptures extends Recheck, SymTransformer:
377383
if env.isOpen && env.owner != sym.enclosure then
378384
capt.println(i"Mark $sym with cs ${ref.captureSet} free in ${env.owner}")
379385
checkElem(ref, env.captured, pos, provenance(env))
380-
recur(nextEnvToCharge(env, _.owner != sym.enclosure))
386+
if !isOfNestedMethod(env) then
387+
recur(nextEnvToCharge(env, _.owner != sym.enclosure))
381388
recur(curEnv)
382389

383390
/** Make sure (projected) `cs` is a subset of the capture sets of all enclosing
@@ -438,7 +445,8 @@ class CheckCaptures extends Recheck, SymTransformer:
438445
isVisible
439446
checkSubset(included, env.captured, pos, provenance(env))
440447
capt.println(i"Include call or box capture $included from $cs in ${env.owner} --> ${env.captured}")
441-
recur(included, nextEnvToCharge(env, !_.owner.isStaticOwner))
448+
if !isOfNestedMethod(env) then
449+
recur(included, nextEnvToCharge(env, !_.owner.isStaticOwner))
442450
recur(cs, curEnv)
443451
end markFree
444452

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,20 @@ import dotty.tools.dotc.util.NoSourcePosition
2323
/** Operations accessed from CheckCaptures */
2424
trait SetupAPI:
2525
type DefRecheck = (tpd.ValOrDefDef, Symbol) => Context ?=> Type
26+
27+
/** Setup procedure to run for each compilation unit
28+
* @param tree the typed tree of the unit to check
29+
* @param recheckDef the recheck method to run on completion of symbols with
30+
* inferred (result-) types
31+
*/
2632
def setupUnit(tree: Tree, recheckDef: DefRecheck)(using Context): Unit
33+
34+
/** Symbol is a term member of a class that was not capture checked
35+
* The info of these symbols is made fluid.
36+
*/
2737
def isPreCC(sym: Symbol)(using Context): Boolean
38+
39+
/** Check to do after the capture checking traversal */
2840
def postCheck()(using Context): Unit
2941

3042
object Setup:

0 commit comments

Comments
 (0)