Support 'let open' in class and class type expressions#1249
Support 'let open' in class and class type expressions#1249alainfrisch merged 6 commits intotrunkfrom
Conversation
| class_expr * class_type option * string list * string list * Concr.t | ||
| (* Visible instance variables, methods and concretes methods *) | ||
| (* Visible instance variables, methods and concretes methods *) | ||
| | Tcl_open of override_flag * Path.t * Longident.t loc * Env.t * class_expr |
There was a problem hiding this comment.
The Env.t parameter never appears to be read anywhere.
There was a problem hiding this comment.
I think it's the same as for the Texp_open case. I assumed this could be used by external tools parsing the .cmt files.
There was a problem hiding this comment.
Fair point, thanks for explaining :)
| rc {cl_desc = Tcl_open (ovf, path, lid, new_val_env, cl); | ||
| cl_loc = scl.pcl_loc; | ||
| cl_type = cl.cl_type; | ||
| cl_env = val_env; |
There was a problem hiding this comment.
You want to use new_val_env here.
There was a problem hiding this comment.
I don't think so. We record here the original env used to type-check the class expression.
There was a problem hiding this comment.
the implementation of Pcl_let a few lines above seems to disagree.
There was a problem hiding this comment.
But it is also possible that it is the handling of Pcl_let which is "wrong". At least I agree it is inconsistent with the way we handle _env fields in other places (eg. expressions)
There was a problem hiding this comment.
My understanding was that the environment here is just there so that we can properly interpret identifiers.
So any of the two environments is ok (the new one has just more information).
At least when it was introduced, the goal was not to be able to use this information to compile source code.
If we want to do that, we should define a more precise semantics.
There was a problem hiding this comment.
My understanding was that the environment here is just there so that we can properly interpret identifiers.
Indeed, a quick look at translclass suggest that cl_env is mostly used on Tcl_ident node. There is also build_class_lets, but it deals with Tcl_let directly (and return the inner env explicitly). The remaining use is through Translobj.oo_wrap/Translobj.oo_add_class, which ends up defining the top_env in transl_class (and then passed to Env.diff). And here I'm a bit lost.
So any of the two environments is ok (the new one has just more information).
If we want to do that, we should define a more precise semantics.
I think the least confusing semantics would be to store the val_env "around" the class expression. This is similar to the semantics of exp_env, pat_env, mod_env. Do you agree?
At least when it was introduced, the goal was not to be able to use this information to compile source code.
I'm not sure what you are referring to, but in my understanding, this more is more about supporting external tools (documentation generators, IDE support, etc) so that they can do some lookups. It's not really about allowing to compile source code fragment (although this might be useful as well).
There was a problem hiding this comment.
Anyway, do we agree that for Pcl_open, it's ok to keep the initial val_env (as for Pcl_fun)? The change to Pcl_let should be dealt with separately.
There was a problem hiding this comment.
I agree that the code for Pcl_open is correct.
|
The need to update both environments seems natural to me. It would be hard to give a semantics of |
trefis
left a comment
There was a problem hiding this comment.
Considering the previous discussion this looks OK to me.
(N.B. I don't have any opinion on the manual changes, as I don't know how the manual is organized)
|
The manual changes look goods to me. I was thinking that using a local open inside of the examples in the class chapter of the tutorial may be nice but this feels very optional since the syntax is easily discoverable starting from the syntax for local open in expression. |
|
@garrigue If you agree with the PR, can you create a formal review? As per the new rule, we need a review from someone with commit rights to merge something that touches the compiler. |
garrigue
left a comment
There was a problem hiding this comment.
The change is a simple one, and easily tested. As any syntactic change, there are many files involved, but there shouldn't be any negative impact on existing code anyway.
4.06 incompatibility was caused by changes to Typedtree in ocaml/ocaml#1118 and ocaml/ocaml#1249.
4.06 incompatibility was caused by changes to Typedtree in ocaml/ocaml#1118 and ocaml/ocaml#1249.
Add support for:
References:
https://caml.inria.fr/mantis/view.php?id=6271
https://caml.inria.fr/mantis/view.php?id=7529
@garrigue I'm not entirely satisfied with the type-checking of open in classes, where the open is performed on both environments val_env/met_env (with a hack to share the usage marker). Do you see a better way?
[EDIT: now ready for review]