@@ -33,8 +33,6 @@ object CheckCaptures:
3333 case NestedInOwner // environment is a temporary one nested in the owner's environment,
3434 // and does not have a different actual owner symbol
3535 // (this happens when doing box adaptation).
36- case ClosureResult // environment is for the result of a closure,
37- // used only under ccConfig.DropOuterUsesInCurried
3836 case Boxed // environment is inside a box (in which case references are not counted)
3937
4038 /** A class describing environments.
@@ -182,11 +180,6 @@ object CheckCaptures:
182180 if ccConfig.useSealed then check.traverse(tp)
183181 end disallowRootCapabilitiesIn
184182
185- /** Attachment key for bodies of closures, provided they are values.
186- * Used only under ccConfig.DropOuterUsesInCurried
187- */
188- val ClosureBodyValue = Property .Key [Unit ]
189-
190183 /** A prototype that indicates selection with an immutable value */
191184 class PathSelectionProto (val sym : Symbol , val pt : Type )(using Context ) extends WildcardSelectionProto
192185
@@ -334,20 +327,13 @@ class CheckCaptures extends Recheck, SymTransformer:
334327
335328 /** The next environment enclosing `env` that needs to be charged
336329 * with free references.
337- * Skips environments directly enclosing environments of kind ClosureResult.
338330 * @param included Whether an environment is included in the range of
339331 * environments to charge. Once `included` is false, no
340332 * more environments need to be charged.
341333 */
342334 def nextEnvToCharge (env : Env , included : Env => Boolean )(using Context ): Env =
343- var nextEnv = env.outer
344- if env.owner.isConstructor then
345- if included(nextEnv) then nextEnv = nextEnv.outer
346- if env.kind == EnvKind .ClosureResult then
347- // skip this one
348- nextEnvToCharge(nextEnv, included)
349- else
350- nextEnv
335+ if env.owner.isConstructor && included(env.outer) then env.outer.outer
336+ else env.outer
351337
352338 /** A description where this environment comes from */
353339 private def provenance (env : Env )(using Context ): String =
@@ -741,15 +727,6 @@ class CheckCaptures extends Recheck, SymTransformer:
741727 .showing(i " rechecked closure $tree / $pt = $result" , capt)
742728
743729 override def recheckClosureBlock (mdef : DefDef , expr : Closure , pt : Type )(using Context ): Type =
744- mdef.rhs match
745- case rhs @ closure(_, _, _) if ccConfig.DropOuterUsesInCurried =>
746- // In a curried closure `x => y => e` don't leak capabilities retained by
747- // the second closure `y => e` into the first one. This is an approximation
748- // of the CC rule which says that a closure contributes captures to its
749- // environment only if a let-bound reference to the closure is used.
750- mdef.rhs.putAttachment(ClosureBodyValue , ())
751- case _ =>
752-
753730 openClosures = (mdef.symbol, pt) :: openClosures
754731 try
755732 // Constrain closure's parameters and result from the expected type before
@@ -997,8 +974,6 @@ class CheckCaptures extends Recheck, SymTransformer:
997974 tree match
998975 case _ : RefTree | closureDef(_) if pt.isBoxedCapturing =>
999976 curEnv = Env (curEnv.owner, EnvKind .Boxed , CaptureSet .Var (curEnv.owner, level = currentLevel), curEnv)
1000- case _ if tree.hasAttachment(ClosureBodyValue ) =>
1001- curEnv = Env (curEnv.owner, EnvKind .ClosureResult , CaptureSet .Var (curEnv.owner, level = currentLevel), curEnv)
1002977 case _ =>
1003978 val res =
1004979 try
0 commit comments