@@ -115,16 +115,17 @@ class TyperState() {
115
115
*/
116
116
def commit ()(using Context ): Unit = {
117
117
Stats .record(" typerState.commit" )
118
+ assert(isCommittable)
118
119
val targetState = ctx.typerState
119
- if (constraint ne targetState.constraint)
120
+ if constraint ne targetState.constraint then
121
+ Stats .record(" typerState.commit.new constraint" )
120
122
constr.println(i " committing $this to $targetState, fromConstr = $constraint, toConstr = ${targetState.constraint}" )
121
- assert(isCommittable)
122
- if (targetState.constraint eq previousConstraint) targetState.constraint = constraint
123
- else targetState.mergeConstraintWith(this )
124
- constraint foreachTypeVar { tvar =>
125
- if (tvar.owningState.get eq this ) tvar.owningState = new WeakReference (targetState)
126
- }
127
- targetState.ownedVars ++= ownedVars
123
+ if targetState.constraint eq previousConstraint then targetState.constraint = constraint
124
+ else targetState.mergeConstraintWith(this )
125
+ if ! ownedVars.isEmpty then
126
+ for tvar <- ownedVars do
127
+ tvar.owningState = new WeakReference (targetState)
128
+ targetState.ownedVars ++= ownedVars
128
129
targetState.gc()
129
130
reporter.flush()
130
131
isCommitted = true
@@ -137,22 +138,19 @@ class TyperState() {
137
138
* type variable instantiation cannot be retracted anymore. Then, remove
138
139
* no-longer needed constraint entries.
139
140
*/
140
- def gc ()(using Context ): Unit = {
141
- Stats .record(" typerState.gc" )
142
- val toCollect = new mutable.ListBuffer [TypeLambda ]
143
- constraint foreachTypeVar { tvar =>
144
- if (! tvar.inst.exists) {
145
- val inst = constraint.instType(tvar)
146
- if (inst.exists && (tvar.owningState.get eq this )) {
147
- tvar.inst = inst
148
- val lam = tvar.origin.binder
149
- if (constraint.isRemovable(lam)) toCollect += lam
150
- }
151
- }
152
- }
153
- for (poly <- toCollect)
154
- constraint = constraint.remove(poly)
155
- }
141
+ def gc ()(using Context ): Unit =
142
+ if ! ownedVars.isEmpty then
143
+ Stats .record(" typerState.gc" )
144
+ val toCollect = new mutable.ListBuffer [TypeLambda ]
145
+ for tvar <- ownedVars do
146
+ if ! tvar.inst.exists then
147
+ val inst = constraint.instType(tvar)
148
+ if inst.exists then
149
+ tvar.inst = inst
150
+ val lam = tvar.origin.binder
151
+ if constraint.isRemovable(lam) then toCollect += lam
152
+ for poly <- toCollect do
153
+ constraint = constraint.remove(poly)
156
154
157
155
override def toString : String = {
158
156
def ids (state : TyperState ): List [String ] =
0 commit comments