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

false branch of if-let doesn't report the correct call stack information. #1404

Closed
amano-kenji opened this issue Feb 17, 2024 · 4 comments
Closed

Comments

@amano-kenji
Copy link
Contributor

amano-kenji commented Feb 17, 2024

(defn recurse
  [branch]
  (if-let [ha branch]
    (do
      (ev/sleep 1)
      (debug/stacktrace (fiber/current) "print stack for true branch" "")
      (recurse branch))
    (do
      (ev/sleep 1)
      (debug/stacktrace (fiber/current) "print stack for false branch" "")
      (recurse branch))))

(defn main
  [& args]
  (def arg
    (case (get args 1 "true")
      "true" true
      "false" false
      nil))
  (recurse arg))

With this, debug/stacktrace in the false branch doesn't report its own line in the call stack, but the line where if-let resides.

debug/stacktrace in the true branch reports its own line in the call stack.

@sogaiu
Copy link
Contributor

sogaiu commented Feb 17, 2024

For future readers, see this comment for example invocations along with output and some explanation.

@bakpakin
Copy link
Member

So the issue here is there is an explicit macro expansion here inside the if-let macro that doesn't preserve the source location information. We can fix this issue by making slight modifications to macex1 which does the explicit macro expansion. This should also fix source mapping information for any macros that explicitly expand sub forms manually, instead of the usual case of letting the be.

@sogaiu
Copy link
Contributor

sogaiu commented Feb 18, 2024

I tried 7a2868c with the sample code.

Both invocations produced the expected output here:

$ janet recurse.janet true
alive: print stack for true branch
  in debug/stacktrace [src/core/debug.c] on line 388
  in recurse [recurse.janet] (tailcall) on line 6, column 7
...
$ janet recurse.janet false
alive: print stack for false branch
  in debug/stacktrace [src/core/debug.c] on line 388
  in recurse [recurse.janet] (tailcall) on line 10, column 7
...

@amano-kenji Does it work for you?

@amano-kenji
Copy link
Contributor Author

I tested the latest commit, and the issue seems fixed.

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

No branches or pull requests

3 participants