git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #16506 from Profpatsch/debug-trace

traceSeq, traceValSeq, deprecate strict

commitd21981c2a8419df79e96e3edded7c5008634f251 authorRok Garbas <rok@garbas.si> dateSun 7 Aug 2016, 03:49 (10 years ago) parentd6d4cf193bbe13
1 file changed+7−21
lib/debug.nix+7−21
lib/debug.nix+7−21
@@ -19,6 +19,10 @@ rec {
1919 traceXMLVal = x: trace (builtins.toXML x) x;
2020 traceXMLValMarked = str: x: trace (str + builtins.toXML x) x;
2121
22+ # strict trace functions (traced structure is fully evaluated and printed)
23+ traceSeq = x: y: trace (builtins.deepSeq x x) y;
24+ traceValSeq = v: traceVal (builtins.deepSeq v v);
25+
2226 # this can help debug your code as well - designed to not produce thousands of lines
2327 traceShowVal = x : trace (showVal x) x;
2428 traceShowValMarked = str: x: trace (str + showVal x) x;
@@ -69,27 +73,9 @@ rec {
6973 # usage: { testX = allTrue [ true ]; }
7074 testAllTrue = expr : { inherit expr; expected = map (x: true) expr; };
7175
72− # evaluate everything once so that errors will occur earlier
73− # hacky: traverse attrs by adding a dummy
74− # ignores functions (should this behavior change?) See strictf
75− #
76− # Note: This should be a primop! Something like seq of haskell would be nice to
77− # have as well. It's used fore debugging only anyway
78− strict = x :
79− let
80− traverse = x :
81− if isString x then true
82− else if isAttrs x then
83− if x ? outPath then true
84− else all id (mapAttrsFlatten (n: traverse) x)
85− else if isList x then
86− all id (map traverse x)
87− else if isBool x then true
88− else if isFunction x then true
89− else if isInt x then true
90− else if x == null then true
91− else true; # a (store) path?
92− in if traverse x then x else throw "else never reached";
76+ strict = v:
77+ trace "Warning: strict is deprecated and will be removed in the next release"
78+ (builtins.seq v v);
9379
9480 # example: (traceCallXml "myfun" id 3) will output something like
9581 # calling myfun arg 1: 3 result: 3