Skip to content

Commit 86f249c

Browse files
committed
Fix resetInst logic
The previous way never reset any type variable since it traversed `ownedVars`, and instantiated TypeVars are no longer in the ownedVars of their owning TyperState.
1 parent ec2b5d6 commit 86f249c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

compiler/src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,19 @@ object TyperState {
2525

2626
type LevelMap = SimpleIdentityMap[TypeVar, Integer]
2727

28-
opaque type Snapshot = (Constraint, TypeVars, TypeVars, LevelMap)
28+
opaque type Snapshot = (Constraint, TypeVars, LevelMap)
2929

3030
extension (ts: TyperState)
3131
def snapshot()(using Context): Snapshot =
32-
var previouslyInstantiated: TypeVars = SimpleIdentitySet.empty
33-
for tv <- ts.ownedVars do if tv.inst.exists then previouslyInstantiated += tv
34-
(ts.constraint, ts.ownedVars, previouslyInstantiated, ts.upLevels)
32+
(ts.constraint, ts.ownedVars, ts.upLevels)
3533

3634
def resetTo(state: Snapshot)(using Context): Unit =
37-
val (c, tvs, previouslyInstantiated, upLevels) = state
38-
for tv <- tvs do
39-
if tv.inst.exists && !previouslyInstantiated.contains(tv) then
35+
val (constraint, ownedVars, upLevels) = state
36+
for tv <- ownedVars do
37+
if !ts.ownedVars.contains(tv) then // tv has been instantiated
4038
tv.resetInst(ts)
41-
ts.ownedVars = tvs
42-
ts.constraint = c
39+
ts.constraint = constraint
40+
ts.ownedVars = ownedVars
4341
ts.upLevels = upLevels
4442
}
4543

@@ -190,7 +188,7 @@ class TyperState() {
190188
if level < targetState.nestingLevel(tv) then
191189
targetState.setNestingLevel(tv, level)
192190
}
193-
191+
194192
targetState.gc()
195193
isCommitted = true
196194
ownedVars = SimpleIdentitySet.empty

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,6 +4524,7 @@ object Types {
45244524
owningState = null // no longer needed; null out to avoid a memory leak
45254525

45264526
private[core] def resetInst(ts: TyperState): Unit =
4527+
assert(myInst.exists)
45274528
myInst = NoType
45284529
owningState = new WeakReference(ts)
45294530

0 commit comments

Comments
 (0)