-
Notifications
You must be signed in to change notification settings - Fork 83
Fix #269 and rewrite DFAMin #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
They are populated by Lines 23 to 24 in eb6c78d
|
Excellent work, @nicuveo ! I took some hours working through the new code for
The last point is something we should/could discuss. My intuition is that If you have any comments on my other changes, let me know as well. My plan is to squash all commits into one. P.S.: In general, I wonder whether the testsuite of alex is not too skimpy. After all, it did not discover the bug you found. |
To fix CI failures try bumping v2 to v3 in alex/.github/workflows/emulated.yml Line 28 in eb6c78d
|
Thank you @andreasabel! Regarding your changes to Regarding let x = IntSet.unions $ do
(target, sources) <- IntMap.toList allPreviousStates
guard $ target `InsSet.member` a
pure sources (An extremely pedantic nitpick, please feel free to ignore: 4522b8d introduces a nested Regarding the test suite: i agree. A big challenge i faced with this work was managing to find a broken example expressed by rules, rather than as a quickcheck property / unit test that tests the invariants of In general, i think this project could use a bit of TLC: it really lacks standardization, the naming conventions and comment styles are a bit all over the place... it looks, i'm sorry to say, like the project has been a bit neglected. I'd be happy to spend some time making cleanup / harmonization / modernization PRs; is that something that'd be welcome? Thanks! |
Ah, thanks! I've noticed the failure seems random, the |
I've pushed the changes to |
I follow in general to separate bug fixes from refactorings, but in this case most of the lines of
Yes, sure!
I agree with the general style to not deeply nest
Refactorings and clean-ups are a bit of a two-edged sword. One the one hand, they improve the quality of the code, on the other hand, there is the risk of introducing regressions. After all, the current code, has passed the "test of time" (which is some correctness guarantee, yet not enough as the present bug shows.).
(The risk of regressions is real; e.g. see the "Hall of fame" for the make-over of the sister project |
I'd be happy to merge the PR in the current state, if you agree @nicuveo . |
This reverts commit e0126a8.
A start state cannot belong to several equivalence classes (they are disjoint), so we can remove already assigned start states from the list of start states we want to assign.
Since all old states in an equivalence class are equivalent, we only need the data from one of them to construct the new state.
Sounds good! What's the proper way to get involved in such future plans? I have a bit of bandwidth and would be happy to help. |
Oh wait no the new test failure is something we introduced. I'll fix that ASAP. |
## Changes in 3.5.3.0 * Fix critical bug in automaton minimizer ([PR #270](haskell/alex#270)), thanks Antoine Leblanc! * Tested with GHC 8.0 - 9.12.2.
Overview
This PR fixes a long-standing bug in the minimizer. As not all states are in the queue
Q
(orW
as it is known in the reference implementation of Hopcroft's algorithm), it is possible in some rare cases for some sets to not be properly subdivided. This can result in the wrong rule being selected at runtime.This PR adds two new tests: one that demonstrates the issue with older versions of the minimizer (pre 4f0b51b) and one that demonstrates the issue with current versions of the minimizer.
Implementation details
The gist of this change is simple: we now initialize
R
to the empty set, andW
(renamed from its previous nonstandard name ofQ
) to a set of subsets of stages. I've additionally used this PR as an opportunity to do several small cleanups.First, this PR rewrites the Note that describes the algorithm. It properly introduces some notation that was left unexplained, fixes the error regarding the initial sets, and fixes some typos.
As far as
groupEquivalentStates
is concerned, beyond the aforementioned core change, this PR extracts several helper functions to the top level, renames them, and adds some basic documentation. For instance, what wasbigmap
is now created by a top-level function calledgenerateReverseTransitionCache
.Beyond this, it also makes use of list functions to reduce the amount of manual list construction / deconstruction, and makes some minor changes to
minimizeDFA
for readability, and to avoid needing to silence shadowing warnings.Open questions