add compiler/debugutils.nim to help debugging compiler #17652
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
add compiler/debugutils.nim; this module (intended to grow) adds utilities to help debugging the compiler.
When nim is built without -d:nimDebugUtils, it has no effect; with -d:nimDebugUtils, it enables some callbacks that help with debugging.
For now this helps with the issue mentioned in #17541, by providing a better fix: instead of SIGSEGV (as before this PR) or returning a dummy path (as with #17541), we return a valid path (see #17541 (comment) for how to reproduce).
We cache a global ConfigRef (again, this is only enabled via
-d:nimDebugUtils
), which allows client code to access it in any context, without having to forward ConfigRef all the way to the code that requires it during a debugging session, thus making debugging easier.future work
I've already implemented a number of those in a private fork, so this is a start.
-d:nimDebugUtils
is specified.astalgo.debug
, but its functionality is limited. I've been using the (fully generic) pretty printing described in Every value should be printable with echo RFCs#203 (comment) which really helps with debugging some compiler issues, when you easily need to inspect recursive cyclic data structures such as PNode, PType, PSym.more debugging utilies lowers the barrier for fixing compiler bugs.