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

Pack parameters to unification in unification_environment #12109

Merged
merged 6 commits into from
May 26, 2023

Conversation

t6s
Copy link
Contributor

@t6s t6s commented Mar 15, 2023

Ctype.unify and related functions used to take a reference to the environment as a parameter and some additional flags via global variables.
This PR packs them in a type unification_environment whose contents depend on the unification mode.

We have uniformly used the variable name uenv for values of type unification_environment and env for Env.t.

@gasche
Copy link
Member

gasche commented Mar 16, 2023

cc @goldfirere

Copy link
Contributor

@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.

Looks very nice -- thank you! Just a few requests for clarifying comments, etc.



(* a local constraint can be added only if the rhs
of the constraint does not contain any Tvars.
They need to be removed using this function *)
let reify env t =
let fresh_constr_scope = get_gadt_equations_level () in
let reify uenv t =
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment saying this can be called only in Pattern mode?

@@ -2466,30 +2469,23 @@ let find_lowest_level ty =
end
in find ty; unmark_type ty; !lowest

let add_gadt_equation env source destination =
let add_gadt_equation uenv source destination =
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment saying this can be called only in Pattern mode? Perhaps this is obvious from the name of the function, but I still think stating preconditions like this help newcomers to the codebase.

typing/ctype.ml Outdated
| Pattern r -> TypePairs.mem r.unify_eq_set (order_type_pair t1 t2)

(* unification during type constructor expansion; more
relaxed than [Expression] in some cases. *)
Copy link
Contributor

Choose a reason for hiding this comment

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

Though I see that this comment is just moved, could you maybe make "in some cases" more explicit? On the call this morning, you had a nice description of what this means, so putting that here -- or on the in_subst field declaration -- would be helpful.

typing/ctype.ml Outdated
@@ -2571,16 +2567,13 @@ let unify_package env unify_list lv1 p1 fl1 lv2 p2 fl2 =


(* force unification in Reither when one side has a non-conjunctive type *)
(* TODO: this could also be put in unification_environment? *)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks to me that this would go somewhere else -- maybe just a (labeled) boolean that gets passed around the eqtype functions? Those functions don't otherwise need the new env type available, so it seems that putting rigid_variants there would be a poor fit.`

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still TODO?

| Pattern r ->
let new_umode = Pattern { r with equations_generation = Forbidden } in
Misc.protect_refs [ Misc.R (umode, new_umode) ] f
let without_assume_injective uenv f =
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these functions be non-CPS'd now? That would seem a little simpler.

Could be done in a separate PR, I suppose.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there plans to do this?

typing/ctype.ml Show resolved Hide resolved
@t6s
Copy link
Contributor Author

t6s commented Apr 11, 2023

Rebased and added comments according to Richard's requests.

@gasche
Copy link
Member

gasche commented May 22, 2023

@goldfirere I wonder if you are happy with the revised state of this PR.

Copy link
Contributor

@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.

Still some dangling pieces, but nothing that needs to make it into this patch. Sorry for the delayed response here! I must have missed the notification.

typing/ctype.ml Outdated
@@ -2571,16 +2567,13 @@ let unify_package env unify_list lv1 p1 fl1 lv2 p2 fl2 =


(* force unification in Reither when one side has a non-conjunctive type *)
(* TODO: this could also be put in unification_environment? *)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still TODO?

| Pattern r ->
let new_umode = Pattern { r with equations_generation = Forbidden } in
Misc.protect_refs [ Misc.R (umode, new_umode) ] f
let without_assume_injective uenv f =
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there plans to do this?

@goldfirere
Copy link
Contributor

Is it possible for me to get enough rights in GitHub to Resolve my own conversations (at least)? It's very nice to clear conversations that arise from reviewing as the issues are addressed. Thanks!

@t6s
Copy link
Contributor Author

t6s commented May 26, 2023

@goldfirere I have added comments related to your questions. We do not plan to modify without_* functions or rigid_variants immediately.

Copy link
Contributor

@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.

Thanks!

@gasche gasche merged commit 3d49c1f into ocaml:trunk May 26, 2023
9 checks passed
@gasche
Copy link
Member

gasche commented May 26, 2023

Merged, thank you both for the PR and review work.

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.

None yet

3 participants