Skip to content

Commit ccf9867

Browse files
committed
Simplify setup
1 parent 67446d2 commit ccf9867

File tree

5 files changed

+26
-35
lines changed

5 files changed

+26
-35
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object ccConfig:
4949

5050
/** Not used currently. Handy for trying out new features */
5151
def newScheme(using Context): Boolean =
52-
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.7`)
52+
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.8`)
5353

5454
end ccConfig
5555

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ object CheckCaptures:
220220

221221
trait CheckerAPI:
222222
/** Complete symbol info of a val or a def */
223-
def completeDef(tree: ValOrDefDef, sym: Symbol, newInfo: Type)(using Context): Type
223+
def completeDef(tree: ValOrDefDef, sym: Symbol, completer: LazyType)(using Context): Type
224224

225225
extension [T <: Tree](tree: T)
226226

@@ -323,10 +323,8 @@ class CheckCaptures extends Recheck, SymTransformer:
323323
case t @ CapturingType(parent, refs) =>
324324
refs match
325325
case refs: CaptureSet.Var if !refs.isConst =>
326-
if variance < 0 then
327-
refs.solve()
328-
else if ccConfig.newScheme && !sym.isAnonymousFunction then
329-
refs.markSolved(provisional = !sym.isMutableVar)
326+
if variance < 0 then refs.solve()
327+
else refs.markSolved(provisional = !sym.isMutableVar)
330328
case _ =>
331329
traverse(parent)
332330
case t @ defn.RefinedFunctionOf(rinfo) =>
@@ -1089,9 +1087,7 @@ class CheckCaptures extends Recheck, SymTransformer:
10891087
* these checks can appear out of order, we need to first create the correct
10901088
* environment for checking the definition.
10911089
*/
1092-
def completeDef(tree: ValOrDefDef, sym: Symbol, newInfo: Type)(using Context): Type =
1093-
val completer = sym.infoOrCompleter
1094-
sym.info = newInfo
1090+
def completeDef(tree: ValOrDefDef, sym: Symbol, completer: LazyType)(using Context): Type =
10951091
val saved = curEnv
10961092
try
10971093
// Setup environment to reflect the new owner.

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
535535
def setupTraverser(checker: CheckerAPI) = new TreeTraverserWithPreciseImportContexts:
536536
import checker.*
537537

538-
private val paramSigChange = util.EqHashSet[Tree]()
539-
540538
/** Transform type of tree, and remember the transformed type as the type of the tree
541539
* @pre !(boxed && sym.exists)
542540
*/
@@ -547,8 +545,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
547545
then transformInferredType(tree.tpe)
548546
else transformExplicitType(tree.tpe, sym, freshen = !boxed, tptToCheck = tree)
549547
if boxed then transformed = box(transformed)
550-
if sym.is(Param) && (transformed ne tree.tpe) then
551-
paramSigChange += tree
552548
tree.setNuType(
553549
if sym.hasAnnotation(defn.UncheckedCapturesAnnot) then makeUnchecked(transformed)
554550
else transformed)
@@ -653,19 +649,19 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
653649
else tree.tpt.nuType
654650

655651
// A test whether parameter signature might change. This returns true if one of
656-
// the parameters has a new type installee. The idea here is that we store a new
652+
// the parameters has a new type installed. The idea here is that we store a new
657653
// type only if the transformed type is different from the original.
658654
def paramSignatureChanges = tree.match
659655
case tree: DefDef =>
660656
tree.paramss.nestedExists:
661-
case param: ValDef => paramSigChange.contains(param.tpt)
662-
case param: TypeDef => paramSigChange.contains(param.rhs)
657+
case param: ValDef => param.tpt.hasNuType
658+
case param: TypeDef => param.rhs.hasNuType
663659
case _ => false
664660

665661
// A symbol's signature changes if some of its parameter types or its result type
666662
// have a new type installed here (meaning hasRememberedType is true)
667663
def signatureChanges =
668-
tree.tpt.hasNuType && !sym.isConstructor || paramSignatureChanges
664+
tree.tpt.hasNuType || paramSignatureChanges
669665

670666
// Replace an existing symbol info with inferred types where capture sets of
671667
// TypeParamRefs and TermParamRefs are put in correspondence by BiTypeMaps with the
@@ -707,12 +703,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
707703

708704
// If there's a change in the signature, update the info of `sym`
709705
if sym.exists && signatureChanges then
710-
val newInfo =
711-
root.toResultInResults(report.error(_, tree.srcPos)):
712-
integrateRT(sym.info, sym.paramSymss, localReturnType, Nil, Nil)
713-
.showing(i"update info $sym: ${sym.info} = $result", capt)
714-
if newInfo ne sym.info then
715-
val updatedInfo =
706+
val updatedInfo =
707+
val newInfo =
708+
root.toResultInResults(report.error(_, tree.srcPos)):
709+
integrateRT(sym.info, sym.paramSymss, localReturnType, Nil, Nil)
710+
.showing(i"update info $sym: ${sym.info} = $result", capt)
716711
if sym.isAnonymousFunction
717712
|| sym.is(Param)
718713
|| sym.is(ParamAccessor)
@@ -728,8 +723,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
728723
assert(ctx.phase == thisPhase.next, i"$sym")
729724
capt.println(i"forcing $sym, printing = ${ctx.mode.is(Mode.Printing)}")
730725
//if ctx.mode.is(Mode.Printing) then new Error().printStackTrace()
731-
completeDef(tree, sym, newInfo)
732-
updateInfo(sym, updatedInfo)
726+
sym.info = newInfo
727+
completeDef(tree, sym, this)
728+
updateInfo(sym, updatedInfo)
733729

734730
case tree: Bind =>
735731
val sym = tree.symbol
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-this.scala:11:15 --------------------------------------
2-
11 | val y: C = this // error
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-this.scala:10:15 --------------------------------------
2+
10 | val y: C = this // error
33
| ^^^^
44
| Found: (C.this : C^{C.this.x})
55
| Required: C
66
|
77
| longer explanation available when compiling with `-explain`
8-
-- Error: tests/neg-custom-args/captures/cc-this.scala:13:15 -----------------------------------------------------------
9-
13 | class C2(val x: () => Int): // error
8+
-- Error: tests/neg-custom-args/captures/cc-this.scala:12:15 -----------------------------------------------------------
9+
12 | class C2(val x: () => Int): // error
1010
| ^
1111
| reference (C2.this.x : () => Int) is not included in the allowed capture set {} of the self type of class C2
12-
-- Error: tests/neg-custom-args/captures/cc-this.scala:20:8 ------------------------------------------------------------
13-
20 | class C4(val f: () => Int) extends C3 // error
12+
-- Error: tests/neg-custom-args/captures/cc-this.scala:19:8 ------------------------------------------------------------
13+
19 | class C4(val f: () => Int) extends C3 // error
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|reference (C4.this.f : () => Int) captured by this self type is not included in the allowed capture set {} of pure base class class C3
16-
-- Error: tests/neg-custom-args/captures/cc-this.scala:34:8 ------------------------------------------------------------
17-
34 | def c3 = c2.y // error
16+
-- Error: tests/neg-custom-args/captures/cc-this.scala:33:8 ------------------------------------------------------------
17+
33 | def c3 = c2.y // error
1818
| ^
1919
| Separation failure: method c3's inferred result type C{val x: () => Int}^{cc} hides non-local parameter cc

tests/neg-custom-args/captures/cc-this.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import language.`3.8`
21
import caps.consume
32

43
class Cap extends caps.Capability
@@ -26,7 +25,7 @@ def test2(using @consume cc: Cap) =
2625
val y: C^ = this
2726

2827
def f = () =>
29-
eff
28+
eff(using cc)
3029
1
3130

3231
def c1 = new C(f)

0 commit comments

Comments
 (0)