Skip to content

Commit 11e8e44

Browse files
committed
hash calculations for domains should not depend on the ordering of domain functions and axioms
1 parent 73ce0e7 commit 11e8e44

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/main/scala/viper/silver/utility/Caching.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
package viper.silver.utility
88

99
import java.security.MessageDigest
10-
1110
import viper.silver.ast.pretty.FastPrettyPrinter
12-
import viper.silver.ast.Node
11+
import viper.silver.ast.{Domain, DomainAxiom, DomainFunc, Node}
1312

1413
import scala.collection.mutable
1514
import scala.language.postfixOps
@@ -106,7 +105,17 @@ object CacheHelper {
106105
new String(MessageDigest.getInstance("MD5").digest(s.getBytes))
107106
}
108107
def computeEntityHash(prefix: String, astNode: Node): String = {
109-
val node = prefix + s"_<${astNode.getClass.toString()}>_" + FastPrettyPrinter.pretty(astNode)
108+
// orders subtrees of `astNode` when their ordering does not matter, i.e. a cache entry for a
109+
// similar node that just has a different ordering of its subtrees should be treated as a cache hit
110+
val normalizedAstNode = astNode match {
111+
case n: Domain =>
112+
Domain(n.name, n.functions.sorted, n.axioms.sorted, n.typVars)(n.pos, n.info, n.errT)
113+
case n => n
114+
}
115+
val node = prefix + s"_<${astNode.getClass.toString}>_" + FastPrettyPrinter.pretty(normalizedAstNode)
110116
CacheHelper.buildHash(node)
111117
}
118+
119+
implicit def domainFnOrdering: Ordering[DomainFunc] = Ordering.by(_.name)
120+
implicit def domainAxOrdering: Ordering[DomainAxiom] = Ordering.by(ax => FastPrettyPrinter.pretty(ax.exp))
112121
}

0 commit comments

Comments
 (0)