Skip to content

Commit

Permalink
Merge pull request #451 from mo-xiaoming/is-prim-variant
Browse files Browse the repository at this point in the history
with a large (>500) match table, variant might cause "not a primitive match table" error
  • Loading branch information
dawa79 authored Aug 14, 2023
2 parents 88a712b + 82c108c commit 431c19b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/hobbes/lang/pat/dfa.C
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ MStatePtr makeSwitch(const MDFA* dfa, const std::string& switchVar, const Switch
if (jmps.empty()) {
return dfa->states[defState];
} else if (isUnit(jmps[0].first->primType())) {
if (dfa->inPrimSel) {
return dfa->states[jmps[0].second];
}
return actAndThen(assume(var(switchVar, dfa->rootLA), primty("unit"), dfa->rootLA), jmps[0].second);
} else {
return MStatePtr(new SwitchVal(switchVar, jmps, defState));
Expand Down
14 changes: 14 additions & 0 deletions test/Matching.C
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,17 @@ TEST(Matching, noRaceInterpMatch) {
EXPECT_EQ(wrongMatches.load(), size_t(0));
c().buildInterpretedMatches(false);
}

TEST(Matching, isPrimSelectionWithVariant) {
std::ostringstream rows;
rows << "(\\a b.match a b with\n";
rows << "| |Close| _ -> 1\n";
for (size_t i = 0; i < 499; ++i) {
rows << "| _ " << i << " -> " << i+2 << "\n";
}
rows << "| _ _ -> -1\n";
rows << ")(|Open|::|Open, Close|, 9)";
auto f = c().compileFn<int()>(rows.str());
EXPECT_EQ(f(), 11);
}

0 comments on commit 431c19b

Please sign in to comment.