-
Notifications
You must be signed in to change notification settings - Fork 445
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
A trace function #130
Comments
Yes, this is a great idea and something I've had in the back of my mind for a while. You can sort of debug with error right now -- error foo will print out foo, but will also block execution. One concern is how many implementation hacks this would expose. For example, at the moment, object-level locals are re-evaluated whenever you read a field of the object (as they are desugared into every field). They are not cached like regular thunks. This will give surprising output! However it is probably still useful. |
Hah, didn't realize that. Yeah, I don't think anyone will be expecting particularly sensible properties around the output, other than it somehow representing what the VM is doing. |
It is trivial to add a new builtin that prints str and returns x. I'm not saying that would be the best way to provide this feature, but it would give you something to play with if you wanted to do that. |
I've been meaning to poke around the code for a while. I'll see if I can scrounge together some time one of these days and hack at it, if you don't get sick of waiting for me before that 😄 |
To save some time -- you need to add another builtin to jsonnet_builtin_decl in desugarer.cpp then modify vm.cpp to add the corresponding case to the inner interpreter loop
and I apologize for the hairiness of that code :) |
https://stackoverflow.com/questions/49742536/how-to-printf-in-jsonnet/49760216#49760216 |
I will push a PR soon. |
There might well be one already, but I looked under the "Assertions and Debugging" section of the stdlib docs and only saw assertions.
Basically, I want a function that is equivalent to
local const(str, x) = x;
But that prints
str
tostderr
as a side effect when forced. Very handy for debugging odd execution flow and the like.Both Haskell and Nix call this function
trace
, but I'm open to other ideas.The text was updated successfully, but these errors were encountered: