@@ -36,8 +36,6 @@ object CheckCaptures:
36
36
case NestedInOwner // environment is a temporary one nested in the owner's environment,
37
37
// and does not have a different actual owner symbol
38
38
// (this happens when doing box adaptation).
39
- case ClosureResult // environment is for the result of a closure,
40
- // used only under ccConfig.DropOuterUsesInCurried
41
39
case Boxed // environment is inside a box (in which case references are not counted)
42
40
43
41
/** A class describing environments.
@@ -185,11 +183,6 @@ object CheckCaptures:
185
183
if ccConfig.useSealed then check.traverse(tp)
186
184
end disallowRootCapabilitiesIn
187
185
188
- /** Attachment key for bodies of closures, provided they are values.
189
- * Used only under ccConfig.DropOuterUsesInCurried
190
- */
191
- val ClosureBodyValue = Property .Key [Unit ]
192
-
193
186
/** A prototype that indicates selection with an immutable value */
194
187
class PathSelectionProto (val sym : Symbol , val pt : Type )(using Context ) extends WildcardSelectionProto
195
188
@@ -339,20 +332,13 @@ class CheckCaptures extends Recheck, SymTransformer:
339
332
340
333
/** The next environment enclosing `env` that needs to be charged
341
334
* with free references.
342
- * Skips environments directly enclosing environments of kind ClosureResult.
343
335
* @param included Whether an environment is included in the range of
344
336
* environments to charge. Once `included` is false, no
345
337
* more environments need to be charged.
346
338
*/
347
339
def nextEnvToCharge (env : Env , included : Env => Boolean )(using Context ): Env =
348
- var nextEnv = env.outer
349
- if env.owner.isConstructor then
350
- if included(nextEnv) then nextEnv = nextEnv.outer
351
- if env.kind == EnvKind .ClosureResult then
352
- // skip this one
353
- nextEnvToCharge(nextEnv, included)
354
- else
355
- nextEnv
340
+ if env.owner.isConstructor && included(env.outer) then env.outer.outer
341
+ else env.outer
356
342
357
343
/** A description where this environment comes from */
358
344
private def provenance (env : Env )(using Context ): String =
@@ -746,15 +732,6 @@ class CheckCaptures extends Recheck, SymTransformer:
746
732
.showing(i " rechecked closure $tree / $pt = $result" , capt)
747
733
748
734
override def recheckClosureBlock (mdef : DefDef , expr : Closure , pt : Type )(using Context ): Type =
749
- mdef.rhs match
750
- case rhs @ closure(_, _, _) if ccConfig.DropOuterUsesInCurried =>
751
- // In a curried closure `x => y => e` don't leak capabilities retained by
752
- // the second closure `y => e` into the first one. This is an approximation
753
- // of the CC rule which says that a closure contributes captures to its
754
- // environment only if a let-bound reference to the closure is used.
755
- mdef.rhs.putAttachment(ClosureBodyValue , ())
756
- case _ =>
757
-
758
735
openClosures = (mdef.symbol, pt) :: openClosures
759
736
try
760
737
// Constrain closure's parameters and result from the expected type before
@@ -1002,8 +979,6 @@ class CheckCaptures extends Recheck, SymTransformer:
1002
979
tree match
1003
980
case _ : RefTree | closureDef(_) if pt.isBoxedCapturing =>
1004
981
curEnv = Env (curEnv.owner, EnvKind .Boxed , CaptureSet .Var (curEnv.owner, level = currentLevel), curEnv)
1005
- case _ if tree.hasAttachment(ClosureBodyValue ) =>
1006
- curEnv = Env (curEnv.owner, EnvKind .ClosureResult , CaptureSet .Var (curEnv.owner, level = currentLevel), curEnv)
1007
982
case _ =>
1008
983
val res =
1009
984
try
0 commit comments