Attach infix extension points/attributes on local module/exception/open to structure item instead of enclosing let expression#14009
Conversation
|
If I understand sherlocode correctly, the in-the-wild usage it found is |
|
( |
No, they would not, because the let[@warning "-60"] module C = ... in ... |
| File "w60.ml", line 40, characters 6-27: | ||
| 40 | let module M = struct end in | ||
| ^ | ||
| ^^^^^^^^^^^^^^^^^^^^^ |
There was a problem hiding this comment.
Do you know why the new error location is less precise than the previous one?
There was a problem hiding this comment.
Yes, it is mentioned in #14005: this less precise location matches the one used for the warning in case of global module bindings module M = ... and is a consequence that we share more code after this PR. We could make all cases (local and global) use the more precise location with a bit more plumbing work. I wasn't sure if it was worth it.
|
How are people supposed to silence warning 60 on structure-level module declarations? I'm confused. Is this a bug? |
I don't think so. As I understand it, the |
|
From a distance the behavior you explain is not quite right, because it does not give a way to selectively silence warnings for one declaration while allowing it for other declarations in the same scope. It would be nice if the behavior I had in mind worked, because it would make the code written by our users correct. But this is arguably a distraction from the wider PR. I still have the impression that the change proposed in this PR (with the breaking change) is nicer than the one proposed in the other PR, and I would support it, assuming that the resulting implementation is not more complex (than the one resulting from the other PR). |
Actually, the implementation in this PR is actually simpler as we can share more code between the local and global cases. |
|
I have done an OPAM-wide search using https://git.frama-c.com/pub/frama-c/-/blob/master/src/plugins/inout/operational_inputs.ml#L645 The rest of hits were in vendored copies of compiler code, along a PPX https://github.com/ghilesZ/ppx_wideopen and Given this, I think that the breaking change in this PR is acceptable. @gasche: do you agree? If yes, are you willing to do a review of the PR? |
gasche
left a comment
There was a problem hiding this comment.
This looks good to me, thanks! I agree that the slight behavior change is acceptable.
| item_extension post_item_attributes | ||
| { let docs = symbol_docs $sloc in | ||
| Pstr_extension ($1, add_docs_attrs docs $2) } | ||
| ) |
There was a problem hiding this comment.
I don't understand why there is a special case for Pstr_extension, I wish it was handled like the rest below (or a comment to explain the difference), but this was already present before the PR.
There was a problem hiding this comment.
Actually, I removed this last commit because the same asymmetry exists for signatures. I will open a follow-up PR doing this cleanup everywhere.
Before this change, infix extension points and/or attributes were attached to the AST node of the enclosing let expression, ie: let module%foo[@bar] M = N in ... was parsed as [%foo (let module M = N in ...)[@bar]] After this change, this is parsed as: let [%%foo module M = N [@@bar]] in ... Moreover, ext/attrs are now allowed in following the "let" itself to attach them to the enclosing let: let%foo[@bar] module M = N in ... is parsed as [%foo (let module M = N in ...)[@bar]] This is a breaking change.
90bfe5d to
b318635
Compare
This is an alternative to #14005 that implements the change in semantics mentioned in #14005 (comment).
Concretely, before this PR, infix extension points/attributes appearing in local modules/exceptions/opens are attached to the enclosing let expression:
is parsed as
while after this PR, this is parsed as
(This syntax is introduced in this PR; it is not allowed in
trunk.)This has the advantage that:
To attach extension points/attributes to the enclosing
letnode, one can write them next to theletkeyword (this is introduced in this PR; it is not allowed intrunk):is parsed as
This is a breaking change, but it is being considered because these forms are not used much in the wild. A search in Sherlocode yielded only use of these forms: https://sherlocode.com/?q=let%20module%20%5B%40.
(Note that that a test is expected to fail until #14008 is merged.)