From 39155d34ae3453d12ab6e3b9d719e438289941b7 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Wed, 19 Apr 2023 14:22:43 -0700 Subject: [PATCH] Remove experimental continuation support (#2776) Removes `__continuation`, `__await`, and `__run`. In part here, the discussion was that while the feature had been useful for validating the early explorer design, it's no longer needed for that role as the explorer is now quite robust. Continuations have been experimental and, at this point, don't have an owner pushing to a proposal. The triggering factor is that, as we push to address fuzzer issues, I ran into a crash bug in this code; basically, `fn Main() -> i32 { __await; return 0; }`. When I mentioned this, the reaction seemed to trend towards removal of the feature. --- common/fuzzing/carbon.proto | 42 +-- common/fuzzing/proto_to_carbon.cpp | 24 -- explorer/README.md | 82 ---- explorer/ast/ast_kinds.h | 4 - explorer/ast/expression.cpp | 4 - explorer/ast/expression.h | 14 - explorer/ast/statement.cpp | 18 - explorer/ast/statement.h | 99 ----- explorer/ast/value.cpp | 11 - explorer/ast/value.h | 57 --- explorer/ast/value_kinds.def | 2 - explorer/ast/value_transform.h | 5 - explorer/fuzzing/ast_to_proto.cpp | 23 -- .../37fcecce96eb5c913f090b2f1f588e3b82c9d1be | 351 ------------------ .../5947862acd3e020041dcd43ca86f05438a6ab930 | 88 ----- .../63378befc2730b6eeca04e21fc914fce5442844b | 51 --- .../879519ec3f915d5bec166b7c1adbea9be016060b | 135 ------- .../91362973dc5b0ed1e93d5f4e8e1e0b21ed98c3e9 | 97 ----- .../96a504c8350c3d69aef1eb3c63f43f73acc6a899 | 153 -------- .../96f494f4264c4c5ff5f351423d60ab98f6a6b12b | 63 ---- .../bbabf13bb9fd0c2a5c1b23eaaf572dce295176a8 | 173 --------- .../e347085328903bbd4f362337d32f45315dc3bf18 | 316 ---------------- .../e38f21d3adb5fb5eb8138b5175401a9ccfe1163d | 88 ----- .../eb9859dd8a2ab2a66b93655aeb5f01090a55978d | 186 ---------- explorer/interpreter/BUILD | 2 - explorer/interpreter/action_stack.cpp | 45 --- explorer/interpreter/action_stack.h | 13 - explorer/interpreter/interpreter.cpp | 50 --- explorer/interpreter/resolve_control_flow.cpp | 6 - explorer/interpreter/resolve_names.cpp | 17 - explorer/interpreter/resolve_unformed.cpp | 4 - explorer/interpreter/stack_fragment.cpp | 48 --- explorer/interpreter/stack_fragment.h | 51 --- explorer/interpreter/type_checker.cpp | 36 -- explorer/interpreter/type_structure.cpp | 1 - explorer/syntax/lexer.lpp | 8 - explorer/syntax/parser.ypp | 15 - .../await_maintains_scope.carbon | 26 -- .../convert_run.carbon | 31 -- .../creation_is_noop.carbon | 20 - .../fail_auto_return_await.carbon | 18 - .../fail_continuation_syntax.carbon | 17 - .../fail_lifetime.carbon | 29 -- .../fail_recursive_continuation.carbon | 20 - .../fail_return_in_continuation.carbon | 18 - .../recursive.carbon | 40 -- .../experimental_continuation/run.carbon | 21 -- .../run_with_await.carbon | 25 -- .../shallow_copy.carbon | 31 -- 49 files changed, 13 insertions(+), 2665 deletions(-) delete mode 100644 explorer/fuzzing/fuzzer_corpus/37fcecce96eb5c913f090b2f1f588e3b82c9d1be delete mode 100644 explorer/fuzzing/fuzzer_corpus/5947862acd3e020041dcd43ca86f05438a6ab930 delete mode 100644 explorer/fuzzing/fuzzer_corpus/63378befc2730b6eeca04e21fc914fce5442844b delete mode 100644 explorer/fuzzing/fuzzer_corpus/879519ec3f915d5bec166b7c1adbea9be016060b delete mode 100644 explorer/fuzzing/fuzzer_corpus/91362973dc5b0ed1e93d5f4e8e1e0b21ed98c3e9 delete mode 100644 explorer/fuzzing/fuzzer_corpus/96a504c8350c3d69aef1eb3c63f43f73acc6a899 delete mode 100644 explorer/fuzzing/fuzzer_corpus/96f494f4264c4c5ff5f351423d60ab98f6a6b12b delete mode 100644 explorer/fuzzing/fuzzer_corpus/bbabf13bb9fd0c2a5c1b23eaaf572dce295176a8 delete mode 100644 explorer/fuzzing/fuzzer_corpus/e347085328903bbd4f362337d32f45315dc3bf18 delete mode 100644 explorer/fuzzing/fuzzer_corpus/e38f21d3adb5fb5eb8138b5175401a9ccfe1163d delete mode 100644 explorer/fuzzing/fuzzer_corpus/eb9859dd8a2ab2a66b93655aeb5f01090a55978d delete mode 100644 explorer/interpreter/stack_fragment.cpp delete mode 100644 explorer/interpreter/stack_fragment.h delete mode 100644 explorer/testdata/experimental_continuation/await_maintains_scope.carbon delete mode 100644 explorer/testdata/experimental_continuation/convert_run.carbon delete mode 100644 explorer/testdata/experimental_continuation/creation_is_noop.carbon delete mode 100644 explorer/testdata/experimental_continuation/fail_auto_return_await.carbon delete mode 100644 explorer/testdata/experimental_continuation/fail_continuation_syntax.carbon delete mode 100644 explorer/testdata/experimental_continuation/fail_lifetime.carbon delete mode 100644 explorer/testdata/experimental_continuation/fail_recursive_continuation.carbon delete mode 100644 explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon delete mode 100644 explorer/testdata/experimental_continuation/recursive.carbon delete mode 100644 explorer/testdata/experimental_continuation/run.carbon delete mode 100644 explorer/testdata/experimental_continuation/run_with_await.carbon delete mode 100644 explorer/testdata/experimental_continuation/shallow_copy.carbon diff --git a/common/fuzzing/carbon.proto b/common/fuzzing/carbon.proto index 49c903a6a192..45a398a538b8 100644 --- a/common/fuzzing/carbon.proto +++ b/common/fuzzing/carbon.proto @@ -114,7 +114,6 @@ message BoolLiteral { } message IntTypeLiteral {} -message ContinuationTypeLiteral {} message IntLiteral { optional int64 value = 1; @@ -177,16 +176,15 @@ message Expression { BoolTypeLiteral bool_type_literal = 12; BoolLiteral bool_literal = 13; IntTypeLiteral int_type_literal = 14; - ContinuationTypeLiteral continuation_type_literal = 15; - IntLiteral int_literal = 16; - StringLiteral string_literal = 17; - StringTypeLiteral string_type_literal = 18; - TypeTypeLiteral type_type_literal = 19; - UnimplementedExpression unimplemented_expression = 20; - ArrayTypeLiteral array_type_literal = 21; - CompoundMemberAccessExpression compound_member_access = 22; - WhereExpression where = 23; - DesignatorExpression designator = 24; + IntLiteral int_literal = 15; + StringLiteral string_literal = 16; + StringTypeLiteral string_type_literal = 17; + TypeTypeLiteral type_type_literal = 18; + UnimplementedExpression unimplemented_expression = 19; + ArrayTypeLiteral array_type_literal = 20; + CompoundMemberAccessExpression compound_member_access = 21; + WhereExpression where = 22; + DesignatorExpression designator = 23; } } @@ -319,17 +317,6 @@ message MatchStatement { repeated MatchClause clauses = 2; } -message ContinuationStatement { - optional string name = 1; - optional BlockStatement body = 2; -} - -message RunStatement { - optional Expression argument = 1; -} - -message AwaitStatement {} - message BreakStatement {} message ContinueStatement {} @@ -344,13 +331,10 @@ message Statement { BlockStatement block = 7; WhileStatement while_statement = 8; MatchStatement match = 9; - ContinuationStatement continuation = 10; - RunStatement run = 11; - AwaitStatement await_statement = 12; - BreakStatement break_statement = 13; - ContinueStatement continue_statement = 14; - ForStatement for_statement = 15; - IncrementDecrementStatement inc_dec = 16; + BreakStatement break_statement = 10; + ContinueStatement continue_statement = 11; + ForStatement for_statement = 12; + IncrementDecrementStatement inc_dec = 13; } } diff --git a/common/fuzzing/proto_to_carbon.cpp b/common/fuzzing/proto_to_carbon.cpp index 1a8297445b22..72b7e9aac14b 100644 --- a/common/fuzzing/proto_to_carbon.cpp +++ b/common/fuzzing/proto_to_carbon.cpp @@ -366,10 +366,6 @@ static auto ExpressionToCarbon(const Fuzzing::Expression& expression, out << "String"; break; - case Fuzzing::Expression::kContinuationTypeLiteral: - out << "__Continuation"; - break; - case Fuzzing::Expression::kTypeTypeLiteral: out << "type"; break; @@ -676,26 +672,6 @@ static auto StatementToCarbon(const Fuzzing::Statement& statement, break; } - case Fuzzing::Statement::kContinuation: { - const auto& continuation = statement.continuation(); - out << "__continuation "; - IdentifierToCarbon(continuation.name(), out); - BlockStatementToCarbon(continuation.body(), out); - break; - } - - case Fuzzing::Statement::kRun: { - const auto& run = statement.run(); - out << "__run "; - ExpressionToCarbon(run.argument(), out); - out << ";"; - break; - } - - case Fuzzing::Statement::kAwaitStatement: - out << "__await;"; - break; - case Fuzzing::Statement::kBreakStatement: out << "break;"; break; diff --git a/explorer/README.md b/explorer/README.md index 9340759edafc..3930e6fa4aee 100644 --- a/explorer/README.md +++ b/explorer/README.md @@ -191,85 +191,3 @@ Each step of execution is printed in the following format: Each step of execution can push new actions on the stack, pop actions, increment the position number of an action, and add result values to an action. - -## Experimental feature: Delimited Continuations - -Delimited continuations provide a kind of resumable exception with first-class -continuations. The point of experimenting with 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. - -So what are delimited continuations? Recall that a continuation is a -representation of what happens next in a computation. In the abstract machine, -the procedure call stack represents the current continuation. A delimited -continuation is also about what happens next, but it doesn't go all the way to -the end of the execution. Instead it represents what happens up until control -reaches the nearest enclosing `__continuation` statement. - -The statement - - __continuation - -creates a continuation object from the given statement and binds the -continuation object to the given identifier. The given statement is not yet -executed. - -The statement - - __run ; - -starts or resumes execution of the continuation object that results from the -given expression. - -The statement - - __await; - -pauses the current continuation, saving the control state in the continuation -object. Control is then returned to the statement after the `__run` that -initiated the current continuation. - -These three language features are demonstrated in the following example, where -we create a continuation and bind it to `k`. We then run the continuation twice. -The first time increments `x` to `1` and the second time increments `x` to `2`, -so the expected result of this program is `2`. - -```carbon -fn Main() -> i32 { - var x: i32 = 0; - __continuation k { - x = x + 1; - __await; - x = x + 1; - } - __run k; - __run k; - return x; -} -``` - -Note that the control state of the continuation object bound to `k` mutates as -the program executes. Upon creation, the control state is at the beginning of -the continuation. After the first `__run`, the control state is just after the -`__await`. After the second `__run`, the control state is at the end of the -continuation. - -Continuation variables are currently copyable, but that operation is "shallow": -the two values are aliases for the same underlying continuation object. - -The delimited continuation feature described here is based on the -`shift`/`reset` style of delimited continuations created by Danvy and Filinsky -(Abstracting control, ACM Conference on Lisp and Functional Programming, 1990). -We adapted the feature to operate in a more imperative manner. The -`__continuation` feature is equivalent to a `reset` followed immediately by a -`shift` to pause and capture the continuation object. The `__run` feature is -equivalent to calling the continuation. The `__await` feature is equivalent to a -`shift` except that it updates the continuation in place. diff --git a/explorer/ast/ast_kinds.h b/explorer/ast/ast_kinds.h index 16180e231c9c..8d59438b2a89 100644 --- a/explorer/ast/ast_kinds.h +++ b/explorer/ast/ast_kinds.h @@ -105,9 +105,6 @@ FINAL(Break) \ FINAL(Continue) \ FINAL(Match) \ - FINAL(Continuation) \ - FINAL(Run) \ - FINAL(Await) \ FINAL(For) #define CARBON_Return_KINDS(ABSTRACT, FINAL) \ @@ -124,7 +121,6 @@ ABSTRACT(MemberAccessExpression) \ FINAL(IndexExpression) \ FINAL(IntTypeLiteral) \ - FINAL(ContinuationTypeLiteral) \ FINAL(IntLiteral) \ FINAL(OperatorExpression) \ FINAL(StringLiteral) \ diff --git a/explorer/ast/expression.cpp b/explorer/ast/expression.cpp index 730102d4ad10..61a44b599a7e 100644 --- a/explorer/ast/expression.cpp +++ b/explorer/ast/expression.cpp @@ -300,7 +300,6 @@ void Expression::Print(llvm::raw_ostream& out) const { case ExpressionKind::StringLiteral: case ExpressionKind::StringTypeLiteral: case ExpressionKind::TypeTypeLiteral: - case ExpressionKind::ContinuationTypeLiteral: case ExpressionKind::ValueLiteral: PrintID(out); break; @@ -338,9 +337,6 @@ void Expression::PrintID(llvm::raw_ostream& out) const { case ExpressionKind::TypeTypeLiteral: out << "type"; break; - case ExpressionKind::ContinuationTypeLiteral: - out << "Continuation"; - break; case ExpressionKind::FunctionTypeLiteral: case ExpressionKind::StructLiteral: case ExpressionKind::ArrayTypeLiteral: diff --git a/explorer/ast/expression.h b/explorer/ast/expression.h index 32016b5402dd..cac6ab2588db 100644 --- a/explorer/ast/expression.h +++ b/explorer/ast/expression.h @@ -817,20 +817,6 @@ class IntTypeLiteral : public Expression { } }; -class ContinuationTypeLiteral : public Expression { - public: - explicit ContinuationTypeLiteral(SourceLocation source_loc) - : Expression(AstNodeKind::ContinuationTypeLiteral, source_loc) {} - - explicit ContinuationTypeLiteral(CloneContext& context, - const ContinuationTypeLiteral& other) - : Expression(context, other) {} - - static auto classof(const AstNode* node) -> bool { - return InheritsFromContinuationTypeLiteral(node->kind()); - } -}; - class TypeTypeLiteral : public Expression { public: explicit TypeTypeLiteral(SourceLocation source_loc) diff --git a/explorer/ast/statement.cpp b/explorer/ast/statement.cpp index c9d195f63d62..cedb508cc5ac 100644 --- a/explorer/ast/statement.cpp +++ b/explorer/ast/statement.cpp @@ -123,24 +123,6 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const { } break; } - case StatementKind::Continuation: { - const auto& cont = cast(*this); - out << "continuation " << cont.name() << " "; - if (depth < 0 || depth > 1) { - out << "\n"; - } - cont.body().PrintDepth(depth - 1, out); - if (depth < 0 || depth > 1) { - out << "\n"; - } - break; - } - case StatementKind::Run: - out << "run " << cast(*this).argument() << ";"; - break; - case StatementKind::Await: - out << "await;"; - break; } } diff --git a/explorer/ast/statement.h b/explorer/ast/statement.h index 8ba8dd5f1c16..716afdd8ccb4 100644 --- a/explorer/ast/statement.h +++ b/explorer/ast/statement.h @@ -581,105 +581,6 @@ class Match : public Statement { std::vector clauses_; }; -// A continuation statement. -// -// __continuation { -// -// } -class Continuation : public Statement { - public: - using ImplementsCarbonValueNode = void; - - Continuation(SourceLocation source_loc, std::string name, - Nonnull body) - : Statement(AstNodeKind::Continuation, source_loc), - name_(std::move(name)), - body_(body) {} - - explicit Continuation(CloneContext& context, const Continuation& other) - : Statement(context, other), - name_(other.name_), - body_(context.Clone(other.body_)), - static_type_(context.Clone(other.static_type_)) {} - - static auto classof(const AstNode* node) -> bool { - return InheritsFromContinuation(node->kind()); - } - - auto name() const -> const std::string& { return name_; } - auto body() const -> const Block& { return *body_; } - auto body() -> Block& { return *body_; } - - // The static type of the continuation. Cannot be called before typechecking. - // - // This will always be ContinuationType, but we must set it dynamically in - // the typechecker because this code can't depend on ContinuationType. - auto static_type() const -> const Value& { return **static_type_; } - - // Sets the static type of the continuation. Can only be called once, - // during typechecking. - void set_static_type(Nonnull type) { - CARBON_CHECK(!static_type_.has_value()); - static_type_ = type; - } - - auto expression_category() const -> ExpressionCategory { - return ExpressionCategory::Reference; - } - auto constant_value() const -> std::optional> { - return std::nullopt; - } - auto symbolic_identity() const -> std::optional> { - return std::nullopt; - } - - private: - std::string name_; - Nonnull body_; - std::optional> static_type_; -}; - -// A run statement. -// -// __run ; -class Run : public Statement { - public: - Run(SourceLocation source_loc, Nonnull argument) - : Statement(AstNodeKind::Run, source_loc), argument_(argument) {} - - explicit Run(CloneContext& context, const Run& other) - : Statement(context, other), argument_(context.Clone(other.argument_)) {} - - static auto classof(const AstNode* node) -> bool { - return InheritsFromRun(node->kind()); - } - - auto argument() const -> const Expression& { return *argument_; } - auto argument() -> Expression& { return *argument_; } - - // Can only be called by type-checking, if a conversion was required. - void set_argument(Nonnull argument) { argument_ = argument; } - - private: - Nonnull argument_; -}; - -// An await statement. -// -// __await; -class Await : public Statement { - public: - explicit Await(SourceLocation source_loc) - : Statement(AstNodeKind::Await, source_loc) {} - - explicit Await(CloneContext& context, const Await& other) - : Statement(context, other) {} - - static auto classof(const AstNode* node) -> bool { - return InheritsFromAwait(node->kind()); - } -}; - } // namespace Carbon #endif // CARBON_EXPLORER_AST_STATEMENT_H_ diff --git a/explorer/ast/value.cpp b/explorer/ast/value.cpp index f3305c9eb7b3..8a46b811cae8 100644 --- a/explorer/ast/value.cpp +++ b/explorer/ast/value.cpp @@ -494,9 +494,6 @@ void Value::Print(llvm::raw_ostream& out) const { case Value::Kind::AutoType: out << "auto"; break; - case Value::Kind::ContinuationType: - out << "Continuation"; - break; case Value::Kind::PointerType: out << cast(*this).pointee_type() << "*"; break; @@ -672,10 +669,6 @@ void Value::Print(llvm::raw_ostream& out) const { out << "." << *GetName(assoc.constant()) << ")"; break; } - case Value::Kind::ContinuationValue: { - out << cast(*this).representation(); - break; - } case Value::Kind::StringType: out << "String"; break; @@ -870,7 +863,6 @@ auto TypeEqual(Nonnull t1, Nonnull t2, } case Value::Kind::IntType: case Value::Kind::BoolType: - case Value::Kind::ContinuationType: case Value::Kind::TypeType: case Value::Kind::StringType: return true; @@ -898,7 +890,6 @@ auto TypeEqual(Nonnull t1, Nonnull t2, case Value::Kind::LocationValue: case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: - case Value::Kind::ContinuationValue: case Value::Kind::UninitializedValue: case Value::Kind::ParameterizedEntityName: case Value::Kind::MemberName: @@ -1034,7 +1025,6 @@ auto ValueStructurallyEqual( case Value::Kind::ConstraintWitness: case Value::Kind::ConstraintImplWitness: case Value::Kind::ChoiceType: - case Value::Kind::ContinuationType: case Value::Kind::VariableType: case Value::Kind::StringType: case Value::Kind::TypeOfMixinPseudoType: @@ -1047,7 +1037,6 @@ auto ValueStructurallyEqual( case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::PointerValue: case Value::Kind::LocationValue: case Value::Kind::UninitializedValue: diff --git a/explorer/ast/value.h b/explorer/ast/value.h index bb9b05c4d271..ae22aaf7f442 100644 --- a/explorer/ast/value.h +++ b/explorer/ast/value.h @@ -1290,21 +1290,6 @@ class ChoiceType : public Value { Nonnull bindings_; }; -// A continuation type. -class ContinuationType : public Value { - public: - ContinuationType() : Value(Kind::ContinuationType) {} - - static auto classof(const Value* value) -> bool { - return value->kind() == Kind::ContinuationType; - } - - template - auto Decompose(F f) const { - return f(); - } -}; - // A variable type. class VariableType : public Value { public: @@ -1449,48 +1434,6 @@ class AssociatedConstant : public Value { Nonnull witness_; }; -// A first-class continuation representation of a fragment of the stack. -// The representation of a continuation is opaque and determined by the -// interpreter. -class ContinuationValue : public Value { - public: - // Base class for the representation of a continuation, which is not defined - // here for layering reasons. The interpreter provides the derived class - // `StackFragment` that defines the concrete representation, which is - // expected to be the only derived class outside of tests. - class Representation { - public: - virtual ~Representation() {} - - Representation(Representation&&) = delete; - auto operator=(Representation&&) -> Representation& = delete; - - virtual void Print(llvm::raw_ostream& out) const = 0; - LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); } - - protected: - Representation() = default; - }; - - explicit ContinuationValue(Nonnull representation) - : Value(Kind::ContinuationValue), representation_(representation) {} - - static auto classof(const Value* value) -> bool { - return value->kind() == Kind::ContinuationValue; - } - - template - auto Decompose(F f) const { - return f(representation_); - } - - // The representation of the continuation. - auto representation() const -> Representation& { return *representation_; } - - private: - Nonnull representation_; -}; - // The String type. class StringType : public Value { public: diff --git a/explorer/ast/value_kinds.def b/explorer/ast/value_kinds.def index 4ae49a92e92d..11ca5c5aba5d 100644 --- a/explorer/ast/value_kinds.def +++ b/explorer/ast/value_kinds.def @@ -40,7 +40,6 @@ CARBON_VALUE_KIND(InterfaceType) CARBON_VALUE_KIND(NamedConstraintType) CARBON_VALUE_KIND(ConstraintType) CARBON_VALUE_KIND(ChoiceType) -CARBON_VALUE_KIND(ContinuationType) CARBON_VALUE_KIND(VariableType) CARBON_VALUE_KIND(AssociatedConstant) CARBON_VALUE_KIND(ParameterizedEntityName) @@ -48,7 +47,6 @@ CARBON_VALUE_KIND(MemberName) CARBON_VALUE_KIND(BindingPlaceholderValue) CARBON_VALUE_KIND(AddrValue) CARBON_VALUE_KIND(AlternativeConstructorValue) -CARBON_VALUE_KIND(ContinuationValue) CARBON_VALUE_KIND(StringType) CARBON_VALUE_KIND(StringValue) CARBON_VALUE_KIND(TypeOfMixinPseudoType) diff --git a/explorer/ast/value_transform.h b/explorer/ast/value_transform.h index f73d5bc31303..4e49f296562d 100644 --- a/explorer/ast/value_transform.h +++ b/explorer/ast/value_transform.h @@ -236,11 +236,6 @@ class ValueTransform : public TransformBase { return node; } - auto operator()(Nonnull continuation) - -> Nonnull { - return continuation; - } - auto operator()(Address addr) -> Address { return addr; } auto operator()(ValueNodeView value_node) -> ValueNodeView { diff --git a/explorer/fuzzing/ast_to_proto.cpp b/explorer/fuzzing/ast_to_proto.cpp index 9c6b2c2a4a45..d3b864ed86cb 100644 --- a/explorer/fuzzing/ast_to_proto.cpp +++ b/explorer/fuzzing/ast_to_proto.cpp @@ -340,10 +340,6 @@ static auto ExpressionToProto(const Expression& expression) expression_proto.mutable_string_type_literal(); break; - case ExpressionKind::ContinuationTypeLiteral: - expression_proto.mutable_continuation_type_literal(); - break; - case ExpressionKind::TypeTypeLiteral: expression_proto.mutable_type_type_literal(); break; @@ -565,25 +561,6 @@ static auto StatementToProto(const Statement& statement) -> Fuzzing::Statement { break; } - case StatementKind::Continuation: { - const auto& continuation = cast(statement); - auto* continuation_proto = statement_proto.mutable_continuation(); - continuation_proto->set_name(continuation.name()); - *continuation_proto->mutable_body() = - BlockStatementToProto(continuation.body()); - break; - } - - case StatementKind::Run: - *statement_proto.mutable_run()->mutable_argument() = - ExpressionToProto(cast(statement).argument()); - break; - - case StatementKind::Await: - // Initializes with the default value; there's nothing to set. - statement_proto.mutable_await_statement(); - break; - case StatementKind::Break: // Initializes with the default value; there's nothing to set. statement_proto.mutable_break_statement(); diff --git a/explorer/fuzzing/fuzzer_corpus/37fcecce96eb5c913f090b2f1f588e3b82c9d1be b/explorer/fuzzing/fuzzer_corpus/37fcecce96eb5c913f090b2f1f588e3b82c9d1be deleted file mode 100644 index f26d18043794..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/37fcecce96eb5c913f090b2f1f588e3b82c9d1be +++ /dev/null @@ -1,351 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - variable { - binding { - name: "current" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - initializer { - int_literal { - value: 0 - } - } - } - } - declarations { - function { - name { - name: "CountUpTo" - } - param_pattern { - fields { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - if_statement { - condition { - operator { - op: Eq - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 0 - } - } - } - } - then_block { - statements { - assign { - lhs { - identifier { - name: "current" - } - } - rhs { - int_literal { - value: 0 - } - } - op: Plain - } - } - statements { - await_statement { - } - } - statements { - return_expression_statement { - expression { - int_literal { - value: 0 - } - } - } - } - } - else_block { - statements { - assign { - lhs { - identifier { - name: "current" - } - } - rhs { - operator { - op: Add - arguments { - int_literal { - value: 1 - } - } - arguments { - call { - function { - identifier { - name: "CountUpTo" - } - } - argument { - tuple_literal { - fields { - operator { - op: Sub - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - } - } - } - } - } - } - op: Plain - } - } - statements { - await_statement { - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "current" - } - } - } - } - } - } - } - } - } - } - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - continuation { - name: "k" - body { - statements { - expression_statement { - expression { - call { - function { - identifier { - name: "CountUpTo" - } - } - argument { - tuple_literal { - fields { - int_literal { - value: 5 - } - } - } - } - } - } - } - } - } - } - } - statements { - variable_definition { - pattern { - binding_pattern { - name: "sum" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - variable_definition { - pattern { - binding_pattern { - name: "count" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 5 - } - } - is_returned: false - } - } - statements { - while_statement { - condition { - operator { - op: NotEq - arguments { - identifier { - name: "count" - } - } - arguments { - int_literal { - value: 0 - } - } - } - } - body { - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - assign { - lhs { - identifier { - name: "sum" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "sum" - } - } - arguments { - identifier { - name: "current" - } - } - } - } - op: Plain - } - } - statements { - assign { - lhs { - identifier { - name: "count" - } - } - rhs { - operator { - op: Sub - arguments { - identifier { - name: "count" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "sum" - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/5947862acd3e020041dcd43ca86f05438a6ab930 b/explorer/fuzzing/fuzzer_corpus/5947862acd3e020041dcd43ca86f05438a6ab930 deleted file mode 100644 index 22f34026dbab..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/5947862acd3e020041dcd43ca86f05438a6ab930 +++ /dev/null @@ -1,88 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "x" - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/63378befc2730b6eeca04e21fc914fce5442844b b/explorer/fuzzing/fuzzer_corpus/63378befc2730b6eeca04e21fc914fce5442844b deleted file mode 100644 index e1929b57986a..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/63378befc2730b6eeca04e21fc914fce5442844b +++ /dev/null @@ -1,51 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "f" - } - param_pattern { - } - return_term { - kind: Auto - } - body { - statements { - await_statement { - } - } - } - } - } - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - return_expression_statement { - expression { - int_literal { - value: 0 - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/879519ec3f915d5bec166b7c1adbea9be016060b b/explorer/fuzzing/fuzzer_corpus/879519ec3f915d5bec166b7c1adbea9be016060b deleted file mode 100644 index 1268d0c745c8..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/879519ec3f915d5bec166b7c1adbea9be016060b +++ /dev/null @@ -1,135 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - statements { - await_statement { - } - } - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 2 - } - } - } - } - op: Plain - } - } - } - } - } - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "x" - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/91362973dc5b0ed1e93d5f4e8e1e0b21ed98c3e9 b/explorer/fuzzing/fuzzer_corpus/91362973dc5b0ed1e93d5f4e8e1e0b21ed98c3e9 deleted file mode 100644 index 6c88e89dee6f..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/91362973dc5b0ed1e93d5f4e8e1e0b21ed98c3e9 +++ /dev/null @@ -1,97 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - } - } - } - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "x" - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/96a504c8350c3d69aef1eb3c63f43f73acc6a899 b/explorer/fuzzing/fuzzer_corpus/96a504c8350c3d69aef1eb3c63f43f73acc6a899 deleted file mode 100644 index 74fbdd0d76f2..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/96a504c8350c3d69aef1eb3c63f43f73acc6a899 +++ /dev/null @@ -1,153 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "capture" - } - param_pattern { - } - return_term { - kind: Expression - type { - continuation_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 1 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "y" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - identifier { - name: "x" - } - } - is_returned: false - } - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "k" - } - } - } - } - } - } - } - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "k" - type { - expression_pattern { - expression { - continuation_type_literal { - } - } - } - } - } - } - init { - call { - function { - identifier { - name: "capture" - } - } - argument { - tuple_literal { - } - } - } - } - is_returned: false - } - } - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - return_expression_statement { - expression { - int_literal { - value: 0 - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/96f494f4264c4c5ff5f351423d60ab98f6a6b12b b/explorer/fuzzing/fuzzer_corpus/96f494f4264c4c5ff5f351423d60ab98f6a6b12b deleted file mode 100644 index 3d565968bc52..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/96f494f4264c4c5ff5f351423d60ab98f6a6b12b +++ /dev/null @@ -1,63 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "f" - } - param_pattern { - } - return_term { - kind: Omitted - } - body { - statements { - continuation { - name: "k" - body { - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - } - } - } - } - } - } - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - return_expression_statement { - expression { - int_literal { - value: 0 - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/bbabf13bb9fd0c2a5c1b23eaaf572dce295176a8 b/explorer/fuzzing/fuzzer_corpus/bbabf13bb9fd0c2a5c1b23eaaf572dce295176a8 deleted file mode 100644 index 5dc0bcb449d9..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/bbabf13bb9fd0c2a5c1b23eaaf572dce295176a8 +++ /dev/null @@ -1,173 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "y" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - statements { - await_statement { - } - } - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 2 - } - } - } - } - op: Plain - } - } - statements { - assign { - lhs { - identifier { - name: "y" - } - } - rhs { - identifier { - name: "x" - } - } - op: Plain - } - } - } - } - } - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - run { - argument { - identifier { - name: "k" - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "y" - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/e347085328903bbd4f362337d32f45315dc3bf18 b/explorer/fuzzing/fuzzer_corpus/e347085328903bbd4f362337d32f45315dc3bf18 deleted file mode 100644 index e0928f965203..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/e347085328903bbd4f362337d32f45315dc3bf18 +++ /dev/null @@ -1,316 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - class_declaration { - name { - name: "Wrap" - } - members { - variable { - binding { - name: "v" - type { - expression_pattern { - expression { - identifier { - name: "T" - } - } - } - } - } - } - } - type_params { - fields { - generic_binding { - name: "T" - type { - type_type_literal { - } - } - } - } - } - } - } - declarations { - function { - name { - name: "MakeWrap" - } - deduced_parameters { - name: "T" - type { - type_type_literal { - } - } - } - param_pattern { - fields { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - identifier { - name: "T" - } - } - } - } - } - } - } - return_term { - kind: Expression - type { - call { - function { - identifier { - name: "Wrap" - } - } - argument { - tuple_literal { - fields { - identifier { - name: "T" - } - } - } - } - } - } - } - body { - statements { - return_expression_statement { - expression { - struct_literal { - fields { - name: "v" - expression { - identifier { - name: "x" - } - } - } - } - } - } - } - } - } - } - declarations { - impl { - kind: InternalImpl - impl_type { - call { - function { - identifier { - name: "Wrap" - } - } - argument { - tuple_literal { - fields { - identifier { - name: "T" - } - } - } - } - } - } - interface { - call { - function { - identifier { - name: "ImplicitAs" - } - } - argument { - tuple_literal { - fields { - identifier { - name: "T" - } - } - } - } - } - } - members { - function { - name { - name: "Convert" - } - self_pattern { - binding_pattern { - name: "self" - type { - expression_pattern { - expression { - identifier { - name: "Self" - } - } - } - } - } - } - param_pattern { - } - return_term { - kind: Expression - type { - identifier { - name: "T" - } - } - } - body { - statements { - return_expression_statement { - expression { - simple_member_access { - field: "v" - object { - identifier { - name: "self" - } - } - } - } - } - } - } - } - } - } - } - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "n" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 1 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - assign { - lhs { - identifier { - name: "n" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "n" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - } - } - } - statements { - assign { - lhs { - identifier { - name: "n" - } - } - rhs { - int_literal { - value: 2 - } - } - op: Plain - } - } - statements { - run { - argument { - call { - function { - identifier { - name: "MakeWrap" - } - } - argument { - tuple_literal { - fields { - identifier { - name: "k" - } - } - } - } - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "n" - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/e38f21d3adb5fb5eb8138b5175401a9ccfe1163d b/explorer/fuzzing/fuzzer_corpus/e38f21d3adb5fb5eb8138b5175401a9ccfe1163d deleted file mode 100644 index c555a187c923..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/e38f21d3adb5fb5eb8138b5175401a9ccfe1163d +++ /dev/null @@ -1,88 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - variable_definition { - pattern { - binding_pattern { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - } - init { - int_literal { - value: 0 - } - } - is_returned: false - } - } - statements { - continuation { - name: "k" - body { - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "x" - } - } - } - } - } - } - } - } - } - } -} diff --git a/explorer/fuzzing/fuzzer_corpus/eb9859dd8a2ab2a66b93655aeb5f01090a55978d b/explorer/fuzzing/fuzzer_corpus/eb9859dd8a2ab2a66b93655aeb5f01090a55978d deleted file mode 100644 index c84f0d508f31..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/eb9859dd8a2ab2a66b93655aeb5f01090a55978d +++ /dev/null @@ -1,186 +0,0 @@ -compilation_unit { - package_statement { - package_name: "ExplorerTest" - } - is_api: true - declarations { - variable { - binding { - name: "x" - type { - expression_pattern { - expression { - int_type_literal { - } - } - } - } - } - initializer { - int_literal { - value: 0 - } - } - } - } - declarations { - function { - name { - name: "Foo" - } - param_pattern { - } - return_term { - kind: Omitted - } - body { - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 1 - } - } - } - } - op: Plain - } - } - statements { - await_statement { - } - } - statements { - assign { - lhs { - identifier { - name: "x" - } - } - rhs { - operator { - op: Add - arguments { - identifier { - name: "x" - } - } - arguments { - int_literal { - value: 2 - } - } - } - } - op: Plain - } - } - } - } - } - declarations { - function { - name { - name: "Main" - } - param_pattern { - } - return_term { - kind: Expression - type { - int_type_literal { - } - } - } - body { - statements { - continuation { - name: "k1" - body { - statements { - expression_statement { - expression { - call { - function { - identifier { - name: "Foo" - } - } - argument { - tuple_literal { - } - } - } - } - } - } - } - } - } - statements { - variable_definition { - pattern { - binding_pattern { - name: "k2" - type { - expression_pattern { - expression { - continuation_type_literal { - } - } - } - } - } - } - init { - identifier { - name: "k1" - } - } - is_returned: false - } - } - statements { - run { - argument { - identifier { - name: "k1" - } - } - } - } - statements { - run { - argument { - identifier { - name: "k2" - } - } - } - } - statements { - return_expression_statement { - expression { - identifier { - name: "x" - } - } - } - } - } - } - } -} diff --git a/explorer/interpreter/BUILD b/explorer/interpreter/BUILD index 9fedc08bff92..ffd12c3f5639 100644 --- a/explorer/interpreter/BUILD +++ b/explorer/interpreter/BUILD @@ -31,11 +31,9 @@ cc_library( name = "action_stack", srcs = [ "action_stack.cpp", - "stack_fragment.cpp", ], hdrs = [ "action_stack.h", - "stack_fragment.h", ], deps = [ ":action", diff --git a/explorer/interpreter/action_stack.cpp b/explorer/interpreter/action_stack.cpp index 64b66cdd5ec0..298f6dc91150 100644 --- a/explorer/interpreter/action_stack.cpp +++ b/explorer/interpreter/action_stack.cpp @@ -95,23 +95,6 @@ void ActionStack::MergeScope(RuntimeScope scope) { CARBON_FATAL() << "No current scope"; } -void ActionStack::InitializeFragment(StackFragment& fragment, - Nonnull body) { - std::vector> scopes; - for (const std::unique_ptr& action : todo_) { - if (action->scope().has_value()) { - scopes.push_back(&*action->scope()); - } - } - // We don't capture globals_ or constants_ because they're global. - - std::vector> reversed_todo; - reversed_todo.push_back(std::make_unique(body)); - reversed_todo.push_back( - std::make_unique(RuntimeScope::Capture(scopes))); - fragment.StoreReversed(std::move(reversed_todo)); -} - namespace { // The way in which FinishAction should be called for a particular kind of // action. @@ -268,34 +251,6 @@ auto ActionStack::UnwindPast(Nonnull ast_node, return Success(); } -auto ActionStack::Resume(Nonnull continuation) - -> ErrorOr { - Action& action = *todo_.Top(); - action.set_pos(action.pos() + 1); - static_cast(continuation->representation()).RestoreTo(todo_); - return Success(); -} - -static auto IsRunAction(const Action& action) -> bool { - const auto* statement = llvm::dyn_cast(&action); - return statement != nullptr && llvm::isa(statement->statement()); -} - -auto ActionStack::Suspend() -> ErrorOr { - // Pause the current continuation - todo_.Pop(); - std::vector> paused; - while (!IsRunAction(*todo_.Top())) { - paused.push_back(todo_.Pop()); - } - const auto& continuation = - llvm::cast(*todo_.Top()->results()[0]); - // Update the continuation with the paused stack. - static_cast(continuation.representation()) - .StoreReversed(std::move(paused)); - return Success(); -} - void ActionStack::PopScopes( std::stack>& cleanup_stack) { while (!todo_.IsEmpty() && llvm::isa(*todo_.Top())) { diff --git a/explorer/interpreter/action_stack.h b/explorer/interpreter/action_stack.h index 4f4b686f9e44..d2ad95d2c0bd 100644 --- a/explorer/interpreter/action_stack.h +++ b/explorer/interpreter/action_stack.h @@ -13,7 +13,6 @@ #include "explorer/ast/statement.h" #include "explorer/ast/value.h" #include "explorer/interpreter/action.h" -#include "explorer/interpreter/stack_fragment.h" namespace Carbon { @@ -56,11 +55,6 @@ class ActionStack { // Merges `scope` into the innermost scope currently on the stack. void MergeScope(RuntimeScope scope); - // Initializes `fragment` so that, when resumed, it begins execution of - // `body`. - void InitializeFragment(StackFragment& fragment, - Nonnull body); - // The result produced by the `action` argument of the most recent // Start call. Cannot be called if IsEmpty() is false, or if `action` // was an action that doesn't produce results. @@ -110,13 +104,6 @@ class ActionStack { auto UnwindPast(Nonnull ast_node, Nonnull result) -> ErrorOr; - // Resumes execution of a suspended continuation. - auto Resume(Nonnull continuation) - -> ErrorOr; - - // Suspends execution of the currently-executing continuation. - auto Suspend() -> ErrorOr; - void Pop() { todo_.Pop(); } auto Count() const -> int { return todo_.Count(); } diff --git a/explorer/interpreter/interpreter.cpp b/explorer/interpreter/interpreter.cpp index 70f8099a0449..3e15d429dc9e 100644 --- a/explorer/interpreter/interpreter.cpp +++ b/explorer/interpreter/interpreter.cpp @@ -28,7 +28,6 @@ #include "explorer/interpreter/action.h" #include "explorer/interpreter/action_stack.h" #include "explorer/interpreter/stack.h" -#include "explorer/interpreter/stack_fragment.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Casting.h" @@ -67,8 +66,6 @@ class Interpreter { trace_stream_(trace_stream), phase_(phase) {} - ~Interpreter(); - // Runs all the steps of `action`. // It's not safe to call `RunAllSteps()` or `result()` after an error. auto RunAllSteps(std::unique_ptr action) -> ErrorOr; @@ -180,22 +177,10 @@ class Interpreter { Heap heap_; ActionStack todo_; - // The underlying states of continuation values. All StackFragments created - // during execution are tracked here, in order to safely deallocate the - // contents of any non-completed continuations at the end of execution. - std::vector> stack_fragments_; - Nonnull trace_stream_; Phase phase_; }; -Interpreter::~Interpreter() { - // Clean up any remaining suspended continuations. - for (Nonnull fragment : stack_fragments_) { - fragment->Clear(); - } -} - // // State Operations // @@ -545,7 +530,6 @@ auto Interpreter::StepLocation() -> ErrorOr { case ExpressionKind::BoolTypeLiteral: case ExpressionKind::TypeTypeLiteral: case ExpressionKind::FunctionTypeLiteral: - case ExpressionKind::ContinuationTypeLiteral: case ExpressionKind::StringLiteral: case ExpressionKind::StringTypeLiteral: case ExpressionKind::ValueLiteral: @@ -771,12 +755,10 @@ auto Interpreter::Convert(Nonnull value, case Value::Kind::ConstraintImplWitness: case Value::Kind::ParameterizedEntityName: case Value::Kind::ChoiceType: - case Value::Kind::ContinuationType: case Value::Kind::VariableType: case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringType: case Value::Kind::StringValue: case Value::Kind::TypeOfMixinPseudoType: @@ -1812,10 +1794,6 @@ auto Interpreter::StepExp() -> ErrorOr { CARBON_CHECK(act.pos() == 0); return todo_.FinishAction(arena_->New()); } - case ExpressionKind::ContinuationTypeLiteral: { - CARBON_CHECK(act.pos() == 0); - return todo_.FinishAction(arena_->New()); - } case ExpressionKind::StringLiteral: CARBON_CHECK(act.pos() == 0); // { {n :: C, E, F} :: S, H} -> { {n' :: C, E, F} :: S, H} @@ -2248,34 +2226,6 @@ auto Interpreter::StepStmt() -> ErrorOr { stmt.source_loc())); return todo_.UnwindPast(*function.body(), return_value); } - case StatementKind::Continuation: { - CARBON_CHECK(act.pos() == 0); - const auto& continuation = cast(stmt); - // Create a continuation object by creating a frame similar the - // way one is created in a function call. - auto* fragment = arena_->New(); - stack_fragments_.push_back(fragment); - todo_.InitializeFragment(*fragment, &continuation.body()); - // Bind the continuation object to the continuation variable - todo_.Initialize(&cast(stmt), - arena_->New(fragment)); - return todo_.FinishAction(); - } - case StatementKind::Run: { - const auto& run = cast(stmt); - if (act.pos() == 0) { - // Evaluate the argument of the run statement. - return todo_.Spawn(std::make_unique(&run.argument())); - } else if (act.pos() == 1) { - // Push the continuation onto the current stack. - return todo_.Resume(cast(act.results()[0])); - } else { - return todo_.FinishAction(); - } - } - case StatementKind::Await: - CARBON_CHECK(act.pos() == 0); - return todo_.Suspend(); } } diff --git a/explorer/interpreter/resolve_control_flow.cpp b/explorer/interpreter/resolve_control_flow.cpp index 416b05e0320b..3c5c5b38d915 100644 --- a/explorer/interpreter/resolve_control_flow.cpp +++ b/explorer/interpreter/resolve_control_flow.cpp @@ -124,16 +124,10 @@ static auto ResolveControlFlow(Nonnull statement, } return Success(); } - case StatementKind::Continuation: - CARBON_RETURN_IF_ERROR(ResolveControlFlow( - &cast(*statement).body(), std::nullopt, std::nullopt)); - return Success(); case StatementKind::ExpressionStatement: case StatementKind::Assign: case StatementKind::IncrementDecrement: case StatementKind::VariableDefinition: - case StatementKind::Run: - case StatementKind::Await: return Success(); } } diff --git a/explorer/interpreter/resolve_names.cpp b/explorer/interpreter/resolve_names.cpp index 5dddca13fc44..383023af8f30 100644 --- a/explorer/interpreter/resolve_names.cpp +++ b/explorer/interpreter/resolve_names.cpp @@ -419,7 +419,6 @@ auto NameResolver::ResolveNames(Expression& expression, case ExpressionKind::BoolTypeLiteral: case ExpressionKind::BoolLiteral: case ExpressionKind::IntTypeLiteral: - case ExpressionKind::ContinuationTypeLiteral: case ExpressionKind::IntLiteral: case ExpressionKind::StringLiteral: case ExpressionKind::StringTypeLiteral: @@ -626,22 +625,6 @@ auto NameResolver::ResolveNames(Statement& statement, } break; } - case StatementKind::Continuation: { - auto& continuation = cast(statement); - CARBON_RETURN_IF_ERROR( - enclosing_scope.Add(continuation.name(), &continuation, - StaticScope::NameStatus::DeclaredButNotUsable)); - StaticScope continuation_scope(&enclosing_scope); - CARBON_RETURN_IF_ERROR(ResolveNames(cast(statement).body(), - continuation_scope)); - enclosing_scope.MarkUsable(continuation.name()); - break; - } - case StatementKind::Run: - CARBON_RETURN_IF_ERROR( - ResolveNames(cast(statement).argument(), enclosing_scope)); - break; - case StatementKind::Await: case StatementKind::Break: case StatementKind::Continue: break; diff --git a/explorer/interpreter/resolve_unformed.cpp b/explorer/interpreter/resolve_unformed.cpp index 7b485225f04f..0b048f10d742 100644 --- a/explorer/interpreter/resolve_unformed.cpp +++ b/explorer/interpreter/resolve_unformed.cpp @@ -134,7 +134,6 @@ static auto ResolveUnformed(Nonnull expression, case ExpressionKind::StringLiteral: case ExpressionKind::StringTypeLiteral: case ExpressionKind::TypeTypeLiteral: - case ExpressionKind::ContinuationTypeLiteral: case ExpressionKind::ValueLiteral: case ExpressionKind::IndexExpression: case ExpressionKind::CompoundMemberAccessExpression: @@ -283,9 +282,6 @@ static auto ResolveUnformed(Nonnull statement, } case StatementKind::Break: case StatementKind::Continue: - case StatementKind::Continuation: - case StatementKind::Run: - case StatementKind::Await: case StatementKind::For: // do nothing break; diff --git a/explorer/interpreter/stack_fragment.cpp b/explorer/interpreter/stack_fragment.cpp deleted file mode 100644 index bd1b614352e7..000000000000 --- a/explorer/interpreter/stack_fragment.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include "explorer/interpreter/stack_fragment.h" - -#include "common/check.h" -#include "llvm/ADT/StringExtras.h" - -namespace Carbon { - -StackFragment::~StackFragment() { - CARBON_CHECK(reversed_todo_.empty()) - << "All StackFragments must be empty before the Carbon program ends."; -} - -void StackFragment::StoreReversed( - std::vector> reversed_todo) { - CARBON_CHECK(reversed_todo_.empty()); - reversed_todo_ = std::move(reversed_todo); -} - -void StackFragment::RestoreTo(Stack>& todo) { - while (!reversed_todo_.empty()) { - todo.Push(std::move(reversed_todo_.back())); - reversed_todo_.pop_back(); - } -} - -void StackFragment::Clear() { - // We destroy the underlying Actions explicitly to ensure they're - // destroyed in the correct order. - for (auto& action : reversed_todo_) { - action.reset(); - } - reversed_todo_.clear(); -} - -void StackFragment::Print(llvm::raw_ostream& out) const { - out << "{"; - llvm::ListSeparator sep(" :: "); - for (const std::unique_ptr& action : reversed_todo_) { - out << sep << *action; - } - out << "}"; -} - -} // namespace Carbon diff --git a/explorer/interpreter/stack_fragment.h b/explorer/interpreter/stack_fragment.h deleted file mode 100644 index 8804ade8e968..000000000000 --- a/explorer/interpreter/stack_fragment.h +++ /dev/null @@ -1,51 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef CARBON_EXPLORER_INTERPRETER_STACK_FRAGMENT_H_ -#define CARBON_EXPLORER_INTERPRETER_STACK_FRAGMENT_H_ - -#include -#include - -#include "explorer/ast/value.h" -#include "explorer/interpreter/action.h" -#include "explorer/interpreter/stack.h" -#include "llvm/Support/raw_ostream.h" - -namespace Carbon { - -// A continuation value behaves like a pointer to the underlying stack -// fragment, which is exposed by `Stack()`. -class StackFragment : public ContinuationValue::Representation { - public: - // Constructs an empty StackFragment. - StackFragment() = default; - - // Requires *this to be empty, because by the time we're tearing down the - // Arena, it's no longer safe to invoke ~Action. - ~StackFragment() override; - - // Store the given partial todo stack in *this, which must currently be - // empty. The stack is represented with the top of the stack at the - // beginning of the vector, the reverse of the usual order. - void StoreReversed(std::vector> reversed_todo); - - // Restore the currently stored stack fragment to the top of `todo`, - // leaving *this empty. - void RestoreTo(Stack>& todo); - - // Destroy the currently stored stack fragment. - void Clear(); - - void Print(llvm::raw_ostream& out) const override; - - private: - // The todo stack of a suspended continuation, starting with the top - // Action. - std::vector> reversed_todo_; -}; - -} // namespace Carbon - -#endif // CARBON_EXPLORER_INTERPRETER_STACK_FRAGMENT_H_ diff --git a/explorer/interpreter/type_checker.cpp b/explorer/interpreter/type_checker.cpp index 27aad712de25..4ec35bc899c5 100644 --- a/explorer/interpreter/type_checker.cpp +++ b/explorer/interpreter/type_checker.cpp @@ -97,7 +97,6 @@ static auto IsTypeOfType(Nonnull value) -> bool { case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: case Value::Kind::ImplWitness: @@ -116,7 +115,6 @@ static auto IsTypeOfType(Nonnull value) -> bool { case Value::Kind::NominalClassType: case Value::Kind::MixinPseudoType: case Value::Kind::ChoiceType: - case Value::Kind::ContinuationType: case Value::Kind::StringType: case Value::Kind::StaticArrayType: case Value::Kind::TupleType: @@ -159,7 +157,6 @@ static auto IsType(Nonnull value) -> bool { case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: case Value::Kind::ImplWitness: @@ -181,7 +178,6 @@ static auto IsType(Nonnull value) -> bool { case Value::Kind::NamedConstraintType: case Value::Kind::ConstraintType: case Value::Kind::ChoiceType: - case Value::Kind::ContinuationType: case Value::Kind::VariableType: case Value::Kind::StringType: case Value::Kind::StaticArrayType: @@ -230,7 +226,6 @@ static auto ExpectCompleteType(SourceLocation source_loc, case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: case Value::Kind::ImplWitness: @@ -250,7 +245,6 @@ static auto ExpectCompleteType(SourceLocation source_loc, case Value::Kind::FunctionType: case Value::Kind::StructType: case Value::Kind::ConstraintType: - case Value::Kind::ContinuationType: case Value::Kind::VariableType: case Value::Kind::AssociatedConstant: case Value::Kind::TypeOfParameterizedEntityName: @@ -344,7 +338,6 @@ static auto TypeContainsAuto(Nonnull type) -> bool { case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: case Value::Kind::ImplWitness: @@ -372,7 +365,6 @@ static auto TypeContainsAuto(Nonnull type) -> bool { case Value::Kind::NamedConstraintType: case Value::Kind::ConstraintType: case Value::Kind::ChoiceType: - case Value::Kind::ContinuationType: case Value::Kind::AssociatedConstant: // These types can contain other types, but those types can't involve // `auto`. @@ -1240,7 +1232,6 @@ auto TypeChecker::ArgumentDeduction::Deduce(Nonnull param, // are not deduced as part of this deduction step. case Value::Kind::StaticArrayType: // TODO: We could deduce the array type from an array or tuple argument. - case Value::Kind::ContinuationType: case Value::Kind::ChoiceType: // TODO: Choice types should be handled like other named declarations. case Value::Kind::ConstraintType: @@ -1274,7 +1265,6 @@ auto TypeChecker::ArgumentDeduction::Deduce(Nonnull param, case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: { // Argument deduction within the parameters of a parameterized class type @@ -3810,7 +3800,6 @@ auto TypeChecker::TypeCheckExp(Nonnull e, case ExpressionKind::BoolTypeLiteral: case ExpressionKind::StringTypeLiteral: case ExpressionKind::TypeTypeLiteral: - case ExpressionKind::ContinuationTypeLiteral: e->set_expression_category(ExpressionCategory::Value); e->set_static_type(arena_->New()); return Success(); @@ -4673,26 +4662,6 @@ auto TypeChecker::TypeCheckStmt(Nonnull s, } return Success(); } - case StatementKind::Continuation: { - auto& cont = cast(*s); - CARBON_RETURN_IF_ERROR(TypeCheckStmt(&cont.body(), impl_scope)); - cont.set_static_type(arena_->New()); - return Success(); - } - case StatementKind::Run: { - auto& run = cast(*s); - CARBON_RETURN_IF_ERROR(TypeCheckExp(&run.argument(), impl_scope)); - CARBON_ASSIGN_OR_RETURN( - Nonnull converted_argument, - ImplicitlyConvert("argument of `run`", impl_scope, &run.argument(), - arena_->New())); - run.set_argument(converted_argument); - return Success(); - } - case StatementKind::Await: { - // Nothing to do here. - return Success(); - } } } @@ -4754,9 +4723,6 @@ auto TypeChecker::ExpectReturnOnAllPaths( case StatementKind::ReturnVar: case StatementKind::ReturnExpression: return Success(); - case StatementKind::Continuation: - case StatementKind::Run: - case StatementKind::Await: case StatementKind::Assign: case StatementKind::IncrementDecrement: case StatementKind::ExpressionStatement: @@ -5895,7 +5861,6 @@ static auto IsValidTypeForAliasTarget(Nonnull type) -> bool { case Value::Kind::BindingPlaceholderValue: case Value::Kind::AddrValue: case Value::Kind::AlternativeConstructorValue: - case Value::Kind::ContinuationValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: CARBON_FATAL() << "type of alias target is not a type"; @@ -5912,7 +5877,6 @@ static auto IsValidTypeForAliasTarget(Nonnull type) -> bool { case Value::Kind::TupleType: case Value::Kind::NominalClassType: case Value::Kind::ChoiceType: - case Value::Kind::ContinuationType: case Value::Kind::StringType: case Value::Kind::AssociatedConstant: return false; diff --git a/explorer/interpreter/type_structure.cpp b/explorer/interpreter/type_structure.cpp index a36ac3ef93fe..9a819c32c191 100644 --- a/explorer/interpreter/type_structure.cpp +++ b/explorer/interpreter/type_structure.cpp @@ -82,7 +82,6 @@ struct TypeStructureBuilder { void Visit(const VTable&) {} void Visit(const FunctionType::GenericParameter&) {} void Visit(const NamedElement&) {} - void Visit(Nonnull) {} // Constraint types can contain mentions of VariableTypes, but they aren't // deducible so it's not important to look for them. diff --git a/explorer/syntax/lexer.lpp b/explorer/syntax/lexer.lpp index 9847722b9e7b..41449072cfc6 100644 --- a/explorer/syntax/lexer.lpp +++ b/explorer/syntax/lexer.lpp @@ -41,7 +41,6 @@ API "api" ARROW "->" AS "as" AUTO "auto" -AWAIT "__await" BASE "base" BOOL "bool" BREAK "break" @@ -54,8 +53,6 @@ COLON ":" COLON_BANG ":!" COMMA "," CONSTRAINT "constraint" -CONTINUATION "__continuation" -CONTINUATION_TYPE "__Continuation" CONTINUE "continue" DEFAULT "default" DESTRUCTOR "destructor" @@ -114,7 +111,6 @@ RETURNED "returned" RIGHT_CURLY_BRACE "}" RIGHT_PARENTHESIS ")" RIGHT_SQUARE_BRACKET "]" -RUN "__run" SELF "Self" SEMICOLON ";" SLASH "/" @@ -164,7 +160,6 @@ operand_start [(A-Za-z0-9_\"] {ARROW} { return CARBON_SIMPLE_TOKEN(ARROW); } {AS} { return CARBON_SIMPLE_TOKEN(AS); } {AUTO} { return CARBON_SIMPLE_TOKEN(AUTO); } -{AWAIT} { return CARBON_SIMPLE_TOKEN(AWAIT); } {BASE} { return CARBON_SIMPLE_TOKEN(BASE); } {BOOL} { return CARBON_SIMPLE_TOKEN(BOOL); } {BREAK} { return CARBON_SIMPLE_TOKEN(BREAK); } @@ -177,8 +172,6 @@ operand_start [(A-Za-z0-9_\"] {COLON} { return CARBON_SIMPLE_TOKEN(COLON); } {COMMA} { return CARBON_SIMPLE_TOKEN(COMMA); } {CONSTRAINT} { return CARBON_SIMPLE_TOKEN(CONSTRAINT); } -{CONTINUATION_TYPE} { return CARBON_SIMPLE_TOKEN(CONTINUATION_TYPE); } -{CONTINUATION} { return CARBON_SIMPLE_TOKEN(CONTINUATION); } {CONTINUE} { return CARBON_SIMPLE_TOKEN(CONTINUE); } {DEFAULT} { return CARBON_SIMPLE_TOKEN(DEFAULT); } {DESTRUCTOR} { return CARBON_SIMPLE_TOKEN(DESTRUCTOR); } @@ -234,7 +227,6 @@ operand_start [(A-Za-z0-9_\"] {PLUS} { return CARBON_SIMPLE_TOKEN(PLUS); } {RETURNED} { return CARBON_SIMPLE_TOKEN(RETURNED); } {RETURN} { return CARBON_SIMPLE_TOKEN(RETURN); } -{RUN} { return CARBON_SIMPLE_TOKEN(RUN); } {SELF} { return CARBON_SIMPLE_TOKEN(SELF); } {SEMICOLON} { return CARBON_SIMPLE_TOKEN(SEMICOLON); } {SLASH_EQUAL} { return CARBON_SIMPLE_TOKEN(SLASH_EQUAL); } diff --git a/explorer/syntax/parser.ypp b/explorer/syntax/parser.ypp index f05a53093318..126dca659ee0 100644 --- a/explorer/syntax/parser.ypp +++ b/explorer/syntax/parser.ypp @@ -217,7 +217,6 @@ ARROW AS AUTO - AWAIT BASE BOOL BREAK @@ -230,8 +229,6 @@ COLON_BANG COMMA CONSTRAINT - CONTINUATION - CONTINUATION_TYPE CONTINUE DEFAULT DESTRUCTOR @@ -291,7 +288,6 @@ RIGHT_CURLY_BRACE RIGHT_PARENTHESIS RIGHT_SQUARE_BRACKET - RUN SELF SEMICOLON SLASH @@ -416,8 +412,6 @@ primary_expression: { $$ = arena->New(context.source_loc()); } | TYPE { $$ = arena->New(context.source_loc()); } -| CONTINUATION_TYPE - { $$ = arena->New(context.source_loc()); } | paren_expression { $$ = $[paren_expression]; } | struct_literal { $$ = $[struct_literal]; } | struct_type_literal { $$ = $[struct_type_literal]; } @@ -1124,15 +1118,6 @@ statement: $$ = arena->New(context.source_loc(), $[expression], $[clause_list]); } -| CONTINUATION identifier block - { - $$ = arena->New(context.source_loc(), $[identifier], - $[block]); - } -| RUN expression SEMICOLON - { $$ = arena->New(context.source_loc(), $[expression]); } -| AWAIT SEMICOLON - { $$ = arena->New(context.source_loc()); } | FOR LEFT_PARENTHESIS variable_declaration IN type_expression RIGHT_PARENTHESIS block { diff --git a/explorer/testdata/experimental_continuation/await_maintains_scope.carbon b/explorer/testdata/experimental_continuation/await_maintains_scope.carbon deleted file mode 100644 index 6e0030ed0c69..000000000000 --- a/explorer/testdata/experimental_continuation/await_maintains_scope.carbon +++ /dev/null @@ -1,26 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 3 - -package ExplorerTest api; - -// Test access to block-scoped variables upon resuming a continuation. - -fn Main() -> i32 { - var y: i32 = 0; - __continuation k { - var x: i32 = 0; - x = x + 1; - __await; - x = x + 2; - y = x; - } - __run k; - __run k; - return y; -} diff --git a/explorer/testdata/experimental_continuation/convert_run.carbon b/explorer/testdata/experimental_continuation/convert_run.carbon deleted file mode 100644 index 2f6376afef23..000000000000 --- a/explorer/testdata/experimental_continuation/convert_run.carbon +++ /dev/null @@ -1,31 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 3 - -package ExplorerTest api; - -class Wrap(T:! type) { - var v: T; -} -fn MakeWrap[T:! type](x: T) -> Wrap(T) { return {.v = x}; } - -impl forall [T:! type] Wrap(T) as ImplicitAs(T) { - fn Convert[self: Self]() -> T { - return self.v; - } -} - -fn Main() -> i32 { - var n: i32 = 1; - __continuation k { - n = n + 1; - } - n = 2; - __run MakeWrap(k); - return n; -} diff --git a/explorer/testdata/experimental_continuation/creation_is_noop.carbon b/explorer/testdata/experimental_continuation/creation_is_noop.carbon deleted file mode 100644 index a9c70f023bac..000000000000 --- a/explorer/testdata/experimental_continuation/creation_is_noop.carbon +++ /dev/null @@ -1,20 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 0 - -package ExplorerTest api; - -// Test that creating a continuation doesn't do anything. - -fn Main() -> i32 { - var x: i32 = 0; - __continuation k { - x = x + 1; - } - return x; -} diff --git a/explorer/testdata/experimental_continuation/fail_auto_return_await.carbon b/explorer/testdata/experimental_continuation/fail_auto_return_await.carbon deleted file mode 100644 index d67bebd48876..000000000000 --- a/explorer/testdata/experimental_continuation/fail_auto_return_await.carbon +++ /dev/null @@ -1,18 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{not} %{explorer-run} -// RUN: %{not} %{explorer-run-trace} - -package ExplorerTest api; - -fn f() -> auto { - // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/experimental_continuation/fail_auto_return_await.carbon:[[@LINE+1]]: control-flow reaches end of function that provides a `->` return type without reaching a return statement - __await; -} - -fn Main() -> i32 { - return 0; -} diff --git a/explorer/testdata/experimental_continuation/fail_continuation_syntax.carbon b/explorer/testdata/experimental_continuation/fail_continuation_syntax.carbon deleted file mode 100644 index 5d1202cb5535..000000000000 --- a/explorer/testdata/experimental_continuation/fail_continuation_syntax.carbon +++ /dev/null @@ -1,17 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{not} %{explorer-run} -// RUN: %{not} %{explorer-run-trace} - -package ExplorerTest api; - -fn Main() -> i32 { - var x: i32 = 0; - // CHECK:STDERR: SYNTAX ERROR: {{.*}}/explorer/testdata/experimental_continuation/fail_continuation_syntax.carbon:[[@LINE+1]]: syntax error, unexpected identifier, expecting LEFT_CURLY_BRACE - __continuation k x = 3; - __run k; - return x; -} diff --git a/explorer/testdata/experimental_continuation/fail_lifetime.carbon b/explorer/testdata/experimental_continuation/fail_lifetime.carbon deleted file mode 100644 index e289eb22e43a..000000000000 --- a/explorer/testdata/experimental_continuation/fail_lifetime.carbon +++ /dev/null @@ -1,29 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{not} %{explorer-run} -// RUN: %{not} %{explorer-run-trace} - -package ExplorerTest api; - -// Test that the read from x triggers an error because x is dead. -// This test also demonstrates how by-reference free-variable capture -// is dangerous and can happen inside continuations. - -fn capture() -> __Continuation { - var x: i32 = 1; - __continuation k { - // CHECK:STDERR: RUNTIME ERROR: {{.*}}/explorer/testdata/experimental_continuation/fail_lifetime.carbon:[[@LINE+1]]: undefined behavior: access to dead value 1 - var y: i32 = x; - } - return k; -} - -fn Main() -> i32 { - var k: __Continuation = capture(); - // error, lifetime of x is over - __run k; - return 0; -} diff --git a/explorer/testdata/experimental_continuation/fail_recursive_continuation.carbon b/explorer/testdata/experimental_continuation/fail_recursive_continuation.carbon deleted file mode 100644 index 91911ff1fedd..000000000000 --- a/explorer/testdata/experimental_continuation/fail_recursive_continuation.carbon +++ /dev/null @@ -1,20 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{not} %{explorer-run} -// RUN: %{not} %{explorer-run-trace} - -package ExplorerTest api; - -fn f() { - __continuation k { - // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/experimental_continuation/fail_recursive_continuation.carbon:[[@LINE+1]]: 'k' is not usable until after it has been completely declared - __run k; - } -} - -fn Main() -> i32 { - return 0; -} diff --git a/explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon b/explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon deleted file mode 100644 index 69b8ee36d99e..000000000000 --- a/explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon +++ /dev/null @@ -1,18 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{not} %{explorer-run} -// RUN: %{not} %{explorer-run-trace} - -package ExplorerTest api; - -fn Main() -> i32 { - var x: i32 = 0; - __continuation k { - x = x + 1; - // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/experimental_continuation/fail_return_in_continuation.carbon:[[@LINE+1]]: return is not within a function body - return x; - } -} diff --git a/explorer/testdata/experimental_continuation/recursive.carbon b/explorer/testdata/experimental_continuation/recursive.carbon deleted file mode 100644 index b5b625e0847f..000000000000 --- a/explorer/testdata/experimental_continuation/recursive.carbon +++ /dev/null @@ -1,40 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 10 - -package ExplorerTest api; - -// Test recursive functions inside continuations. - -var current: i32 = 0; - -fn CountUpTo(x: i32) -> i32 { - if (x == 0) { - current = 0; - __await; - return 0; - } else { - current = 1 + CountUpTo(x - 1); - __await; - return current; - } -} - -fn Main() -> i32 { - __continuation k { - CountUpTo(5); - } - var sum: i32 = 0; - var count: i32 = 5; - while (count != 0) { - __run k; - sum = sum + current; - count = count - 1; - } - return sum; -} diff --git a/explorer/testdata/experimental_continuation/run.carbon b/explorer/testdata/experimental_continuation/run.carbon deleted file mode 100644 index e7d12e7ff19b..000000000000 --- a/explorer/testdata/experimental_continuation/run.carbon +++ /dev/null @@ -1,21 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 1 - -package ExplorerTest api; - -// Test creating and running a continuation. - -fn Main() -> i32 { - var x: i32 = 0; - __continuation k { - x = x + 1; - } - __run k; - return x; -} diff --git a/explorer/testdata/experimental_continuation/run_with_await.carbon b/explorer/testdata/experimental_continuation/run_with_await.carbon deleted file mode 100644 index 9a9a26d0ce22..000000000000 --- a/explorer/testdata/experimental_continuation/run_with_await.carbon +++ /dev/null @@ -1,25 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 3 - -package ExplorerTest api; - -// Test pausing a continuation with `__await` and restarting it with -// `__run`. - -fn Main() -> i32 { - var x: i32 = 0; - __continuation k { - x = x + 1; - __await; - x = x + 2; - } - __run k; - __run k; - return x; -} diff --git a/explorer/testdata/experimental_continuation/shallow_copy.carbon b/explorer/testdata/experimental_continuation/shallow_copy.carbon deleted file mode 100644 index 68462e6f2eef..000000000000 --- a/explorer/testdata/experimental_continuation/shallow_copy.carbon +++ /dev/null @@ -1,31 +0,0 @@ -// Part of the Carbon Language project, under the Apache License v2.0 with LLVM -// Exceptions. See /LICENSE for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// AUTOUPDATE -// RUN: %{explorer-run} -// RUN: %{explorer-run-trace} -// CHECK:STDOUT: result: 3 - -package ExplorerTest api; - -// Assignment for continuations is shallow, so `k2` refers to the same -// continuation as `k1`. - -var x: i32 = 0; - -fn Foo() { - x = x + 1; - __await; - x = x + 2; -} - -fn Main() -> i32 { - __continuation k1 { - Foo(); - } - var k2: __Continuation = k1; - __run k1; - __run k2; - return x; -}