mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 10:25:49 +01:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user