janestreet / janestreet/magic-trace
Broken stack (with "1 instruction trace errors" warning) on non-tailrecursive code
- 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):

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
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