Do not discard attributes attached to pattern variables#1822
Do not discard attributes attached to pattern variables#1822nojb merged 7 commits intoocaml:trunkfrom
Conversation
trefis
left a comment
There was a problem hiding this comment.
I suggest you squash the second and third commit.
Apart from that everything looks good to me.
I also agree with your choice of not adding the suggested cascading logic in this PR. I think the current GPR should be mergeable fairly quickly and that further steps can be discussed on the original MPR.
typing/typecore.ml
Outdated
| { | ||
| pv_id: Ident.t; | ||
| pv_type: type_expr; | ||
| pv_name: string loc; |
There was a problem hiding this comment.
I believe the pv_name field is useless. Not only is it redundant with the pv_id and pv_loc fields, as far as I can tell it's only "used" to be stuffed in Tcl_fun, and then completely ignored when Tcl_fun is processed in translclass.ml.
This remark is somewhat orthogonal to your PR, but since you're cleaning up that area, might as well go all the way :)
Do you mind trying to add a commit which removes that field?
There was a problem hiding this comment.
This is done, I removed the corresponding field from both Tcl_fun and Tcl_let, which resulted in a nice cleanup.
typing/typecore.ml
Outdated
| | [],(y,_,_,_,_)::_ -> raise (Error (loc, env, Orpat_vars (y, []))) | ||
| | (x,_,_,_,_)::_, (y,_,_,_,_)::_ -> | ||
| | {pv_id = x; _}::_, [] -> raise (Error (loc, env, Orpat_vars (x, []))) | ||
| | [],{pv_id = y; _}::_ -> raise (Error (loc, env, Orpat_vars (y, []))) |
There was a problem hiding this comment.
While you're touching these two lines (and I'm making stylistic comments), do you mind merging the two cases above?
|
Unsure whether it falls under your notion of cascading, while the following will: It might be surprising. |
Ideas/suggestions? |
Indeed, this behavior may be surprising in the case of a |
|
I had a look at the code as well, I agree with everything @trefis said. I vote for option 4: Warn on deprecated attributes in non-nonsensical places. We already warn on nonsensical inline attributes, so there is a precedent. |
|
The problem with warning is that if we warn in one version, and then we improve the behavior in the next version (eg. implement the reasonable cascading behavior), people that want their code to be warning-free on all recent versions will be unable to use the nice behavior. I would rather give a bit more thought to how what is the desirable semantics that start to implement warnings from our current implementation right away. No objection of course for things that we believe do not actually make sense -- rather than things that are not currently supported. |
c30cad3 to
cdc4c6a
Compare
cdc4c6a to
9ef3d3f
Compare
|
Indeed, Alain is correct. I was initially tempted to propose to warn when the set of attributes for a given variable is not the same in all branches. But I can easily imagine people being frustrated by having to repeat the information.
I find the second option more appealing but I'm not sure what the implementation would look like... That is: can we easily and reliably deduplicate attributes present in several branches? |
|
Btw, I confess that 0d6569f brought me joy. I hope writing it felt immensely satisfying. |
|
I think I would be in favor of merging the PR about as it is now. It is not perfect, but it is at a stable point that is strictly better than what we have before, and we can discuss later concerns after. The refactoring patches are good to have now and might be annoying to rebase later. |
|
OK, let's merge this now and leave further improvements for later. I will merge once the CI passes unless someone beats me to it :) |
One certainly want to ignore all locations when comparing the attributes (including locations deeply nested in the payload); I believe this can be done easily using Ast_mapper. But it would be the first case, I think, where we compare Parsetree fragments (using structural equality). I think the use of structural equality should be ok, technically, but is that a good semantics? Yet another solution would be to merge without deduplication: this is straightforward to implement and document. This might interact badly with a future addition of implicit cascading, but:
|
Personally, I don't think this "cascading" is the right solution to this problem. The underlying cause of the problem is that we are treating the attributes of bindings as semantic attributes on variables. What we should be doing is having a |
Adding a field to value descriptions sounds like the good solution. I will give it a shot. Thanks! |
This PR adds the necessary plumbing so that attributes attached to variables bound in patterns are not discarded. It is motivated by MPR#7719, where it is observed that
[@@deprecated]attributes attached to top-levellets are ignored.For example, this PR makes it so that
will trigger the deprecation warning.
The PR is better reviewed commit-by-commit:
Typecore.pattern_variableby a record type to aid readability;pattern_variabletype; andIn order to fix MPR#7719 some kind of cascading logic is needed so that
[@@deprecated]attributes attached to aletare inherited by the individual variables bounds in the pattern. But it wasn't clear to me that it was a good idea for this to be the case for arbitrary attributes. Maybe special casing some attributes (such as[@@deprecated]) would be a better idea.