-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Experimental control-flow operator #368
Conversation
@jsiek Note my edit to the description that cross-references the issue. |
Thanks Dave! |
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 it's a hassle, but comments on all the new entities is basically a prerequisite for getting a useful review out of me. Those statements are how I evaluate whether a thing does/is what it's supposed to be. Please do that at a minimum and ask me to re-review.
Thanks!
Thanks for the feedback and reminders Dave! |
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 will be a lot easier to review (and a lot easier for future maintainers to read) if there's some kind of prose description of this feature from the point of view of the language user. It doesn't have to be super detailed, since the whole point of this code is to act as a specification, but just a quick introduction to the core vocabulary (e.g. "continuation values"), syntax, and the broad strokes of the semantics. The best place would probably be executable_semantics/README.md
, where it can also act as a "this is a stress-test of the executable_semantics architecture, not a planned Carbon feature" disclaimer.
@geoffromer good idea, I'll add an introduction to this in the README. Thanks! |
improve comment for MakeDelimitStmt Co-authored-by: Dave Abrahams <dabrahams@google.com>
I've implemented an imperative variant of the shift/reset style of continuations. |
Copying a continuation now does a deep copy of its stack. |
After more thinking and more test cases, I flipped back to shallow copy for continuations. Some of the behavior from allowing copies is just too weird, such as double deletes of a local variable (the now deleted test |
Co-authored-by: Geoff Romer <gromer@google.com>
* AST and syntax for delimited control * stashing for later * a little more progress * progress on delimited continuations * delimit, suspend, and resume implemented (draft) * example that generates the natural numbers * fixes * tinkering * changed demo to experimental * comments and name changes * describe delimited continuations in the README * renamed Snapshot to Continuation, edits to comments * Update executable_semantics/ast/statement.h improve comment for MakeDelimitStmt Co-authored-by: Dave Abrahams <dabrahams@google.com> * Update executable_semantics/interpreter/interpreter.cpp remove snake_case Co-authored-by: Dave Abrahams <dabrahams@google.com> * edits to comments, change name of variable * updates to handle review edits * trailing whitespace * fixes to delimited continuations, added more tests, also fixed assignment to do a copy * improvements from Geoffrey * new test from Geoffrey, fix for empty blocks * more suggestions from Geoffrey * more tests for delimited continuations, renaming some of them * renamed test files * improve a comment * sketch of creating continuation * initial implementation of shift/reset style continuations * more documentation * fix some camel case * implemented deep copy of continuations, added a test case for it * fixed a bug and got the recursive test case working * removed __delimit, polished up __continuation * back to shallow copy for continuations * suggestions from Geoffrey * removed structured binding (for now) * Update executable_semantics/ast/expression.cpp Co-authored-by: Geoff Romer <gromer@google.com> * responses to Geoffrey Co-authored-by: Dave Abrahams <dabrahams@google.com> Co-authored-by: Geoff Romer <gromer@google.com>
This adds "delimited continuations" with
delimit
,yield
andresume
features that provide a kind of resumable exception with first-class continuations. The point of adding this feature is not to say that we want delimited continuations in Carbon, but this represents a place-holder for other powerful control-flow features that might eventually be in Carbon, such as coroutines, threads, exceptions, etc. As we refactor the executable semantics, having this feature in place will keep us honest and prevent us from accidentally simplifying the interpreter to the point where it can't handle features like this one.Instead of delimited continuations, we could have instead done regular continuations with callcc. However, there seems to be a consensus amongst the experts that delimited continuations are better than regular ones.
This implementation needs more testing. However, the examples from the literature that I'd like to use as tests all use
lambda
, so I'm going to do an experimentallambda
and then circle back to add more tests for the delimited continuations.Fixes #349