Skip to content

Commit

Permalink
annotate more compiler stacktraces (#1371)
Browse files Browse the repository at this point in the history
## Summary

Stacktraces from within `mirgen` and `transf` are now also annotated
with the line information of the currently processed node, providing
more context for compiler crashes when using `nim_dbg`.
  • Loading branch information
zerbina authored Jul 5, 2024
1 parent 70d59b5 commit 3328b9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/mir/mirgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ import

import std/options as std_options

when defined(nimCompilerStacktraceHints):
import compiler/utils/debugutils

type
DestFlag = enum
## Extra information about an assignment destination. The flags are used to
Expand Down Expand Up @@ -400,6 +403,9 @@ proc exprToPmir(c: var TCtx, n: PNode, sink, mutable: bool): PMirExpr =
n, sink, mutable)

proc genx(c: var TCtx, n: PNode; consume: bool = false) =
when defined(nimCompilerStacktraceHints):
frameMsg(c.graph.config, n)

let e = exprToPmir(c, n, consume, false)
genx(c, e, e.high)

Expand Down
6 changes: 6 additions & 0 deletions compiler/sem/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ import

from compiler/sem/semdata import makeVarType

when defined(nimCompilerStacktraceHints):
import compiler/utils/debugutils

type
PTransCon = ref object # part of TContext; stackable
mapping: TIdNodeTable # mapping from symbols to nodes
Expand Down Expand Up @@ -1205,6 +1208,9 @@ proc commonOptimizations*(g: ModuleGraph; idgen: IdGenerator; c: PSym, n: PNode)
result = n

proc transform(c: PTransf, n: PNode): PNode =
when defined(nimCompilerStacktraceHints):
frameMsg(c.graph.config, n)

when false:
var oldDeferAnchor: PNode
if n.kind in {nkElifBranch, nkOfBranch, nkExceptBranch, nkElifExpr,
Expand Down

0 comments on commit 3328b9e

Please sign in to comment.