guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

219/376: Add ‘deepSeq’ primop


From: Ludovic Courts
Subject: 219/376: Add ‘deepSeq’ primop
Date: Wed, 28 Jan 2015 22:05:11 +0000

civodul pushed a commit to tag 1.8
in repository guix.

commit 0cd6596b0e75870dc59f17848c6c152e2b2c6dba
Author: Eelco Dolstra <address@hidden>
Date:   Mon Sep 22 16:03:55 2014 +0200

    Add ‘deepSeq’ primop
    
    Note that unlike ‘lib.deepSeq’ in Nixpkgs, this handles cycles.
---
 src/libexpr/primops.cc           |   11 +++++++++++
 tests/lang/eval-fail-deepseq.nix |    1 +
 tests/lang/eval-okay-deepseq.exp |    1 +
 tests/lang/eval-okay-deepseq.nix |    1 +
 4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 2da15b3..a25bd88 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -392,6 +392,16 @@ void prim_seq(EvalState & state, const Pos & pos, Value * 
* args, Value & v)
 }
 
 
+/* Evaluate the first argument deeply (i.e. recursing into lists and
+   attrsets), then return the second argument. */
+void prim_deepSeq(EvalState & state, const Pos & pos, Value * * args, Value & 
v)
+{
+    state.forceValueDeep(*args[0]);
+    state.forceValue(*args[1]);
+    v = *args[1];
+}
+
+
 /* Evaluate the first expression and print it on standard error.  Then
    return the second expression.  Useful for debugging. */
 static void prim_trace(EvalState & state, const Pos & pos, Value * * args, 
Value & v)
@@ -1435,6 +1445,7 @@ void EvalState::createBaseEnv()
 
     // Strictness
     addPrimOp("__seq", 2, prim_seq);
+    addPrimOp("__deepSeq", 2, prim_deepSeq);
 
     // Debugging
     addPrimOp("__trace", 2, prim_trace);
diff --git a/tests/lang/eval-fail-deepseq.nix b/tests/lang/eval-fail-deepseq.nix
new file mode 100644
index 0000000..9baa49b
--- /dev/null
+++ b/tests/lang/eval-fail-deepseq.nix
@@ -0,0 +1 @@
+builtins.deepSeq { x = abort "foo"; } 456
diff --git a/tests/lang/eval-okay-deepseq.exp b/tests/lang/eval-okay-deepseq.exp
new file mode 100644
index 0000000..8d38505
--- /dev/null
+++ b/tests/lang/eval-okay-deepseq.exp
@@ -0,0 +1 @@
+456
diff --git a/tests/lang/eval-okay-deepseq.nix b/tests/lang/eval-okay-deepseq.nix
new file mode 100644
index 0000000..53aa4b1
--- /dev/null
+++ b/tests/lang/eval-okay-deepseq.nix
@@ -0,0 +1 @@
+builtins.deepSeq (let as = { x = 123; y = as; }; in as) 456



reply via email to

[Prev in Thread] Current Thread [Next in Thread]