janestreet / janestreet/magic-trace

Broken stack (with "1 instruction trace errors" warning) on non-tailrecursive code

Open
#246 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
OCaml
Stars
6.3k
Forks
209
PR merge metrics
No merged PRs in 30d

Description

For example, running `magic-trace run -full-execution` on this code:

```ocaml
let rec go dir =
if (Unix.lstat dir).st_kind = Unix.S_DIR then
let rec handle_dir d =
match Unix.readdir d with
| exception End_of_file -> Unix.closedir d; ()
| "." | ".." -> handle_dir d
| subdir -> go (Filename.concat dir subdir); handle_dir d
in
handle_dir (Unix.opendir dir)
else
()

(* a large directory structure, for example the ocaml source code checked out via git *)
let dir = "repositories/ocaml"
let () = ignore (go dir)
```

Prints `Warning: 1 instruction trace errors` and shows a cut-off stack as shown below (if a bigger directory is chosen, it happens more than once):

![Screenshot_2022-07-13_21-06-00](https://user-images.githubusercontent.com/1816456/178729810-e4aeebc8-5d79-46e1-88a9-07eaebf77e13.png)

The issue happens in similar code that doesn't use exceptions, so I don't think irregular control flow is the issue. Just for reference, this is in a 4.14 flambda switch and the executable is built with `dune --profile=release`.

Contributor guide

Open the contributing guide

Research direction

Reproduce the warning with the provided OCaml example using `magic-trace run -full-execution`, comparing a small directory with a large one. Investigate how the trace is collected and rendered for non-tailrecursive calls; done means the complete stack is shown without an instruction trace error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
devtools, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.