Skip to content

Commit e6b08de

Browse files
committed
Drop code supporting previous unsound scheme for curried lambdas
1 parent 02cd565 commit e6b08de

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
@@ -36,8 +36,6 @@ object CheckCaptures:
3636
case NestedInOwner // environment is a temporary one nested in the owner's environment,
3737
// and does not have a different actual owner symbol
3838
// (this happens when doing box adaptation).
39-
case ClosureResult // environment is for the result of a closure,
40-
// used only under ccConfig.DropOuterUsesInCurried
4139
case Boxed // environment is inside a box (in which case references are not counted)
4240

4341
/** A class describing environments.
@@ -185,11 +183,6 @@ object CheckCaptures:
185183
if ccConfig.useSealed then check.traverse(tp)
186184
end disallowRootCapabilitiesIn
187185

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-
193186
/** A prototype that indicates selection with an immutable value */
194187
class PathSelectionProto(val sym: Symbol, val pt: Type)(using Context) extends WildcardSelectionProto
195188

@@ -339,20 +332,13 @@ class CheckCaptures extends Recheck, SymTransformer:
339332

340333
/** The next environment enclosing `env` that needs to be charged
341334
* with free references.
342-
* Skips environments directly enclosing environments of kind ClosureResult.
343335
* @param included Whether an environment is included in the range of
344336
* environments to charge. Once `included` is false, no
345337
* more environments need to be charged.
346338
*/
347339
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
356342

357343
/** A description where this environment comes from */
358344
private def provenance(env: Env)(using Context): String =
@@ -746,15 +732,6 @@ class CheckCaptures extends Recheck, SymTransformer:
746732
.showing(i"rechecked closure $tree / $pt = $result", capt)
747733

748734
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-
758735
openClosures = (mdef.symbol, pt) :: openClosures
759736
try
760737
// Constrain closure's parameters and result from the expected type before
@@ -1002,8 +979,6 @@ class CheckCaptures extends Recheck, SymTransformer:
1002979
tree match
1003980
case _: RefTree | closureDef(_) if pt.isBoxedCapturing =>
1004981
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)
1007982
case _ =>
1008983
val res =
1009984
try

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
314314
case _ => res
315315
)
316316
val fntpe = defn.PolyFunctionOf(mt)
317-
if !encl.isEmpty && (!ccConfig.DropOuterUsesInCurried || resDecomposed.isEmpty) then
317+
if !encl.isEmpty then
318318
val cs = CaptureSet(encl.map(_.paramRefs.head)*)
319319
CapturingType(fntpe, cs, boxed = false)
320320
else fntpe

0 commit comments

Comments
 (0)