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 Accum function refactoring. #264

Open
ryukzak opened this issue Jan 21, 2024 · 0 comments
Open

Improve Accum function refactoring. #264

ryukzak opened this issue Jan 21, 2024 · 0 comments

Comments

@ryukzak
Copy link
Owner

ryukzak commented Jan 21, 2024

The problem you can find in the following test:

        , testCase "Complex items sum refactor" $
            let
                -- Start algorithm:
                -- tmp1, tmp2 = a + b
                -- tmp3, tmp4 = c + d
                -- res1 = one + tmp1 + tmp3
                -- res2 = two + tmp2 + tmp4
                -- res = res1 + res2

                -- Result algorithm:
                -- res = one + a + b + c + d + two + a + b + c + d
                func1 = acc [Push Plus (I "a"), Push Plus (I "b"), Pull (O $ S.fromList ["tmp1", "tmp2"])]
                func2 = acc [Push Plus (I "c"), Push Plus (I "d"), Pull (O $ S.fromList ["tmp3", "tmp4"])]
                func3 = acc [Push Plus (I "one"), Push Plus (I "tmp1"), Push Plus (I "tmp3"), Pull (O $ S.fromList ["res1"])]
                func4 = acc [Push Plus (I "two"), Push Plus (I "tmp2"), Push Plus (I "tmp4"), Pull (O $ S.fromList ["res2"])]
                func5 = acc [Push Plus (I "res1"), Push Plus (I "res2"), Pull (O $ S.fromList ["res"])]

                funcRes =
                    acc
                        [ Push Plus (I "one")
                        , Push Plus (I "a")
                        , Push Plus (I "b")
                        , Push Plus (I "c")
                        , Push Plus (I "d")
                        , Push Plus (I "two")
                        , Push Plus (I "a")
                        , Push Plus (I "b")
                        , Push Plus (I "c")
                        , Push Plus (I "d")
                        , Pull (O $ S.fromList ["res"])
                        ] ::
                        F String Int
             in
                [func1, func2, func3, func4, func5] `refactorTo` [funcRes]
    Complex items sum refactor:                                                FAIL
      test/NITTA/Model/Problems/Refactor/Accum/Tests.hs:155:
      expected: fromList [Acc(+one +a +b +c +d +two +a +b +c +d = res)]
       but got: fromList [Acc(+a +b = tmp1 = tmp2),Acc(+c +d = tmp3 = tmp4),Acc(+one +tmp1 +tmp3 +two +tmp2 +tmp4 = res)]
      Use -p '/Complex items sum refactor/' to rerun this test only.

As you see, after refactoring we have a lot of buffer variables. They should be merged in one function to reduce numbers of transactions.

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

No branches or pull requests

1 participant