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

nkComesFrom seems deadcode (but used a lot); ok to remove? #11

Open
timotheecour opened this issue Jun 20, 2020 · 3 comments
Open

nkComesFrom seems deadcode (but used a lot); ok to remove? #11

timotheecour opened this issue Jun 20, 2020 · 3 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Jun 20, 2020

@Araq
while working on something else I noticed that nkComesFrom is deadcode (never set) even though it's used quite a bit, so removing it would declutter a bit.

  • is there any chance nkComesFrom might be revived or is the new code path in wrapInComesFrom strictly better so that nkComesFrom can be removed + its corresponding code cleaned up?
  • was the goal of nkComesFrom to produce stacktrace entries for templates/macros as if they were function calls? if so, it would be useful to have it as an option (i had a WIP on that but done differently) but not sure that's what it was about
proc wrapInComesFrom*(info: TLineInfo; sym: PSym; res: PNode): PNode =
  when true:
    result = res
    result.info = info
    if result.kind in {nkStmtList, nkStmtListExpr} and result.len > 0:
      result.lastSon.info = info
    when false:
      # this hack is required to
      var x = result
      while x.kind == nkStmtListExpr: x = x.lastSon
      if x.kind in nkCallKinds:
        for i in 1..<x.len:
          if x[i].kind in nkCallKinds:
            x[i].info = info
  else:
    result = newNodeI(nkStmtListExpr, info)
    var d = newNodeI(nkComesFrom, info)
    d.add newSymNode(sym, info)
    result.add d
    result.add res
    result.typ = res.typ

eg, this code is also dead because of that:

    if it.kind == nkComesFrom:
      if hasNimFrame and frameName == nil:
        inc p.labels
        frameName = "FR" & rope(p.labels) & "_"
        let theMacro = it[0].sym
        add p.s(cpsStmts), initFrameNoDebug(p, frameName,
           makeCString theMacro.name.s,
           quotedFilename(p.config, theMacro.info), it.info.line.int)

as well as initFrameNoDebug + deinitFrameNoDebug + some other code

@Araq
Copy link
Member

Araq commented Jun 20, 2020

The idea of ComesFrom is that template expansions do not lose one debug stack frame. As you can see, the implementation was never finished but I think the idea is a good one so I'd rather keep the dead code.

@timotheecour
Copy link
Member Author

just to clarify: so the goal was indeed what i suspected, to treat template/macro calls as if they were function calls, ie:

template bar() = doAssert false
proc fn=bar()
fn()

with nim --stacktracetemplates would produce something like:

stacktrace:
main.nim(1) in bar
main.nim(2) in fn

?

if so, yes, it's a good idea (but i was thinking of a different implementation to achieve that)

if not, please clarify maybe with an example

@Araq
Copy link
Member

Araq commented Jun 20, 2020

Yes, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants