@@ -520,16 +520,13 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
520
520
if isExcluded(meth) then
521
521
return
522
522
523
- ccState.recordLevel(meth)
524
- ccState.inNestedLevel:
525
- inContext(ctx.withOwner(meth)):
526
- paramss.foreach(traverse)
527
- transformResultType(tpt, meth)
528
- traverse(tree.rhs)
523
+ inContext(ctx.withOwner(meth)):
524
+ paramss.foreach(traverse)
525
+ transformResultType(tpt, meth)
526
+ traverse(tree.rhs)
529
527
530
528
case tree @ ValDef (_, tpt : TypeTree , _) =>
531
529
val sym = tree.symbol
532
- ccState.recordLevel(sym)
533
530
val defCtx = if sym.isOneOf(TermParamOrAccessor ) then ctx else ctx.withOwner(sym)
534
531
inContext(defCtx):
535
532
transformResultType(tpt, sym)
@@ -546,10 +543,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
546
543
547
544
case tree : TypeDef if tree.symbol.isClass =>
548
545
val sym = tree.symbol
549
- ccState.recordLevel(sym)
550
- ccState.inNestedLevelUnless(sym.is(Module )):
551
- inContext(ctx.withOwner(sym))
552
- traverseChildren(tree)
546
+ inContext(ctx.withOwner(sym))
547
+ traverseChildren(tree)
553
548
554
549
case tree @ TypeDef (_, rhs : TypeTree ) =>
555
550
transformTT(rhs, tree.symbol, boxed = false )
@@ -670,55 +665,54 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
670
665
tree.symbol match
671
666
case cls : ClassSymbol =>
672
667
checkClassifiedInheritance(cls)
673
- ccState.inNestedLevelUnless(cls.is(Module )):
674
- val cinfo @ ClassInfo (prefix, _, ps, decls, selfInfo) = cls.classInfo
675
-
676
- // Compute new self type
677
- def isInnerModule = cls.is(ModuleClass ) && ! cls.isStatic
678
- val selfInfo1 =
679
- if (selfInfo ne NoType ) && ! isInnerModule then
680
- // if selfInfo is explicitly given then use that one, except if
681
- // self info applies to non-static modules, these still need to be inferred
682
- selfInfo
683
- else if cls.isPureClass then
684
- // is cls is known to be pure, nothing needs to be added to self type
685
- selfInfo
686
- else if ! cls.isEffectivelySealed && ! cls.baseClassHasExplicitNonUniversalSelfType then
687
- // assume {cap} for completely unconstrained self types of publicly extensible classes
688
- CapturingType (cinfo.selfType, CaptureSet .universal)
689
- else
690
- // Infer the self type for the rest, which is all classes without explicit
691
- // self types (to which we also add nested module classes), provided they are
692
- // neither pure, nor are publicily extensible with an unconstrained self type.
693
- val cs = CaptureSet .Var (cls, level = ccState.currentLevel)
694
- if cls.derivesFrom(defn.Caps_Capability ) then
695
- // If cls is a capability class, we need to add a fresh readonly capability to
696
- // ensure we cannot treat the class as pure.
697
- CaptureSet .fresh(Origin .InDecl (cls)).readOnly.subCaptures(cs)
698
- CapturingType (cinfo.selfType, cs)
699
-
700
- // Compute new parent types
701
- val ps1 = inContext(ctx.withOwner(cls)):
702
- ps.mapConserve(transformExplicitType(_, NoSymbol , freshen = false ))
703
-
704
- // Install new types and if it is a module class also update module object
705
- if (selfInfo1 ne selfInfo) || (ps1 ne ps) then
706
- val newInfo = ClassInfo (prefix, cls, ps1, decls, selfInfo1)
707
- updateInfo(cls, newInfo, cls.owner)
708
- capt.println(i " update class info of $cls with parents $ps selfinfo $selfInfo to $newInfo" )
709
- cls.thisType.asInstanceOf [ThisType ].invalidateCaches()
710
- if cls.is(ModuleClass ) then
711
- // if it's a module, the capture set of the module reference is the capture set of the self type
712
- val modul = cls.sourceModule
713
- val selfCaptures = selfInfo1 match
714
- case CapturingType (_, refs) => refs
715
- case _ => CaptureSet .empty
716
- // Note: Can't do val selfCaptures = selfInfo1.captureSet here.
717
- // This would potentially give stackoverflows when setup is run repeatedly.
718
- // One test case is pos-custom-args/captures/checkbounds.scala under
719
- // ccConfig.alwaysRepeatRun = true.
720
- updateInfo(modul, CapturingType (modul.info, selfCaptures), modul.owner)
721
- modul.termRef.invalidateCaches()
668
+ val cinfo @ ClassInfo (prefix, _, ps, decls, selfInfo) = cls.classInfo
669
+
670
+ // Compute new self type
671
+ def isInnerModule = cls.is(ModuleClass ) && ! cls.isStatic
672
+ val selfInfo1 =
673
+ if (selfInfo ne NoType ) && ! isInnerModule then
674
+ // if selfInfo is explicitly given then use that one, except if
675
+ // self info applies to non-static modules, these still need to be inferred
676
+ selfInfo
677
+ else if cls.isPureClass then
678
+ // is cls is known to be pure, nothing needs to be added to self type
679
+ selfInfo
680
+ else if ! cls.isEffectivelySealed && ! cls.baseClassHasExplicitNonUniversalSelfType then
681
+ // assume {cap} for completely unconstrained self types of publicly extensible classes
682
+ CapturingType (cinfo.selfType, CaptureSet .universal)
683
+ else
684
+ // Infer the self type for the rest, which is all classes without explicit
685
+ // self types (to which we also add nested module classes), provided they are
686
+ // neither pure, nor are publicily extensible with an unconstrained self type.
687
+ val cs = CaptureSet .Var (cls)
688
+ if cls.derivesFrom(defn.Caps_Capability ) then
689
+ // If cls is a capability class, we need to add a fresh readonly capability to
690
+ // ensure we cannot treat the class as pure.
691
+ CaptureSet .fresh(Origin .InDecl (cls)).readOnly.subCaptures(cs)
692
+ CapturingType (cinfo.selfType, cs)
693
+
694
+ // Compute new parent types
695
+ val ps1 = inContext(ctx.withOwner(cls)):
696
+ ps.mapConserve(transformExplicitType(_, NoSymbol , freshen = false ))
697
+
698
+ // Install new types and if it is a module class also update module object
699
+ if (selfInfo1 ne selfInfo) || (ps1 ne ps) then
700
+ val newInfo = ClassInfo (prefix, cls, ps1, decls, selfInfo1)
701
+ updateInfo(cls, newInfo, cls.owner)
702
+ capt.println(i " update class info of $cls with parents $ps selfinfo $selfInfo to $newInfo" )
703
+ cls.thisType.asInstanceOf [ThisType ].invalidateCaches()
704
+ if cls.is(ModuleClass ) then
705
+ // if it's a module, the capture set of the module reference is the capture set of the self type
706
+ val modul = cls.sourceModule
707
+ val selfCaptures = selfInfo1 match
708
+ case CapturingType (_, refs) => refs
709
+ case _ => CaptureSet .empty
710
+ // Note: Can't do val selfCaptures = selfInfo1.captureSet here.
711
+ // This would potentially give stackoverflows when setup is run repeatedly.
712
+ // One test case is pos-custom-args/captures/checkbounds.scala under
713
+ // ccConfig.alwaysRepeatRun = true.
714
+ updateInfo(modul, CapturingType (modul.info, selfCaptures), modul.owner)
715
+ modul.termRef.invalidateCaches()
722
716
case _ =>
723
717
case _ =>
724
718
end postProcess
@@ -857,7 +851,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
857
851
858
852
/** Add a capture set variable to `tp` if necessary. */
859
853
private def addVar (tp : Type , owner : Symbol )(using Context ): Type =
860
- decorate(tp, CaptureSet .Var (owner, _, level = ccState.currentLevel ))
854
+ decorate(tp, CaptureSet .Var (owner, _))
861
855
862
856
/** A map that adds <fluid> capture sets at all contra- and invariant positions
863
857
* in a type where a capture set would be needed. This is used to make types
0 commit comments