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

Allow improveIf of con/undet when only one constructor #748

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quark17
Copy link
Collaborator

@quark17 quark17 commented Nov 6, 2024

This fixes #742 by allowing improveIf to merge ICCon and ICUndet when the type has only one constructor, by pushing the conditional into the constructor arguments.

when (length argTypes /= length es1) $ internalError ("improveIf Con/Undet:" ++ ppReadable (argTypes, es1))
let mkUndet t = icUndetAt (getIdPosition i2) t u
(es', bs) <- mapAndUnzipM (\(t, e1) -> improveIf f t cnd e1 (mkUndet t)) (zip argTypes es1)
-- unambiguous improvement because the ICCon has propagated out
Copy link
Collaborator

Choose a reason for hiding this comment

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

great comment, thank you for that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't my comment. The body of this clause is copied from an earlier clause, that optimizes arms containing the same constructor, line 4359. The comment comes from there.

This duplication could be avoided by having the new clause (that I'm adding) only convert the else _ to else (C _ _ _), and then recursively call improveIf to do the merging of C e1 e2 e3 with C _ _ _ (for example). But most of the clause is just computing the types of the arguments to C, so most of the lines in the body of the clause would be duplicated anyway. It's not much more to just go ahead and do the full optimization, and avoid any duplicated work from the recursive call.

@@ -0,0 +1,45 @@
// This example comes from GitHub Issue #742
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just add that it's testing the effect of this optimization on compilation time rather than directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Evaluator regression
2 participants