@@ -115,16 +115,17 @@ class TyperState() {
115115 */
116116 def commit ()(using Context ): Unit = {
117117 Stats .record(" typerState.commit" )
118+ assert(isCommittable)
118119 val targetState = ctx.typerState
119- if (constraint ne targetState.constraint)
120+ if constraint ne targetState.constraint then
121+ Stats .record(" typerState.commit.new constraint" )
120122 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
128129 targetState.gc()
129130 reporter.flush()
130131 isCommitted = true
@@ -137,22 +138,19 @@ class TyperState() {
137138 * type variable instantiation cannot be retracted anymore. Then, remove
138139 * no-longer needed constraint entries.
139140 */
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)
156154
157155 override def toString : String = {
158156 def ids (state : TyperState ): List [String ] =
0 commit comments