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

[#265] Make SuperComposition less brittle #266

Conversation

treeowl
Copy link

@treeowl treeowl commented May 9, 2022

  • Use overlapping instances instead of incoherent ones. Fixes SuperComposition instance resolution is brittle #265.

  • Make the first argument of ... a function unconditionally, before
    instance selection. This can theoretically improve inference slightly,
    though it probably doesn't have much impact in practice.

Description

Related issues(s)

✓ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this
checkmark indicating that you are sure it is dealt with (be that by irrelevance).

  • I made sure my PR addresses a single concern, or multiple concerns which
    are inextricably linked. Otherwise I should open multiple PR's.
  • If your PR fixes/relates to an open issue then the description should
    reference this issue. See also auto linking on
    github
    .

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    I checked whether I should update the docs and did so if necessary:

  • Record your changes

    • I added an entry to the changelog if my changes are visible to the users
      and
    • provided a migration guide for breaking changes if possible

Stylistic guide (mandatory)

  • My commit history is clean (only contains changes relating to my
    issue/pull request and no reverted-my-earlier-commit changes) and commit
    messages start with identifiers of related issues in square brackets.

    Example: [#42] Short commit description

    If necessary both of these can be achieved even after the commits have been
    made/pushed using rebase and squash.

@treeowl
Copy link
Author

treeowl commented May 9, 2022

This change causes compilation failures in the benchmark suite. I tried to patch that up using an incoherent instance (to let type information flow from the result type to the second argument type):

instance {-# INCOHERENT #-} (SuperComposition x y d q, cd ~ (c -> d)) =>
         SuperComposition x y cd (c -> q) where
    (f ... g) c = (...) @x @y @d @q f (g c)
    {-# INLINE (...) #-}

For some reason, that leads to a reduction stack overflow in the benchmark, which I find extremely mysterious. It looks to me like at least one type argument gets smaller in each recursive call, and none get larger. What am I missing???

@treeowl
Copy link
Author

treeowl commented May 9, 2022

Oh, of course, that particular instance is just wrong, because the arrows could come from the first argument. Whoops! I think it's okay to break this a little, in exchange for more stable behavior.

@treeowl treeowl force-pushed the dfeuer/#265-coherent-super-composition branch from 716654d to 4791828 Compare May 9, 2022 21:56
@treeowl
Copy link
Author

treeowl commented May 9, 2022

Where should I put a migration guide?

* Use overlapping instances instead of incoherent ones. Fixes serokell#265.

* Make the first argument of `...` a function unconditionally, before
  instance selection. This can theoretically improve inference slightly,
  though it probably doesn't have much impact in practice.
@treeowl treeowl force-pushed the dfeuer/#265-coherent-super-composition branch from 4791828 to 078a5ca Compare May 9, 2022 22:58
@treeowl treeowl closed this May 10, 2022
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.

SuperComposition instance resolution is brittle
1 participant