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

Extra types in path #11568

Merged
merged 6 commits into from Nov 11, 2022
Merged

Extra types in path #11568

merged 6 commits into from Nov 11, 2022

Conversation

HyunggyuJang
Copy link
Contributor

This PR replaces #11315.
Encodes inline record types in Path.t

  • adds Pextra_ty in Path.t
  • Pext_ty is added by @lpw25 for inline records in variant constructors and extension constructors
    They replace the decoding through Path.typath used before

The goal of the changes is to remove encodings through names that were used before:

  • inline records in variant constructors were represented by a path finished by a lower case name followed by an upper case name
  • inline records in extension constructors were represented by a path finished by two upper case names

Hash types will be removed by a separate PR.

The only remaining such encoding is for abstract row types.

Written with @garrigue and @t6s

This was referenced Sep 27, 2022
typing/typemod.ml Outdated Show resolved Hide resolved
Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

I have done a full review of this PR, and have only comments on the details (plus a point about Shape computation that needs not be resolved for this PR to be merged). See the comments inline.

@@ -154,7 +154,7 @@ let extension_descr ~current_unit path_ext ext =
in
let existentials, cstr_args, cstr_inlined =
constructor_args ~current_unit ext.ext_private ext.ext_args ext.ext_ret_type
path_ext (Record_extension path_ext)
Path.(Pextra_ty (path_ext, Pext_ty)) (Record_extension path_ext)
Copy link
Member

Choose a reason for hiding this comment

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

We discussed this line during our type-system meeting: it is weird that before we would have path_ext on both sides and now we pass two different passes. @HyunggyuJang and @garrigue say that they have looked carefully and they believe that this is the right choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is exactly what @lpw25 made at 94c10c3, we believe it is the way to go.

typing/env.ml Outdated Show resolved Hide resolved
typing/env.ml Show resolved Hide resolved
typing/path.ml Outdated Show resolved Hide resolved
@@ -460,6 +460,11 @@ let of_path ~find_shape ~namespace =
| Pident id -> find_shape ns id
| Pdot (path, name) -> proj (aux Module path) (name, ns)
| Papply (p1, p2) -> app (aux Module p1) ~arg:(aux Module p2)
| Pextra_ty (path, extra) -> begin
match extra with
Pcstr_ty _ -> aux Type path
Copy link
Member

Choose a reason for hiding this comment

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

This case (should ideally start with a | and) does not fully make sense, but I think that the issue is with the Shape code, which is not robust enough here to be extended with new paths, and not with the PR itself. I don't think this problem needs to be fixed in this PR.

More details in case Shape people are reading this (again, irrelevant for this PR I think): what we want to do here is to return the cda_shape field of the constructor_data record in the typing environment. But this is not possible with the prototype of this function, which only lets us query the environment on identifiers, not full paths. This is frustrating because Env.find_shape (which is not exposed in env.mli) does exactly the right thing in the Extension_constructor case.

I think that we should change the prototype of the Make_reduce functor to take a Sig_component_kind.t -> Path.t -> Shape.t function, and get rid of of_path. But this is a change that affects Merlin as well.

Another option would be to guarantee that we can recover precise shape information from aux Type path here, enough to compute the path of the constructor itself. (Our input is a path of the form M.t.Foo, meaning the inline-record type of the constructor Foo in the type M.t.) For this, the shape of M.t itself should not be a Leaf, but a product structure containing the shape of each of its constructors. This makes sense semantically, we may do something like this eventually, and it would be necessary if we wanted to decouple the shape-computation from the typer (currently we store all shapes in the environment, but in theory we could do without), but it is a slightly more complex change.

Copy link
Member

Choose a reason for hiding this comment

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

(cc @voodoos)

@HyunggyuJang
Copy link
Contributor Author

@gasche Ready to be merged.

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

4 participants