Skip to content

Commit 34b42d8

Browse files
committed
Cleanup LinkedHashSet fixes and replace them with Set (i.e., back
to initial implementation). Assuming that the DPLL procedure does not run into max recursion depth, that workaround is not needed anymore, since the non- determinism has been fixed.
1 parent 179419c commit 34b42d8

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

src/compiler/scala/tools/nsc/transform/patmat/Logic.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ trait Logic extends Debugging {
8787
def mayBeNull: Boolean
8888

8989
// compute the domain and return it (call registerNull first!)
90-
def domainSyms: Option[mutable.LinkedHashSet[Sym]]
90+
def domainSyms: Option[Set[Sym]]
9191

9292
// the symbol for this variable being equal to its statically known type
9393
// (only available if registerEquality has been called for that type before)
@@ -205,7 +205,7 @@ trait Logic extends Debugging {
205205
def removeVarEq(props: List[Prop], modelNull: Boolean = false): (Formula, List[Formula]) = {
206206
val start = if (Statistics.canEnable) Statistics.startTimer(patmatAnaVarEq) else null
207207

208-
val vars = mutable.LinkedHashSet[Var]()
208+
val vars = new mutable.HashSet[Var]
209209

210210
object gatherEqualities extends PropTraverser {
211211
override def apply(p: Prop) = p match {
@@ -292,7 +292,7 @@ trait Logic extends Debugging {
292292
def eqFreePropToSolvable(p: Prop): Formula
293293
def cnfString(f: Formula): String
294294

295-
type Model = collection.immutable.SortedMap[Sym, Boolean]
295+
type Model = Map[Sym, Boolean]
296296
val EmptyModel: Model
297297
val NoModel: Model
298298

@@ -342,9 +342,9 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
342342
// we enumerate the subtypes of the full type, as that allows us to filter out more types statically,
343343
// once we go to run-time checks (on Const's), convert them to checkable types
344344
// TODO: there seems to be bug for singleton domains (variable does not show up in model)
345-
lazy val domain: Option[mutable.LinkedHashSet[Const]] = {
346-
val subConsts: Option[mutable.LinkedHashSet[Const]] = enumerateSubtypes(staticTp).map { tps =>
347-
mutable.LinkedHashSet(tps: _*).map{ tp =>
345+
lazy val domain: Option[Set[Const]] = {
346+
val subConsts = enumerateSubtypes(staticTp).map{ tps =>
347+
tps.toSet[Type].map{ tp =>
348348
val domainC = TypeConst(tp)
349349
registerEquality(domainC)
350350
domainC
@@ -487,7 +487,7 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
487487
}
488488

489489
// accessing after calling registerNull will result in inconsistencies
490-
lazy val domainSyms: Option[collection.mutable.LinkedHashSet[Sym]] = domain map { _ map symForEqualsTo }
490+
lazy val domainSyms: Option[Set[Sym]] = domain map { _ map symForEqualsTo }
491491

492492
lazy val symForStaticTp: Option[Sym] = symForEqualsTo.get(TypeConst(staticTpCheckable))
493493

src/compiler/scala/tools/nsc/transform/patmat/Solving.scala

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,9 @@ trait Solving extends Logic {
2626
type Formula = FormulaBuilder
2727
def formula(c: Clause*): Formula = ArrayBuffer(c: _*)
2828

29-
type Clause = collection.Set[Lit]
29+
type Clause = Set[Lit]
3030
// a clause is a disjunction of distinct literals
31-
def clause(l: Lit*): Clause = (
32-
if (l.lengthCompare(1) <= 0) {
33-
l.toSet // SI-8531 Avoid LinkedHashSet's bulk for 0 and 1 element clauses
34-
} else {
35-
// neg/t7020.scala changes output 1% of the time, the non-determinism is quelled with this linked set
36-
mutable.LinkedHashSet(l: _*)
37-
}
38-
)
31+
def clause(l: Lit*): Clause = l.toSet
3932

4033
type Lit
4134
def Lit(sym: Sym, pos: Boolean = true): Lit
@@ -140,7 +133,7 @@ trait Solving extends Logic {
140133
def cnfString(f: Formula) = alignAcrossRows(f map (_.toList) toList, "\\/", " /\\\n")
141134

142135
// adapted from http://lara.epfl.ch/w/sav10:simple_sat_solver (original by Hossein Hojjat)
143-
val EmptyModel = collection.immutable.SortedMap.empty[Sym, Boolean]
136+
val EmptyModel = Map.empty[Sym, Boolean]
144137
val NoModel: Model = null
145138

146139
// returns all solutions, if any (TODO: better infinite recursion backstop -- detect fixpoint??)
@@ -256,15 +249,14 @@ trait Solving extends Logic {
256249
withLit(findModelFor(dropUnit(f, unitLit)), unitLit)
257250
case _ =>
258251
// partition symbols according to whether they appear in positive and/or negative literals
259-
// SI-7020 Linked- for deterministic counter examples.
260-
val pos = new mutable.LinkedHashSet[Sym]()
261-
val neg = new mutable.LinkedHashSet[Sym]()
252+
val pos = new mutable.HashSet[Sym]()
253+
val neg = new mutable.HashSet[Sym]()
262254
mforeach(f)(lit => if (lit.pos) pos += lit.sym else neg += lit.sym)
263255

264256
// appearing in both positive and negative
265-
val impures: mutable.LinkedHashSet[Sym] = pos intersect neg
257+
val impures = pos intersect neg
266258
// appearing only in either positive/negative positions
267-
val pures: mutable.LinkedHashSet[Sym] = (pos ++ neg) -- impures
259+
val pures = (pos ++ neg) -- impures
268260

269261
if (pures nonEmpty) {
270262
val pureSym = pures.head

0 commit comments

Comments
 (0)