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 an infinite-loop construct #1906
Comments
It might be simpler to have typestate recognize |
Could possibly also make an iterator like That would at least cover the case in the referenced issue. |
Well, I guess there are lots of ways to structure the code in the other issue so that it isn't a |
We could also have |
Or change |
Java's typestate knows about |
I think it'd be ok to just accept "while true" as our "infinite loop" form, personally. |
What's wrong with a library function?
|
for one thing, most "infinite" loops actually break... or at least ret. but even if we had break and non-local return, wouldn't type state then have to treat the "forever" library function as special, so as to know that it never returns unless the body breaks? |
If it breaks, it's not a forever loop, and this whole bug doesn't apply: the control paths after the loop are reachable. |
It was more |
Oh, right. Ok, then in that case you would have to manually put in the I looked through the compiler and libraries and see ... a few cases, but only a handful. I guess it's a real case; and given that the cost of "solving" it is extremely low in terms of cognitive burden I won't resist further. I'd say I like brson's suggestion of making the trailing If we solve this "in the language" I've a slight preference for an unadorned |
|
I'm hearing consensus in the meeting in favor of adding |
At meeting, has consensus to implement |
Add a loop {} construct for infinite loops, and use it in test cases. See #1906 for details.
Implemented. Cleanup of existing code-that-uses-while-true is in 35400e1 |
Great, thanks! |
This idea has come up before, but #1905 reminded me that we never really reached agreement on it. I propose adding a new looping construct,
forever [block]
, that has the same semantics aswhile (true) [block]
. The reason to add a special construct would be to allow typestate to recognize that infinite loops run forever, and not yield spurious-looking errors (see #1905 for an example) about functions not returning a value. The current workaround is to dowhile (true) { ... }; fail "Unreachable";
, which isn't terribly burdensome, but is annoying.I realize we're trying not to add stuff, but this issue seems to be a source of confusion, and
while (true)
loops seem to be pretty common.The text was updated successfully, but these errors were encountered: