Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions xls/dslx/bytecode/bytecode_emitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,12 @@ absl::StatusOr<Bytecode::MatchArmItem> BytecodeEmitter::HandleNameDefTreeExpr(
[&](WildcardPattern* n) -> absl::StatusOr<Bytecode::MatchArmItem> {
return Bytecode::MatchArmItem::MakeWildcard();
},
[&](SumVariantPayloadPattern* /*n*/)
-> absl::StatusOr<Bytecode::MatchArmItem> {
return absl::UnimplementedError(
"Semantic sum patterns are not supported by the bytecode "
"runtime.");
},
[&](RestOfTuple* n) -> absl::StatusOr<Bytecode::MatchArmItem> {
return Bytecode::MatchArmItem::MakeRestOfTuple();
},
Expand Down Expand Up @@ -1676,6 +1682,11 @@ absl::Status BytecodeEmitter::HandleStructInstance(const StructInstance* node) {
return absl::OkStatus();
}

absl::Status BytecodeEmitter::HandleSumInstance(const SumInstance*) {
return absl::UnimplementedError(
"Semantic sum execution is not supported by the bytecode runtime.");
}

absl::Status BytecodeEmitter::HandleSplatStructInstance(
const SplatStructInstance* node) {
// For each field in the struct:
Expand Down
1 change: 1 addition & 0 deletions xls/dslx/bytecode/bytecode_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class BytecodeEmitter : public ExprVisitor {
absl::Status HandleSpawn(const Spawn* node) override;
absl::Status HandleString(const String* node) override;
absl::Status HandleStructInstance(const StructInstance* node) override;
absl::Status HandleSumInstance(const SumInstance* node) override;
absl::Status HandleSplatStructInstance(
const SplatStructInstance* node) override;
absl::Status HandleConditional(const Conditional* node) override;
Expand Down
4 changes: 4 additions & 0 deletions xls/dslx/constexpr_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ absl::Status ConstexprEvaluator::HandleStructInstance(
return InterpretExpr(expr);
}

absl::Status ConstexprEvaluator::HandleSumInstance(const SumInstance*) {
return absl::UnimplementedError("Semantic sum constants are not supported.");
}

absl::Status ConstexprEvaluator::HandleConditional(const Conditional* expr) {
// Simple enough that we don't need to invoke the interpreter.
EVAL_AS_CONSTEXPR_OR_RETURN(expr->test());
Expand Down
1 change: 1 addition & 0 deletions xls/dslx/constexpr_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class ConstexprEvaluator : public xls::dslx::ExprVisitor {
absl::Status HandleStatementBlock(const StatementBlock* expr) override;
absl::Status HandleString(const String* expr) override;
absl::Status HandleStructInstance(const StructInstance* expr) override;
absl::Status HandleSumInstance(const SumInstance* expr) override;
absl::Status HandleTupleIndex(const TupleIndex* expr) override;
absl::Status HandleUnop(const Unop* expr) override;
absl::Status HandleConstFor(const ConstFor* expr) override;
Expand Down
5 changes: 5 additions & 0 deletions xls/dslx/cpp_transpiler/cpp_type_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,11 @@ CppTypeGenerator::Create(const TypeDefinition& type_definition,
return EnumCppTypeGenerator::Create(enum_def, type_info,
import_data, namespaces);
},
[&](const SumDef* sum_def)
-> absl::StatusOr<std::unique_ptr<CppTypeGenerator>> {
return absl::UnimplementedError(
absl::StrFormat("Unsupported type: %s", sum_def->ToString()));
},
[&](const ColonRef* colon_ref)
-> absl::StatusOr<std::unique_ptr<CppTypeGenerator>> {
return absl::UnimplementedError(
Expand Down
19 changes: 19 additions & 0 deletions xls/dslx/dslx_fmt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ def test_small_no_spaces_example_in_place(self):
""")
self.assertEqual(self._run(contents, in_place=True), want)

def test_semantic_sum_payload_comment_is_preserved(self):
contents = textwrap.dedent("""\
enum Option {
Some(
// Payload comment.
u32,
),
}
""")
want = textwrap.dedent("""\
enum Option {
Some(
// Payload comment.
u32
),
}
""")
self.assertEqual(self._run(contents), want)

def test_multi_file_in_place_fmt(self):
contents0 = 'fn f()->u32{u32:42}'
contents1 = 'fn g()->u32{u32:42}'
Expand Down
9 changes: 9 additions & 0 deletions xls/dslx/exhaustiveness/match_exhaustiveness_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ PatternLeaf ToPatternLeaf(const NameDefTree::Leaf& leaf) {
return SomeWildcard();
},
[&](Number* number) -> PatternLeaf { return number; },
[&](SumVariantPayloadPattern* /*constructor_pattern*/)
-> PatternLeaf {
LOG(FATAL) << "SumVariantPayloadPattern not yet supported in "
"MatchExhaustivenessChecker";
},
[&](RestOfTuple* rest_of_tuple) -> PatternLeaf {
LOG(FATAL) << "RestOfTuple not valid for conversion to PatternLeaf";
}},
Expand Down Expand Up @@ -293,6 +298,10 @@ std::vector<PatternLeaf> ExpandPatternLeaves(const NameDefTree& pattern,
result.push_back(ToPatternLeaf(leaf));
types_index += 1;
},
[&](const SumVariantPayloadPattern* /*unused*/) {
result.push_back(ToPatternLeaf(leaf));
types_index += 1;
},
[&](const RestOfTuple* /*unused*/) {
// Instead of using flattened_index here, use types_index (the
// number of tuple elements already matched) to figure out how
Expand Down
Loading
Loading