Skip to content

Lambda lifting: only lift functions that have free variables #1885

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

OlivierNicole
Copy link
Contributor

This addresses the second remark in #1792: lifted functions that have no free variables don't need to be wrapped.

@OlivierNicole OlivierNicole force-pushed the improve-lambda-lifting branch from 3a5a2d8 to b9076fb Compare March 14, 2025 16:41
@hhugo
Copy link
Member

hhugo commented Apr 11, 2025

What's the status of this ?

This addresses the second remark in ocsigen#1792: lifted functions that have no
free variables don't need to be wrapped.
@OlivierNicole OlivierNicole force-pushed the improve-lambda-lifting branch from b9076fb to dd2219d Compare April 28, 2025 14:14
@OlivierNicole
Copy link
Contributor Author

It’s a small improvement, currently only used for --effects=double-translation, and is ready for review.

@vouillon
Copy link
Member

In this functor, one should be able to lift without wrapper both f and g.

module F (X : sig end) = struct
  let f x = prerr_endline x
  let x = 1
  let g x = f x; f x
end

Sequences of functions are not handled:

module G (X : sig end) = struct
  let f x = prerr_endline x
  let g x = f x; f x
end

Neither are mutually recursive functions:

module H (X : sig end) = struct
  let rec h x y =
    if x > 0 then i x y else prerr_endline y
  and i x y =
    h (x - 1) y
end

Maybe one should use Strongly_connected_components to distinguish functions that are really mutually recursive from functions that just follow one-another?

@OlivierNicole
Copy link
Contributor Author

We could, it would be a further improvement on the gain that the present state of this PR brings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants