Skip to content
Merged
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
12 changes: 9 additions & 3 deletions xls/dslx/frontend/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3195,9 +3195,15 @@ absl::StatusOr<Function*> Parser::ParseProcNext(
"Channels cannot be Proc next params.");
}

XLS_ASSIGN_OR_RETURN(TypeAnnotation * return_type,
CloneNode(state_param->type_annotation(),
&PreserveTypeDefinitionsReplacer));
TypeAnnotation* return_type;
if (module_->attributes().contains(ModuleAttribute::kExplicitStateAccess)) {
return_type = module_->Make<TupleTypeAnnotation>(
state_param->span(), std::vector<TypeAnnotation*>{});
} else {
XLS_ASSIGN_OR_RETURN(return_type,
CloneNode(state_param->type_annotation(),
&PreserveTypeDefinitionsReplacer));
}
XLS_ASSIGN_OR_RETURN(StatementBlock * body,
ParseBlockExpression(inner_bindings));
Span span(oparen.span().start(), GetPos());
Expand Down
20 changes: 20 additions & 0 deletions xls/dslx/frontend/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,26 @@ TEST_F(ParserTest, ParseExplicitStateAccessAttribute) {
testing::ElementsAre(ModuleAttribute::kExplicitStateAccess));
}

TEST_F(ParserTest, ExplicitStateAccessProcNextReturnsEmptyTuple) {
constexpr std::string_view kProgram = R"(#![feature(explicit_state_access)]
proc simple {
config() {
()
}
init {
u32:0
}
next(state: u32) {
}
})";
XLS_ASSERT_OK_AND_ASSIGN(std::unique_ptr<Module> module, Parse(kProgram));
XLS_ASSERT_OK_AND_ASSIGN(Proc * proc,
module->GetMemberOrError<Proc>("simple"));
const Function& next = proc->next();
ASSERT_NE(next.return_type(), nullptr);
EXPECT_EQ(next.return_type()->ToString(), "()");
}

// Verifies that we can walk backwards through a tree. In this case, from the
// terminal node to the defining expr.
TEST(ParserBackrefTest, CanFindDefiner) {
Expand Down