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
Changes from 2 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
6 changes: 3 additions & 3 deletions lambda/translclass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,9 @@ let transl_class_rebind ~scopes cl vf =

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

let rec module_path = function
let 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

Expand All @@ -542,7 +541,8 @@ let const_path local = function
| 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
| Lprim(Pfield _, [p], _) -> module_path p
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you also need a case for Lprim(Pgetglobal _, [], _) ?
Couldn't it happen if you pass a first class module wrapping a compilation unit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, but it's a super-rare idiom, esp. because this requires that no coercion is needed between the compilation unit and the expected module type.

| _ -> false

let rec builtin_meths self env env2 body =
let const_path = const_path (env::self) in
Expand Down