Skip to content
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

lib/debug.nix overhaul #38368

Merged
merged 12 commits into from Apr 27, 2018
Merged

lib/debug.nix overhaul #38368

merged 12 commits into from Apr 27, 2018

Conversation

Profpatsch
Copy link
Member

@Profpatsch Profpatsch commented Apr 3, 2018

The debug module is very useful for day-to-day nix programming, but hasn’t seen a lot of care and aquired quite a lot of cruft.

Main changes:

  • add *Val*Fn group of functions
  • remove deprecated strict function
  • deprecate the showVal group of functions because traceSeqN should be strictly more general
  • deprecate the Xml-group of functions, because they are mostly trivial and/or overly specific
  • deprecate traceValIfNot and addErrorContextToAttrs
  • document the module and tracing functions

More detailed reasoning is included in each commit description.

@makefu
Copy link
Contributor

makefu commented Apr 3, 2018

I think it would be nice to have a consistent write-up (or at least a reference entry) on how to use these functions, not only in the comment field above the code but in the manual itself. This is related to NixOS/nix#701 and
NixOS/nix#702

@Profpatsch
Copy link
Member Author

Profpatsch commented Apr 3, 2018

@makefu I can mention the debug module in the manual (similar to how generators is mentioned), but would rather not duplicate the docstrings (because that will go out of sync sooner rather than later).

If there’s a debugging tutorial, it should most likely go into a new chapter of the nix pills, which have been designated as our official tutorial as far as I can see.

@makefu
Copy link
Contributor

makefu commented Apr 3, 2018

@Profpatsch For newcomers that kind of "documentation" is far from optimal. When you start with nix and nixpkgs it is not very obvious to look for solutions inside the implementation source code.

IMHO the nixpkgs libs need a reference similar to what we have for the modules and packages, however to solve this is out of scope for this PR which looks fine.

lib/default.nix Outdated
@@ -117,7 +117,7 @@ let
traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq
traceValSeqFn traceValSeqN traceValSeqNFn traceShowVal
traceShowValMarked showVal traceCall traceCall2 traceCall3
traceValIfNot runTests testAllTrue strict traceCallXml
traceValIfNot runTests testAllTrue traceCallXml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs release notes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

lib/debug.nix Outdated
@@ -56,19 +56,25 @@ rec {
traceShowVal = x: trace (showVal x) x;
traceShowValMarked = str: x: trace (str + showVal x) x;
attrNamesToStr = a: lib.concatStringsSep "; " (map (x: "${x}=") (attrNames a));
showVal = x:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't clear to me that traceSeqN is an improvement over showVal for this use case. Can you provide some examples of the two's output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showVal displays the value with one layer of depth. traceValSeqN 1 does the same, traceValSeqN 2 does the same for a depth of two layers and so forth.

To be fair, the display is different, but I don’t think there is any information in showVal that cannot be seen in the output of traceValSeqN.

lib/debug.nix Outdated
trace ( "Warning: `traceXMLValMarked` is deprecated "
+ "and will be removed in the next release." )
(trace (str + builtins.toXML x) x);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need release notes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -33,7 +33,7 @@ let
configType = mkOptionType {
name = "nixpkgs-config";
description = "nixpkgs config";
check = traceValIfNot isConfig;
check = x: if isConfig x then true else lib.traceSeqN 1 x false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the named one, actually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s locally let-named in the rebased commit.

@Profpatsch
Copy link
Member Author

@makefu Added an initial section to the manual in the last commit. It is more of a stub for now (but at least users now find something when they search for debug (in the right manual)).

@grahamc
Copy link
Member

grahamc commented Apr 3, 2018

I think all the functions which have been deprecated need:

  1. release notes
  2. their deprecation warnings to include what to replace them with

@Profpatsch
Copy link
Member Author

Added release notes & replacement instructions in the last commit.

<section xml:id="sec-debug">
<title>Debugging Nix Expressions</title>

<para>Nix is a unityped, dynamic language, this means every value can
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unityped or untyped?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither of those are true 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shlevy Hm, why is nix not unityped?

Copy link
Member

@shlevy shlevy Apr 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[] and {} are of different types. The fact that those are checked at eval time (which, FWIW, can be seen as compile time with respect to the underlying .drv outputs...) doesn't make them not typed!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well, I see eval time more as execution time.

@shlevy shlevy removed their assignment Apr 9, 2018
Being able to modify the value on-the-fly before printing is very useful in
practice.
The grace period was long enough.
The code is re-implemented in terms of `generators.toPretty`, but is strictly
less general than `traceValSeqN`, so we deprecate it.
`attrNamesToStr` is very specific (and pretty trivial), so it doesn’t make sense
to have it in the library.
`traceXMLVal(Marked)` are just a builtin and `trace` and not very useful in
general (trace output should not be parsed anyway).
The function is only used in exactly one module and overly specific (`c` must be
a true predicate for `x`, if not, a specific trace is called).
The function isn’t used anywhere and `addErrorContext` is an undocumented
builtin.
The builtin is explicitely qualified at its two uses in the module system.
Incompletely documented, and a FIXME/bug that has been there for years.
Reason: has overhauled the module quite substantially.
It is more of a stub for now, but at least points to the right file.
@Profpatsch
Copy link
Member Author

Profpatsch commented Apr 13, 2018

I rebased it to remove the release note merge conflicts.

@Profpatsch Profpatsch merged commit 900cec7 into NixOS:master Apr 27, 2018
@Profpatsch
Copy link
Member Author

Merging because no further feedback.
We can roll back selectively if something breaks (although nothing should, since these are debug functions).

Artturin added a commit to Artturin/nixpkgs that referenced this pull request Oct 8, 2022
traceShowVal
traceShowValMarked
attrNamesToStr
showVal
traceXMLVal
traceXMLValMarked
traceCall
traceCall2
traceCall3
traceValIfNot
addErrorContextToAttrs
traceCallXml

they were deprecated in NixOS#38368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants