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

Fix miscompilation of method delegation #10764

Merged
merged 6 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ OCaml 4.14.0
- #10735: Uncaught unify exception from `build_as_type`
(Jacques Garrigue, report and review by Leo White)

- #10763, #10764: fix miscompilation of method delegation
(Alain Frisch, review by Vincent Laviron and Jacques Garrigue)


OCaml 4.13 maintenance branch
Expand Down
9 changes: 1 addition & 8 deletions lambda/translclass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,13 @@ let transl_class_rebind ~scopes cl vf =

(* Rewrite a closure using builtins. Improves native code size. *)

let rec module_path = function
Lvar id ->
let s = Ident.name id in s <> "" && s.[0] >= 'A' && s.[0] <= 'Z'
| Lprim(Pfield _, [p], _) -> module_path p
| Lprim(Pgetglobal _, [], _) -> true
| _ -> false

let const_path local = function
Lvar id -> not (List.mem id local)
| Lconst _ -> true
| Lfunction {kind = Curried; body} ->
let fv = free_variables body in
List.for_all (fun x -> not (Ident.Set.mem x fv)) local
| p -> module_path p
| _ -> false

let rec builtin_meths self env env2 body =
let const_path = const_path (env::self) in
Expand Down
14 changes: 14 additions & 0 deletions testsuite/tests/basic/objects.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(* TEST *)


(* Non-regression for bug #10763, fixed in #10764 *)

module W = struct
let r = ref (object method m x = Printf.printf "BAD %i\n%!" x end)
end

let proxy = object method m = (!W.r) # m end

let () =
W.r := object method m x = Printf.printf "OK %i\n%!" x end;
proxy # m 3
1 change: 1 addition & 0 deletions testsuite/tests/basic/objects.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK 3