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

Improve specialization optimization #2944

Merged
merged 12 commits into from
Aug 14, 2024
Merged

Improve specialization optimization #2944

merged 12 commits into from
Aug 14, 2024

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Aug 8, 2024

Checklist

@lukaszcz lukaszcz added core Related to JuvixCore optimization labels Aug 8, 2024
@lukaszcz lukaszcz added this to the 0.6.5 milestone Aug 8, 2024
@lukaszcz lukaszcz self-assigned this Aug 8, 2024
@lukaszcz lukaszcz added enhancement New feature or request fix:bug labels Aug 9, 2024
@lukaszcz lukaszcz marked this pull request as ready for review August 13, 2024 09:50
@@ -269,7 +271,7 @@ convertNode = dmapLRM go

shiftSpecargs :: [Int] -> [Int] -> [Int]
shiftSpecargs specargs =
map (\argNum -> argNum - length (filter (argNum <) specargs))
map (\argNum -> argNum - length (filter (argNum >) specargs))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the change from < -> > fix a bug or is it related to another change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was incorrect, but we didn't see it because:

  1. This adjusts the indices of arguments marked for specialization which are not specialized because the provided argument has the wrong form, e.g., it is a variable (makes no sense to specialize by an unknown). They can be specialized later in another iteration if, e.g., inlining substitutes a concrete value for the variable, but this is not very common.
  2. If specialization fails nothing really bad happens -- the function application is just not specialized and thus less efficient.

@@ -19,7 +19,7 @@ optimize' :: CoreOptions -> Module -> Module
optimize' opts@CoreOptions {..} md =
filterUnreachable
. compose
(4 * _optOptimizationLevel)
(6 * _optOptimizationLevel)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why has this changed from 4 to 6?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because with maps and folds inside record definitions 4 iterations are not enough to inline & specialize everything in a typical case (without further nestings).

@lukaszcz lukaszcz requested a review from paulcadman August 13, 2024 16:48
paulcadman
paulcadman previously approved these changes Aug 13, 2024
@lukaszcz lukaszcz merged commit fcd52a4 into main Aug 14, 2024
4 checks passed
@lukaszcz lukaszcz deleted the improve-spec-opt branch August 14, 2024 08:04
paulcadman added a commit to anoma/juvix-stdlib that referenced this pull request Aug 14, 2024
* Closes #121 
* Depends on anoma/juvix#2944
* Includes #123
* Adds `Stdlib.Data.Range` to the Prelude. Since now `for` and `rfor`
are trait fields, there is no name clash anymore.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to JuvixCore enhancement New feature or request fix:bug optimization
Projects
None yet
2 participants