Skip to content

Commit 751045d

Browse files
committed
Do not use patch_env anymore
`Env.without_cmis` has an issue in 4.04 and 4.05: it corrupts the environment, making the toplevel unusable after (see ocaml/ocaml#1223). The `patch_env` function in mdx makes it a noop instead. This prevents corruption, but will display different results in some cases. This commit removes that workaround. This has two benefits: - this removes a complex piece of code, which relies on unsafe behavior - this aligns the mdx behavior for recent compilers (after 2017) with what the toplevel does in these corner cases
1 parent 3361efb commit 751045d

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#### Fixed
1010

11+
- Use the same output as the normal toplevel. Mdx used to carry an unsafe patch
12+
to work around a bug fixed in OCaml 4.06 and that patch would change the
13+
printed types in some corner cases. (#322, @emillon)
14+
1115
#### Removed
1216

1317
#### Security

lib/top/mdx_top.ml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -537,35 +537,6 @@ let verbose t =
537537
let silent t =
538538
add_directive ~name:"silent" ~doc:"Be silent" (`Bool (fun x -> t.silent <- x))
539539

540-
(* BLACK MAGIC: patch field of a module at runtime *)
541-
let monkey_patch (type a) (m : a) (type b) (prj : unit -> b) (v : b) =
542-
let m = Obj.repr m in
543-
let v = Obj.repr v in
544-
let v' = Obj.repr (prj ()) in
545-
if v' == v then ()
546-
else
547-
try
548-
for i = 0 to Obj.size m - 1 do
549-
if Obj.field m i == v' then (
550-
Obj.set_field m i v;
551-
if Obj.repr (prj ()) == v then raise Exit;
552-
Obj.set_field m i v')
553-
done;
554-
invalid_arg "monkey_patch: field not found"
555-
with Exit -> ()
556-
557-
let patch_env () =
558-
let module M = struct
559-
module type T = module type of Env
560-
561-
let field () = Env.without_cmis
562-
563-
let replacement f x = f x
564-
565-
let () = monkey_patch (module Env : T) field replacement
566-
end in
567-
()
568-
569540
let protect f arg =
570541
try
571542
let _ = f arg in
@@ -604,7 +575,6 @@ let init ~verbose:v ~silent:s ~verbose_findlib ~directives ~packages ~predicates
604575
Mdx.Compat.init_path ();
605576
Toploop.toplevel_env := Compmisc.initial_env ();
606577
Sys.interactive := false;
607-
patch_env ();
608578
List.iter
609579
(function
610580
| Directory path -> Topdirs.dir_directory path

0 commit comments

Comments
 (0)