-
Notifications
You must be signed in to change notification settings - Fork 206
Add configuration to control whether let-punning is used #2746
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
Add configuration to control whether let-punning is used #2746
Conversation
EmileTrotignon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good, except maybe the documentation which could have an exemple and more explicit wording.
doc/manpage_ocamlformat.mld
Outdated
| Name punning in extended let bindings preserve uses let-punning | ||
| only when it exists in the source. always uses let-punning whenever | ||
| possible. never never uses let-punning. The default value is | ||
| preserve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not the style of the current documentation, but I think an example of what let punning is should included.
Also regarding the name, I thought a let-binding is any use of let, but this only concerns bindings with let operators ? This does not have to be reflected in the name, but the documentation should probably say something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that it's not possible to add line breaks in the documentation, forcing the explanation to be concise. This is the output of cmdliner, which removes line breaks and reflow the text.
I'd be totally in favor of a new way of generating the list of option in the documentation and taking advantage of Odoc markup (paragraph, lists, text blocks). The cmdliner output must stay thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the name to your suggestion from the issue, letop-punning. I also made an attempt at including an example in this doc, let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc looks good to me ! It's a bit messed up because of the way we pass it through cmdliner but that can be improved independently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that it's not possible to add line breaks in the documentation, forcing the explanation to be concise. This is the output of cmdliner, which removes line breaks and reflow the text.
I wasn't aware, thanks. I agree it would be better with improvement
Julow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the discussion on documentation, I'm totally in favor of this change :)
doc/manpage_ocamlformat.mld
Outdated
| Name punning in extended let bindings preserve uses let-punning | ||
| only when it exists in the source. always uses let-punning whenever | ||
| possible. never never uses let-punning. The default value is | ||
| preserve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that it's not possible to add line breaks in the documentation, forcing the explanation to be concise. This is the output of cmdliner, which removes line breaks and reflow the text.
I'd be totally in favor of a new way of generating the list of option in the documentation and taking advantage of Odoc markup (paragraph, lists, text blocks). The cmdliner output must stay thought.
lib/Conf.ml
Outdated
| ; Decl.Value.make ~name:"always" `Always | ||
| "$(b,always) uses let-punning whenever possible." | ||
| ; Decl.Value.make ~name:"never" `Never | ||
| "$(b,never) never uses let-punning." ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the difference between never and preserve clearer, I think you should say that existing code using let-punning will be rewritten without.
|
Question: Would this be better in this PR or in another PR? I don't currently have 'preserve' working for these, because that requires parser changes, but I think I could get that done |
That's fantastic ! |
This is the type of parser changes that we try to do, so please do that ! Don't forget to have the loc of every node you add (maybe in that case all the locs are here already) Thats because comments moving around are caused by not knowing the loc of certain tokens, and therefore having no way of knowing if the comment was before or after said token. |
|
I am merging once the CI is green (except for that benchmark which always fails) |
|
Thanks @EmileTrotignon, I was wondering about that one. The rest all look like they passed |
|
Yeah, I think the benchmark has a dependency on libpcre3dev which is a recently defunct debian package. Lets merge ! |
Adds option
--let-binding-punning={preserve|always|never}to control whether ocamlformat outputslet punning (open to suggestions on naming).
Default is
preservein all profiles to match the current release's behavior.Closes #2743