Skip to content

Generalize Ctype.free_variables to Ctype.free_variables_list #1518

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

Closed
wants to merge 1 commit into from

Conversation

rtjoa
Copy link
Contributor

@rtjoa rtjoa commented Jun 21, 2023

(See also #1519, which attempts to fix the same problem)

The motivation for this change is similar to #1503's: we sometimes collect all free variables in a list of types tyl by passing a fake TTuple to Ctype.free_variables, as in Ctype.free_variables (Btype.newgenty (Ttuple tyl)).

However, this is fragile to changes in tuples, and in particular, becomes messy when adding labeled tuples: the above would become Ctype.free_variables (Btype.newgenty (Ttuple (List.map (fun t -> None, t) tyl))).

@rtjoa rtjoa marked this pull request as ready for review June 21, 2023 12:50
@ccasin ccasin added the typing label Jun 21, 2023
@rtjoa rtjoa marked this pull request as draft June 21, 2023 14:06
Copy link
Collaborator

@goldfirere goldfirere left a comment

Choose a reason for hiding this comment

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

I think this is a good direction of travel. But there's a small piece of logic that is repeated in this implementation: would it be possible to consolidate the set-up and tear-down steps into a higher order function? I'm thinking of something like run_free_vars_rec : ?env:Env.t -> (unit -> unit) -> type_expr list that fiddles with the free_variables and really_closed variables.

@ccasin
Copy link
Contributor

ccasin commented Jun 26, 2023

@goldfirere Ryan subsequently made a more substantial refactoring of this code in #1519. He and I discussed it, and while it's certainly an improvement, my general feeling was that the cost of differing from upstream was higher than the benefit of having nicer code.

I had forgotten this one was still open. It's a less substantial refactor, so maybe benefits outweigh the costs?

As for your suggestion, I agree that's an improvement. I recommended against doing something similar in #1503 because it seemed much clearer to duplicate the code, but here we don't have the complicated control flow.

@goldfirere
Copy link
Collaborator

Yeah -- I was worried about the upstream interaction, but decided that the change was small enough that any merge conflicts there would be manageable. I don't know how painful it is not to make this change; I'm fine either way (making the change or not). I also like the idea floated in #1519 to prepare an upstream patch with these changes (and then including them locally as well).

@mshinwell
Copy link
Collaborator

@goldfirere what is going to happen with this PR? Nearly a year!

@goldfirere
Copy link
Collaborator

I think we should just close. This should just be an upstream patch, but I'm not inclined to push that through. @ccasin: second opinion?

@ccasin ccasin closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants