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

Terminating semi-colon ignored by -strict-sequence #7193

Closed
vicuna opened this issue Mar 22, 2016 · 9 comments
Closed

Terminating semi-colon ignored by -strict-sequence #7193

vicuna opened this issue Mar 22, 2016 · 9 comments

Comments

@vicuna
Copy link

vicuna commented Mar 22, 2016

Original bug ID: 7193
Reporter: @lpw25
Status: acknowledged (set by @damiendoligez on 2016-03-24T18:19:11Z)
Resolution: open
Priority: normal
Severity: feature
Target version: undecided
Category: typing
Related to: #6961
Monitored by: @gasche @diml @jmeber @hcarty

Bug description

I think that when strict sequence is turned on, the following code:

let f foo bar =
let a =
foo ();
bar ();
in
a;;

should have type:

val f : (unit -> unit) -> (unit -> unit) -> unit =

rather than the current:

val f : (unit -> unit) -> (unit -> 'a) -> 'a =

as this would be more consistent.

It somewhat depends on how you think of strict sequence, but I think one reasonable meaning is "force things before semi-colons to have type unit" and, for this meaning, the above is a bug.

@vicuna
Copy link
Author

vicuna commented Mar 23, 2016

Comment author: @garrigue

There seems to be a misunderstanding here.
The double semicolon is not a sequencing operator, but a separator between toplevel elements.
Just by looking into the compiler source, you will see that in many files every phrase is separated by a double semicolon, most of them clearly having a type that is not unit.

I see no simple way to enforce the result type of a function to be unit, out of adding a type annotation.
For toplevel computations, a good policy is to write
let () = ...
as it forces this expression to have unit type.

@vicuna
Copy link
Author

vicuna commented Mar 23, 2016

Comment author: @lpw25

The double semicolon is not a sequencing operator, but a separator between toplevel elements.

Sorry, my description was not clear. I was referring to the ; after bar () not the ;; after a (which was only there because I was running the example in the toplevel).

@vicuna
Copy link
Author

vicuna commented Mar 24, 2016

Comment author: @damiendoligez

I agree this would be desirable, but I think it'll involve non-trivial changes to the parser so don't hold your breath.

@vicuna
Copy link
Author

vicuna commented Mar 24, 2016

Comment author: @gasche

Or: do push for a menhir parser when the time to discuss integration comes, to make non-trivial changes great again.

@vicuna
Copy link
Author

vicuna commented Mar 24, 2016

Comment author: @alainfrisch

See #522 . I don't think that Menhir would make this any easier, honestly.

@vicuna
Copy link
Author

vicuna commented Mar 24, 2016

Comment author: @alainfrisch

Considering the amount of changes that were required on the ocaml code base itself to compile after this change, it seems this would likely break many packages around. Time for a -really-strict-sequence mode?

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label Mar 24, 2021
@gasche
Copy link
Member

gasche commented Mar 24, 2021

If I understand correctly, currently let f = foo; bar; in ... and let f = foo; bar in ... generate the same parsetree, and this is a problem because we would like -strict-sequence to enforce bar : unit in the first case. To solve the present issue we would need the AST to keep track of trailing semicolons.

One issue is that there is no obvious way to do this without changing the AST format. Currently we have Pexp_sequence of expr * expr, we could consider using say expr * expr option, or adding an extra constructor Pexp_uniseq of expr. Neither are fully satisfying (the first is a fairly invasive change, the second is odd), and changing the AST format makes ppx people unhappy (although things are better than they used to thanks to the ppxlib takeover).

One could consider, as an alternative, desugaring a; into a; (). On the plus side, the type-constraints on a are as expected whether or not -strict-sequence is set. On the minus side, the type globally changes to unit and the returned value to (), so this is a semantic change for some programs.

Finally, we could also consider desugaring a; into a (as currently) when -strict-sequence is not set, and into a; () when it is set. This is bad in various ways (I would strongly prefer configuration not to affect the parsetree, it does for -unsafe and it's ugly), but perfectly backwards-compatible.

@github-actions github-actions bot removed the Stale label Mar 26, 2021
@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants