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

Fix compiler bug with rank 2 types in mapAccuml #2342

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

CharlonTank
Copy link

@CharlonTank CharlonTank commented Dec 14, 2024

This PR fixes a compiler bug that occurs when using mapAccuml with explicit type annotations. The bug manifested as a compiler crash with the message "x [rank = 2]" followed by "thread blocked indefinitely in an MVar operation".

The issue was that the compiler was incorrectly treating rank 2 type variables as invalid during generalization. These rank 2 variables are actually valid and necessary for higher-order functions like mapAccuml.

The fix modifies the isGeneric function to specifically allow rank 2 variables, which enables proper type inference for mapAccuml and similar functions.

Test case that previously crashed but now works properly:

func =
    List.Extra.mapAccuml
        (\acc x ->
            let
                newAcc = acc + 1
                result = x + acc
            in
            ( newAcc, result )
        )
        0
        [1, 2, 3]

Unfortunately, it (hot)fixes the problem but there surely are some side-effects

Copy link

Thanks for suggesting these code changes. To set expectations:

  • Pull requests are reviewed in batches, so it can take some time to get a response.
  • Smaller pull requests are easier to review. To fix nine typos, nine specific issues will always go faster than one big one. Learn why here.
  • Reviewers may not know as much as you about certain situations, so add links to supporting evidence for important claims, especially regarding standards for CSS, HTTP, URI, etc.

Finally, please be patient with the core team. They are trying their best with limited resources.

@CharlonTank CharlonTank marked this pull request as draft December 14, 2024 15:43
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.

1 participant