|
| 1 | +let[@inline never] make n = List.init n Fun.id |
| 2 | + |
| 3 | +exception Exn of int |
| 4 | +let[@inline never] break n = |
| 5 | + raise (Exn n) |
| 6 | + |
| 7 | +let[@inline never] check_backtrace n = |
| 8 | + try |
| 9 | + break n |
| 10 | + with |
| 11 | + | Exn i -> |
| 12 | + let raw_backtrace = Printexc.get_raw_backtrace () in |
| 13 | + let len = Printexc.raw_backtrace_length raw_backtrace in |
| 14 | + assert (len > 0); |
| 15 | + let slot = Printexc.get_raw_backtrace_slot raw_backtrace 0 |
| 16 | + |> Printexc.convert_raw_backtrace_slot in |
| 17 | + let name = Printexc.Slot.format 0 slot |> Option.get in |
| 18 | + Printf.printf "i=%d len=%d name=%s\n" i len name; |
| 19 | + () |
| 20 | + |
| 21 | +let test n = |
| 22 | + let l = make n in |
| 23 | + (*$ |
| 24 | + for i = 1 to Sys.opaque_identity 20 do |
| 25 | + Printf.printf "let a%d = Sys.opaque_identity 1 in\n" i |
| 26 | + done; |
| 27 | + *)let a1 = Sys.opaque_identity 1 in |
| 28 | +let a2 = Sys.opaque_identity 1 in |
| 29 | +let a3 = Sys.opaque_identity 1 in |
| 30 | +let a4 = Sys.opaque_identity 1 in |
| 31 | +let a5 = Sys.opaque_identity 1 in |
| 32 | +let a6 = Sys.opaque_identity 1 in |
| 33 | +let a7 = Sys.opaque_identity 1 in |
| 34 | +let a8 = Sys.opaque_identity 1 in |
| 35 | +let a9 = Sys.opaque_identity 1 in |
| 36 | +let a10 = Sys.opaque_identity 1 in |
| 37 | +let a11 = Sys.opaque_identity 1 in |
| 38 | +let a12 = Sys.opaque_identity 1 in |
| 39 | +let a13 = Sys.opaque_identity 1 in |
| 40 | +let a14 = Sys.opaque_identity 1 in |
| 41 | +let a15 = Sys.opaque_identity 1 in |
| 42 | +let a16 = Sys.opaque_identity 1 in |
| 43 | +let a17 = Sys.opaque_identity 1 in |
| 44 | +let a18 = Sys.opaque_identity 1 in |
| 45 | +let a19 = Sys.opaque_identity 1 in |
| 46 | +let a20 = Sys.opaque_identity 1 in |
| 47 | +(*$*) |
| 48 | + check_backtrace n; |
| 49 | + let l = make (List.length l) in |
| 50 | + Gc.compact (); |
| 51 | + [ |
| 52 | + (*$ |
| 53 | + for i = 1 to Sys.opaque_identity 20 do |
| 54 | + Printf.printf "a%d;\n" i |
| 55 | + done; |
| 56 | + *)a1; |
| 57 | +a2; |
| 58 | +a3; |
| 59 | +a4; |
| 60 | +a5; |
| 61 | +a6; |
| 62 | +a7; |
| 63 | +a8; |
| 64 | +a9; |
| 65 | +a10; |
| 66 | +a11; |
| 67 | +a12; |
| 68 | +a13; |
| 69 | +a14; |
| 70 | +a15; |
| 71 | +a16; |
| 72 | +a17; |
| 73 | +a18; |
| 74 | +a19; |
| 75 | +a20; |
| 76 | +(*$*) |
| 77 | + ]@l |
| 78 | + |> Sys.opaque_identity |
| 79 | + |
| 80 | + |
| 81 | +let () = |
| 82 | + Printexc.record_backtrace true; |
| 83 | + 10_000 |
| 84 | + |> Sys.opaque_identity |
| 85 | + |> test |
| 86 | + |> ignore |
0 commit comments