about summary refs log tree commit diff
path: root/src/fix.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/fix.cc')
-rw-r--r--src/fix.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/fix.cc b/src/fix.cc
index 5405190f3d6b..e50d77620cd7 100644
--- a/src/fix.cc
+++ b/src/fix.cc
@@ -18,6 +18,13 @@ struct EvalState
     NormalForms normalForms;
     PkgPaths pkgPaths;
     PkgHashes pkgHashes; /* normalised package hashes */
+    Expr blackHole;
+
+    EvalState()
+    {
+        blackHole = ATmake("BlackHole()");
+        if (!blackHole) throw Error("cannot build black hole");
+    }
 };
 
 
@@ -64,8 +71,6 @@ static Expr substExpr(string x, Expr rep, Expr e)
         }
     }
 
-    /* ??? unfair substitutions? */
-
     /* Generically substitute in subterms. */
 
     if (ATgetType(e) == AT_APPL) {
@@ -345,9 +350,14 @@ static Expr evalExpr(EvalState & state, Expr e)
     /* Consult the memo table to quickly get the normal form of
        previously evaluated expressions. */
     NormalForms::iterator i = state.normalForms.find(e);
-    if (i != state.normalForms.end()) return i->second;
+    if (i != state.normalForms.end()) {
+        if (i->second == state.blackHole)
+            throw badTerm("infinite recursion", e);
+        return i->second;
+    }
 
     /* Otherwise, evaluate and memoize. */
+    state.normalForms[e] = state.blackHole;
     Expr nf = evalExpr2(state, e);
     state.normalForms[e] = nf;
     return nf;