Skip to content

Commit 0ffba0d

Browse files
committed
Simplifications
- Drop valsCanBeLevelOwners and levelOwnersNeedCapParam config settings - Drop !isCaseClassSynthetic condition in isLevelOwner - Drop handling of anonymous functions in levelOwnerNamed Neither are needed anymore with the the conflg flags gone.
1 parent 8646308 commit 0ffba0d

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ private val adaptUnpickledFunctionTypes = false
2828
*/
2929
private val constrainRootsWhenMapping = true
3030

31-
/** If true, most vals can be level owners. If false, only vals defined by a
32-
* closure as RHS can be level owners
33-
*/
34-
private val valsCanBeLevelOwners = true
35-
36-
/** If true, only vals, defs, and classes with a universal capability in a parameter
37-
* or self type are considered as level owners.
38-
*/
39-
private val levelOwnersNeedCapParam = true
31+
private val constructorsAreLevelOwners = false
4032

4133
def allowUniversalInBoxed(using Context) =
4234
Feature.sourceVersion.isAtLeast(SourceVersion.`3.3`)
@@ -390,25 +382,21 @@ extension (sym: Symbol)
390382
def isCaseClassSynthetic = // TODO drop
391383
symd.maybeOwner.isClass && symd.owner.is(Case) && symd.is(Synthetic) && symd.info.firstParamNames.isEmpty
392384
def classQualifies =
393-
!levelOwnersNeedCapParam
394-
|| takesCappedParamIn(symd.primaryConstructor.info)
385+
takesCappedParamIn(symd.primaryConstructor.info)
395386
|| symd.asClass.givenSelfType.hasUniversalRootOf(sym)
396-
def termQualifies =
397-
!levelOwnersNeedCapParam || takesCappedParamIn(symd.info)
398387
def compute =
399388
if symd.isClass then
400389
symd.is(CaptureChecked) && classQualifies || symd.isRoot
401390
else
402391
(symd.is(Method, butNot = Accessor)
403-
|| valsCanBeLevelOwners && symd.isTerm && !symd.isOneOf(TermParamOrAccessor | Mutable))
392+
|| symd.isTerm && !symd.isOneOf(TermParamOrAccessor | Mutable))
404393
&& (!symd.owner.isClass
405394
|| symd.owner.is(CaptureChecked)
406395
|| Synthetics.needsTransform(symd)
407396
)
408-
&& !isCaseClassSynthetic
409397
&& !symd.isConstructor
410398
&& (!symd.isAnonymousFunction || sym.definedLocalRoot.exists)
411-
&& termQualifies
399+
&& takesCappedParamIn(symd.info)
412400
&& { ccSetup.println(i"Level owner $sym"); true }
413401

414402
ccState.isLevelOwner.getOrElseUpdate(sym, compute)
@@ -433,17 +421,13 @@ extension (sym: Symbol)
433421
* owner.
434422
*/
435423
def levelOwnerNamed(name: String)(using Context): Symbol =
436-
def recur(sym: Symbol, prev: Symbol): Symbol =
424+
def recur(sym: Symbol): Symbol =
437425
if sym.name.toString == name then
438426
if sym.isLevelOwner then sym
439-
else if sym.isTerm && !sym.isOneOf(Method | Module) && prev.exists then prev
440427
else NoSymbol
441-
else if sym == defn.RootClass then
442-
NoSymbol
443-
else
444-
val prev1 = if sym.isAnonymousFunction && sym.isLevelOwner then sym else NoSymbol
445-
recur(sym.owner, prev1)
446-
recur(sym, NoSymbol)
428+
else if sym == defn.RootClass then NoSymbol
429+
else recur(sym.owner)
430+
recur(sym)
447431
.showing(i"find outer $sym [ $name ] = $result", capt)
448432

449433
/** The parameter with type caps.Cap in the leading term parameter section,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
463463
case possiblyTypedClosureDef(ddef)
464464
if !mentionsCap(rhsOfEtaExpansion(ddef))
465465
&& !sym.is(Mutable)
466-
&& (!levelOwnersNeedCapParam
467-
|| ddef.symbol.takesCappedParamIn(ddef.symbol.info)) =>
466+
&& ddef.symbol.takesCappedParamIn(ddef.symbol.info) =>
468467
ccSetup.println(i"Level owner at setup $sym / ${ddef.symbol.info}")
469468
ccState.isLevelOwner(sym) = true
470469
case _ =>
@@ -571,6 +570,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
571570
// closures are handled specially; the newInfo is constrained from
572571
// the expected type and only afterwards we recheck the definition
573572
newInfo
573+
else if sym.isPrimaryConstructor then
574+
newInfo
574575
else new LazyType:
575576
def complete(denot: SymDenotation)(using Context) =
576577
// infos of other methods are determined from their definitions which

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ object Synthetics:
157157
case DefaultGetterName(nme.copy, n) =>
158158
transformDefaultGetterCaptures(info, symd.owner, n)
159159
case nme.unapply =>
160-
if levelOwnersNeedCapParam then ccState.isLevelOwner(symd.symbol) = true
160+
ccState.isLevelOwner(symd.symbol) = true
161161
transformUnapplyCaptures(info)
162162
case nme.apply | nme.copy =>
163163
addCaptureDeps(info)
164164
case nme.andThen | nme.compose =>
165-
if levelOwnersNeedCapParam then ccState.isLevelOwner(symd.symbol) = true
165+
ccState.isLevelOwner(symd.symbol) = true
166166
transformComposeCaptures(info, symd.owner)
167167
case nme.curried | nme.tupled =>
168168
transformCurriedTupledCaptures(info, symd.owner)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package test
2+
3+
trait IOnce[A]:
4+
self: I[A]^ =>
5+
6+
trait I[+A]:
7+
self: I[A]^ =>
8+
9+
def concat[B >: A](xs: => IOnce[B]^): I[B]^{this, xs} = new I.ConcatI[B](self).concat(xs)
10+
11+
object I:
12+
private final class ConcatI[+A](val from: I[A]^) extends I[A]:
13+
override def concat[B >: A](that: => IOnce[B]^): I[B]^{this, that} = ???
14+
15+
16+
17+

0 commit comments

Comments
 (0)