Make continuations consistently "shallow" (#874)

Prior to this change, `__await` would make a deep copy of the continuation stack, but shallow-copy the individual stack frames within it. As a result, continuations appeared to have shallow semantics so long as the continuation stack had only a single frame.

This change also removes an obsolete test from the brief period when we intended continuations to have deep-copy semantics, which has been passing basically by accident.
This commit is contained in:
Geoff Romer
2021-10-11 14:57:09 -07:00
committed by GitHub
parent 9211c98951
commit d177a08e01
5 changed files with 34 additions and 52 deletions
+10 -4
View File
@@ -493,19 +493,25 @@ class VariableType : public Value {
};
// A first-class continuation representation of a fragment of the stack.
// A continuation value behaves like a pointer to the underlying stack
// fragment, which is exposed by `Stack()`.
class ContinuationValue : public Value {
public:
explicit ContinuationValue(std::vector<Nonnull<Frame*>> stack)
: Value(Kind::ContinuationValue), stack(std::move(stack)) {}
explicit ContinuationValue(Nonnull<std::vector<Nonnull<Frame*>>*> stack)
: Value(Kind::ContinuationValue), stack(stack) {}
static auto classof(const Value* value) -> bool {
return value->kind() == Kind::ContinuationValue;
}
auto Stack() const -> const std::vector<Nonnull<Frame*>>& { return stack; }
// The call stack of the suspended continuation, starting with the top
// frame (the reverse of the usual order). Note that this provides mutable
// access, even when *this is const, because of the reference-like semantics
// of ContinuationValue.
auto Stack() const -> Nonnull<std::vector<Nonnull<Frame*>>*> { return stack; }
private:
std::vector<Nonnull<Frame*>> stack;
Nonnull<std::vector<Nonnull<Frame*>>*> stack;
};
// The String type.