From 19d2407de7115759f867a302835a85cbcfe01f35 Mon Sep 17 00:00:00 2001 From: pk19604014 <95385881+pk19604014@users.noreply.github.com> Date: Tue, 24 May 2022 20:53:49 -0400 Subject: [PATCH] Similar to #1272, changed the type of alternative signature from generic Expression to TupleLiteral to match the grammar (#1291) --- common/fuzzing/carbon.proto | 2 +- common/fuzzing/proto_to_carbon.cpp | 2 +- explorer/ast/declaration.h | 8 +- explorer/fuzzing/ast_to_proto.cpp | 2 +- ...0b6edea6bcf31348f30a12a27b36d496.textproto | 482 ++++++++++++++++++ ...ccc71913bc6166593f51626e0cebb737.textproto | 299 +++++++++++ ...7db2a3b777e740964a09a379684261d8.textproto | 28 + ...81916ee306624a2ac3db2a3c7a4ea5ad.textproto | 26 - 8 files changed, 816 insertions(+), 33 deletions(-) create mode 100644 explorer/fuzzing/fuzzer_corpus/3a2e6f830b6edea6bcf31348f30a12a27b36d496.textproto create mode 100644 explorer/fuzzing/fuzzer_corpus/90c1b392ccc71913bc6166593f51626e0cebb737.textproto create mode 100644 explorer/fuzzing/fuzzer_corpus/c7c6e4477db2a3b777e740964a09a379684261d8.textproto delete mode 100644 explorer/fuzzing/fuzzer_corpus/dedba2ac81916ee306624a2ac3db2a3c7a4ea5ad.textproto diff --git a/common/fuzzing/carbon.proto b/common/fuzzing/carbon.proto index 1f6947d9c961..bb4b72a494a2 100644 --- a/common/fuzzing/carbon.proto +++ b/common/fuzzing/carbon.proto @@ -300,7 +300,7 @@ message ClassDeclaration { message AlternativeSignature { optional string name = 1; - optional Expression signature = 2; + optional TupleLiteralExpression signature = 3; } message ChoiceDeclaration { diff --git a/common/fuzzing/proto_to_carbon.cpp b/common/fuzzing/proto_to_carbon.cpp index 2cbdad8eb376..9234fd9fa3df 100644 --- a/common/fuzzing/proto_to_carbon.cpp +++ b/common/fuzzing/proto_to_carbon.cpp @@ -644,7 +644,7 @@ static auto DeclarationToCarbon(const Fuzzing::Declaration& declaration, for (const auto& alternative : choice.alternatives()) { out << sep; IdentifierToCarbon(alternative.name(), out); - ExpressionToCarbon(alternative.signature(), out); + TupleLiteralExpressionToCarbon(alternative.signature(), out); } out << "}"; break; diff --git a/explorer/ast/declaration.h b/explorer/ast/declaration.h index df8f8e2f8b57..fda0f7610bdb 100644 --- a/explorer/ast/declaration.h +++ b/explorer/ast/declaration.h @@ -220,7 +220,7 @@ class ClassDeclaration : public Declaration { class AlternativeSignature : public AstNode { public: AlternativeSignature(SourceLocation source_loc, std::string name, - Nonnull signature) + Nonnull signature) : AstNode(AstNodeKind::AlternativeSignature, source_loc), name_(std::move(name)), signature_(signature) {} @@ -233,12 +233,12 @@ class AlternativeSignature : public AstNode { } auto name() const -> const std::string& { return name_; } - auto signature() const -> const Expression& { return *signature_; } - auto signature() -> Expression& { return *signature_; } + auto signature() const -> const TupleLiteral& { return *signature_; } + auto signature() -> TupleLiteral& { return *signature_; } private: std::string name_; - Nonnull signature_; + Nonnull signature_; }; class ChoiceDeclaration : public Declaration { diff --git a/explorer/fuzzing/ast_to_proto.cpp b/explorer/fuzzing/ast_to_proto.cpp index 68a59082681f..8e6dd45acee9 100644 --- a/explorer/fuzzing/ast_to_proto.cpp +++ b/explorer/fuzzing/ast_to_proto.cpp @@ -516,7 +516,7 @@ static auto DeclarationToProto(const Declaration& declaration) auto* alternative_proto = choice_proto->add_alternatives(); alternative_proto->set_name(alternative->name()); *alternative_proto->mutable_signature() = - ExpressionToProto(alternative->signature()); + TupleLiteralExpressionToProto(alternative->signature()); } break; } diff --git a/explorer/fuzzing/fuzzer_corpus/3a2e6f830b6edea6bcf31348f30a12a27b36d496.textproto b/explorer/fuzzing/fuzzer_corpus/3a2e6f830b6edea6bcf31348f30a12a27b36d496.textproto new file mode 100644 index 000000000000..c2b5d220588e --- /dev/null +++ b/explorer/fuzzing/fuzzer_corpus/3a2e6f830b6edea6bcf31348f30a12a27b36d496.textproto @@ -0,0 +1,482 @@ +compilation_unit { + package_statement { + package_name: "ExplorerTest" + } + is_api: true + declarations { + choice { + name: "Ints" + alternatives { + name: "None" + signature { + } + } + alternatives { + name: "One" + signature { + fields { + int_type_literal { + } + } + } + } + alternatives { + name: "Two" + signature { + fields { + int_type_literal { + } + } + fields { + int_type_literal { + } + } + } + } + } + } + declarations { + function { + name: "Main" + param_pattern { + } + return_term { + kind: Expression + type { + int_type_literal { + } + } + } + body { + statements { + variable_definition { + pattern { + binding_pattern { + name: "x" + type { + auto_pattern { + } + } + } + } + init { + call { + function { + field_access { + field: "None" + aggregate { + identifier { + name: "Ints" + } + } + } + } + argument { + tuple_literal { + } + } + } + } + } + } + statements { + variable_definition { + pattern { + binding_pattern { + name: "y" + type { + auto_pattern { + } + } + } + } + init { + call { + function { + field_access { + field: "One" + aggregate { + identifier { + name: "Ints" + } + } + } + } + argument { + tuple_literal { + fields { + int_literal { + value: 42 + } + } + } + } + } + } + } + } + statements { + variable_definition { + pattern { + binding_pattern { + name: "n" + type { + auto_pattern { + } + } + } + } + init { + int_literal { + value: 0 + } + } + } + } + statements { + match { + expression { + identifier { + name: "y" + } + } + clauses { + pattern { + expression_pattern { + expression { + field_access { + field: "None" + aggregate { + identifier { + name: "Ints" + } + } + } + } + } + } + statement { + assign { + lhs { + identifier { + name: "n" + } + } + rhs { + primitive_operator { + op: Add + arguments { + identifier { + name: "n" + } + } + arguments { + int_literal { + value: 2 + } + } + } + } + } + } + } + clauses { + pattern { + alternative_pattern { + choice_type { + identifier { + name: "Ints" + } + } + alternative_name: "One" + arguments { + fields { + binding_pattern { + name: "x" + type { + auto_pattern { + } + } + } + } + } + } + } + statement { + assign { + lhs { + identifier { + name: "n" + } + } + rhs { + primitive_operator { + op: Sub + arguments { + primitive_operator { + op: Add + arguments { + identifier { + name: "x" + } + } + arguments { + int_literal { + value: 1 + } + } + } + } + arguments { + int_literal { + value: 42 + } + } + } + } + } + } + } + clauses { + pattern { + alternative_pattern { + choice_type { + identifier { + name: "Ints" + } + } + alternative_name: "Two" + arguments { + fields { + binding_pattern { + name: "a" + type { + auto_pattern { + } + } + } + } + fields { + binding_pattern { + name: "b" + type { + auto_pattern { + } + } + } + } + } + } + } + statement { + assign { + lhs { + identifier { + name: "n" + } + } + rhs { + int_literal { + value: 2 + } + } + } + } + } + } + } + statements { + match { + expression { + identifier { + name: "x" + } + } + clauses { + pattern { + alternative_pattern { + choice_type { + identifier { + name: "Ints" + } + } + alternative_name: "One" + arguments { + fields { + binding_pattern { + name: "x" + type { + auto_pattern { + } + } + } + } + } + } + } + statement { + assign { + lhs { + identifier { + name: "n" + } + } + rhs { + primitive_operator { + op: Add + arguments { + identifier { + name: "x" + } + } + arguments { + int_literal { + value: 2 + } + } + } + } + } + } + } + clauses { + pattern { + expression_pattern { + expression { + call { + function { + field_access { + field: "None" + aggregate { + identifier { + name: "Ints" + } + } + } + } + argument { + tuple_literal { + } + } + } + } + } + } + statement { + assign { + lhs { + identifier { + name: "n" + } + } + rhs { + primitive_operator { + op: Sub + arguments { + identifier { + name: "n" + } + } + arguments { + int_literal { + value: 1 + } + } + } + } + } + } + } + clauses { + pattern { + alternative_pattern { + choice_type { + identifier { + name: "Ints" + } + } + alternative_name: "Two" + arguments { + fields { + binding_pattern { + name: "x" + type { + auto_pattern { + } + } + } + } + fields { + binding_pattern { + name: "y" + type { + auto_pattern { + } + } + } + } + } + } + } + statement { + assign { + lhs { + identifier { + name: "n" + } + } + rhs { + int_literal { + value: 5 + } + } + } + } + } + } + } + statements { + return_statement { + expression { + identifier { + name: "n" + } + } + } + } + } + } + } + declarations { + choice { + name: "MoreInts" + alternatives { + name: "None" + signature { + } + } + alternatives { + name: "One" + signature { + fields { + int_type_literal { + } + } + } + } + alternatives { + name: "Two" + signature { + fields { + int_type_literal { + } + } + fields { + int_type_literal { + } + } + } + } + } + } +} diff --git a/explorer/fuzzing/fuzzer_corpus/90c1b392ccc71913bc6166593f51626e0cebb737.textproto b/explorer/fuzzing/fuzzer_corpus/90c1b392ccc71913bc6166593f51626e0cebb737.textproto new file mode 100644 index 000000000000..cce937104f59 --- /dev/null +++ b/explorer/fuzzing/fuzzer_corpus/90c1b392ccc71913bc6166593f51626e0cebb737.textproto @@ -0,0 +1,299 @@ +compilation_unit { + package_statement { + package_name: "ExplorerTest" + } + is_api: true + declarations { + choice { + name: "Ints" + alternatives { + name: "None" + signature { + } + } + alternatives { + name: "One" + signature { + fields { + int_type_literal { + } + } + } + } + alternatives { + name: "Two" + signature { + fields { + int_type_literal { + } + } + fields { + int_type_literal { + } + } + } + } + } + } + declarations { + function { + name: "Main" + param_pattern { + } + return_term { + kind: Expression + type { + int_type_literal { + } + } + } + body { + statements { + variable_definition { + pattern { + tuple_pattern { + fields { + var_pattern { + pattern { + alternative_pattern { + choice_type { + identifier { + name: "Ints" + } + } + alternative_name: "Two" + arguments { + fields { + binding_pattern { + name: "a1" + type { + auto_pattern { + } + } + } + } + fields { + var_pattern { + pattern { + binding_pattern { + name: "a2" + type { + auto_pattern { + } + } + } + } + } + } + } + } + } + } + } + fields { + tuple_pattern { + fields { + tuple_pattern { + fields { + binding_pattern { + name: "b" + type { + auto_pattern { + } + } + } + } + fields { + var_pattern { + pattern { + binding_pattern { + name: "c" + type { + auto_pattern { + } + } + } + } + } + } + } + } + fields { + var_pattern { + pattern { + tuple_pattern { + fields { + binding_pattern { + name: "d" + type { + auto_pattern { + } + } + } + } + fields { + binding_pattern { + name: "e" + type { + auto_pattern { + } + } + } + } + } + } + } + } + } + } + } + } + init { + tuple_literal { + fields { + call { + function { + field_access { + field: "Two" + aggregate { + identifier { + name: "Ints" + } + } + } + } + argument { + tuple_literal { + fields { + int_literal { + value: 1 + } + } + fields { + int_literal { + value: 10 + } + } + } + } + } + } + fields { + tuple_literal { + fields { + tuple_literal { + fields { + int_literal { + value: 2 + } + } + fields { + int_literal { + value: 3 + } + } + } + } + fields { + tuple_literal { + fields { + int_literal { + value: 4 + } + } + fields { + int_literal { + value: 5 + } + } + } + } + } + } + } + } + } + } + statements { + assign { + lhs { + identifier { + name: "a1" + } + } + rhs { + int_literal { + value: 0 + } + } + } + } + statements { + assign { + lhs { + identifier { + name: "a2" + } + } + rhs { + int_literal { + value: 0 + } + } + } + } + statements { + assign { + lhs { + identifier { + name: "c" + } + } + rhs { + int_literal { + value: 0 + } + } + } + } + statements { + assign { + lhs { + identifier { + name: "d" + } + } + rhs { + int_literal { + value: 0 + } + } + } + } + statements { + assign { + lhs { + identifier { + name: "e" + } + } + rhs { + int_literal { + value: 0 + } + } + } + } + statements { + return_statement { + expression { + int_literal { + value: 0 + } + } + } + } + } + } + } +} diff --git a/explorer/fuzzing/fuzzer_corpus/c7c6e4477db2a3b777e740964a09a379684261d8.textproto b/explorer/fuzzing/fuzzer_corpus/c7c6e4477db2a3b777e740964a09a379684261d8.textproto new file mode 100644 index 000000000000..bef4a83a0c95 --- /dev/null +++ b/explorer/fuzzing/fuzzer_corpus/c7c6e4477db2a3b777e740964a09a379684261d8.textproto @@ -0,0 +1,28 @@ +compilation_unit { + declarations { + choice { + alternatives { + signature { + fields { + primitive_operator { + arguments { + intrinsic { + argument { + fields { + primitive_operator { + arguments { + identifier { + } + } + } + } + } + } + } + } + } + } + } + } + } +} diff --git a/explorer/fuzzing/fuzzer_corpus/dedba2ac81916ee306624a2ac3db2a3c7a4ea5ad.textproto b/explorer/fuzzing/fuzzer_corpus/dedba2ac81916ee306624a2ac3db2a3c7a4ea5ad.textproto deleted file mode 100644 index 3021e3dd9f35..000000000000 --- a/explorer/fuzzing/fuzzer_corpus/dedba2ac81916ee306624a2ac3db2a3c7a4ea5ad.textproto +++ /dev/null @@ -1,26 +0,0 @@ -compilation_unit { - declarations { - choice { - alternatives { - signature { - primitive_operator { - arguments { - intrinsic { - argument { - fields { - primitive_operator { - arguments { - identifier { - } - } - } - } - } - } - } - } - } - } - } - } -}