From 0cd6596b0e75870dc59f17848c6c152e2b2c6dba Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 22 Sep 2014 16:03:55 +0200 Subject: Add ‘deepSeq’ primop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that unlike ‘lib.deepSeq’ in Nixpkgs, this handles cycles. --- src/libexpr/primops.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libexpr') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 2da15b3c53..a25bd8854e 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); -- cgit 1.4.1