Skip to content

Direct fn calls: disable for cyclic calls #44

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

Merged

Conversation

Janiczek
Copy link
Collaborator

Quick Summary: Cyclic functions were not correctly analyzed for makeArgLookup (finding the number of arguments of a function).

SSCCE

module Main exposing (main)

import Html exposing (Html)


main : Html msg
main =
    Html.div []
        [ Html.text (a1 1 1)
        , Html.text (a2 1 1)
        , Html.text (b1 3 4 5)
        , Html.text (b2 1 2 3 4 5)
        ]


a1 : Int -> Int -> String
a1 =
    a2


a2 : Int -> Int -> String
a2 m n =
    if n > 0 then
        a1 (m - 1) (n - 1)

    else
        "done"


b1 : Int -> Int -> Int -> String
b1 =
    b2 1 2


b2 : Int -> Int -> Int -> Int -> Int -> String
b2 x1 x2 x3 x4 x5 =
    if True then
        "done"

    else
        b1 3 4 5

Additional Details

Found by @pithub here

I attempted to optimize these cases in #43 but got stuck on actually generating the needed JavaScript, making sure generated arg names don't collide with user-given ones, etc.

It should be technically possible to do this but it's not a 5-minute fix.

Until then we do what Gren did and just don't optimize cyclic function definitions in this way and fall back to AX/FX.

@MartinSStewart
Copy link
Member

Thanks for looking into this! I don't really have much to add, reviewing Haskell isn't my strong suit 😅

Hopefully @supermario has time to review this.

Comment on lines +151 to +152
expectTextContains jsOutput "$Main$b1, 1, 1)" -- A2
expectTextContains jsOutput "$Main$b2$(1, 1)"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With the test we're showing that the designated "beginning of the cycle" doesn't get called directly (there's no $b1$), but the other parts of the cycle do.

Copy link
Member

@supermario supermario left a comment

Choose a reason for hiding this comment

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

Thanks @Janiczek 👍

@supermario supermario merged commit 685a6d0 into lamdera:lamdera-next Mar 27, 2025
@Janiczek Janiczek deleted the janiczek/make-it-stop-crashing branch March 27, 2025 21:48
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.

3 participants