Skip to content
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

BestFirstSearch: don't give up too soon #1729

Merged
merged 4 commits into from
Feb 21, 2020
Merged

Conversation

kitbellew
Copy link
Collaborator

@kitbellew kitbellew commented Feb 21, 2020

Currently, the algorithm would clear the search priority queue when the top candidate points to a new statement. Sometimes this leads to losing a viable path and the dreaded "Unable to format due to bug" error.

Rather than clearing the queue, let's maintain several generations of priority queues and create a new generation on a new statement, thus continuing to process subsequent states just like the old algorithm did but with the previously discarded states available as backup.

Apply this modification to top-level invocations only, so that nested calls will still terminate early; thus the backup candidates are really processed at the very end of the existing logic.

Fixes #448. Fixes #1462. Fixes #1485. Fixes #1599. Fixes #1717.

NB: scala-repos diffs, looks like they contain files previously unformatted by scalafmt: kitbellew/scala-repos@0876f01?w=1

@kitbellew
Copy link
Collaborator Author

@olafurpg the change is simple enough but likely requires your level of understanding of the existing algorithm to review, PTAL.

@tanishiking @poslegm fyi.

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the idea of generations! That's a neat trick 👍 Only one comment on the performance of comparing the order of states. I can't find the link to the original discussions but I remember that comparing State instances showed up in CPU profiles.

Currently, the algorithm would clear the search priority queue when the
top candidate points to a new statement. Sometimes this leads to losing
a viable path and the dreaded "Unable to format due to bug" error.

Rather than clearing the queue, let's maintain several generations of
priority queues and create a new generation on a new statement, thus
continuing to process subsequent states just like the old algorithm did
but with the previously discarded states available as backup.

Apply this modification to top-level invocations only, so that nested
calls will still terminate early; thus the backup candidates are really
processed at the very end of the existing logic.

Fixes scalameta#448. Fixes scalameta#1462. Fixes scalameta#1485. Fixes scalameta#1599. Fixes scalameta#1717.
@kitbellew kitbellew merged commit 9112af4 into scalameta:master Feb 21, 2020
@kitbellew kitbellew deleted the 1729 branch February 21, 2020 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants