Skip to content

Commit a90c32a

Browse files
committed
Drop code supporting previous unsound scheme for curried lambdas
1 parent 1a781b2 commit a90c32a

File tree

3 files changed

+3
-31
lines changed

3 files changed

+3
-31
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ object ccConfig:
4040
*/
4141
inline val handleEtaExpansionsSpecially = false
4242

43-
/** If enabled we drop inner uses in outer arrows of a curried function */
44-
inline val DropOuterUsesInCurried = false
45-
4643
/** If true, use existential capture set variables */
4744
def useExistentials(using Context) =
4845
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.5`)

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

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
306306
case _ => res
307307
)
308308
val fntpe = defn.PolyFunctionOf(mt)
309-
if !encl.isEmpty && (!ccConfig.DropOuterUsesInCurried || resDecomposed.isEmpty) then
309+
if !encl.isEmpty then
310310
val cs = CaptureSet(encl.map(_.paramRefs.head)*)
311311
CapturingType(fntpe, cs, boxed = false)
312312
else fntpe

0 commit comments

Comments
 (0)