-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unification benchmark using 'map' and 'stream' #798
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Here's a slightly minified version: /// Robinson-style Unification Algorithm
module examples/benchmarks/unify
import map
import result
import bytearray
type Type {
Var(name: String)
Con(name: String, args: List[Type])
}
type Substitution = Map[String, Type]
type UnificationError {
OccursCheckFailure(variable: String, tpe: Type)
UnificationFailure(tpe1: Type, tpe2: Type)
UnificationManyFailure(tps1: List[Type], tps2: List[Type])
}
def showType(ty: Type): String = ty match {
case Var(name) => name
case Con(name, Nil()) => name
case Con(name, args) =>
name ++ "(" ++ args.map { t => showType(t) }.join(", ") ++ ")"
}
def show(err: UnificationError): String = err match {
case OccursCheckFailure(variable, ty) =>
"Occurs check failed: " ++ variable ++ " occurs in " ++ showType(ty)
case UnificationFailure(ty1, ty2) =>
"Cannot unify " ++ showType(ty1) ++ " with " ++ showType(ty2)
case UnificationManyFailure(tps1, tps2) =>
"Cannot unify " ++ tps2.map { t => showType(t) }.join(", ") ++ " with " ++ tps1.map { t => showType(t) }.join(", ")
}
def reporting { body : => Substitution / Exception[UnificationError] }: Unit = {
val res = result[Substitution, UnificationError] {
body()
}
res match {
case Success(subst) => {
println("Unification successful!")
println("Substitution:")
subst.foreach { (k, v) =>
println(" " ++ k ++ " -> " ++ showType(v))
}
}
case Error(err, msg) =>
println("Unification failed: " ++ show(err))
if (msg.length > 0) {
println(msg)
}
}
}
def main() = reporting {
val intType = Con("Int", [])
val listType = Con("List", [intType])
val typeVar = Var("a")
do raise(UnificationManyFailure([intType], [listType, typeVar]), "")
} seems to crash the normaliser!
When I do |
Co-authored-by: Jonathan Brachthäuser <[email protected]>
effekt/shared/src/main/scala/effekt/core/optimizer/Normalizer.scala
Outdated
Show resolved
Hide resolved
// the actual test | ||
val N = 12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N = 12
means unification of two trees of depth 12, i.e. tree of tuples with 2^12 = 4096
variables in the leaves.
We can tweak this number or even use the benchmarks/runner
...
Resolves #796
It's an OK (not great, not terrible) benchmark:
(...((XLLL, XLLR), (XLRL, XLRR)), ...
forX = { A, B }
,ALLL -> BLLL
.Configurable with a given
N
if some tweaking is needed.Perf:
My machine
On my computer with
N = 12
:On my computer with
N = 16
(16x more work thanN = 12
)CI
With
N = 12
in CI (measured imprecisely in two CI rounds):With
N = 16
in CI (measured imprecisely in two CI rounds):