elm-lang / elm-make

A build tool for Elm projects
BSD 3-Clause "New" or "Revised" License
175 stars 45 forks source link

Eating all CPU and memory #178

Closed dwendelen closed 6 years ago

dwendelen commented 6 years ago

When I try to process the code below with elm-make, then it eats all my memory and it uses all my CPU's at 100%. The same thing happens on http://elm-lang.org/try.

Version: elm-make 0.18 (Elm Platform 0.18.0)

Line 7 (type annotation of string) is the problem. Commenting this line out solves the problem. I am aware of the fact that the type annotation is wrong, but it should not eat all my resources. It should report a compilation error.

import Html exposing (text)

ctor: a -> (a -> List String -> Result String b) -> List String -> Result String b
ctor ctor next list =
  next ctor list

string: (a -> List String -> Result String a) -> (String -> a) -> List String -> Result String a
string next f list =
  case list of
    [] ->
      Err "Not enough arguments"
    head::tail ->
      next (f head) tail

end: a -> List String -> Result String a
end result list =
  case list of
    [] -> Ok result
    _ -> Err "Too many arguments"

type MyType1 = MyCon1 String String
type MyType2 = MyCon2 String String String

chain1: List String -> Result String MyType1
chain1 = ctor MyCon1 <| string <| string <| end
result1 = chain1 ["A", "B"]

chain2: List String -> Result String MyType2
chain2 = ctor MyCon2 <| string <| string <| string <| end
result2 = chain2 ["A", "B", "C"]

main = text (toString1 result1 ++ toString2 result2)

toString1 result = case result of
  Err err -> "Error: " ++ err
  Ok (MyCon1 a b) -> a ++ b

toString2 result = case result of
  Err err -> "Error: " ++ err
  Ok (MyCon2 a b c) -> a ++ b ++ c
process-bot commented 6 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

evancz commented 6 years ago

In my development build, I get the following error immediately from this code:

-- SHADOWING ---------------------------------------------------------- temp.elm

These variables cannot have the same name:

10| ctor ctor next list =
    ^^^^ ^^^^
Think of a more helpful name for one of them and you should be all set!

Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read <https://elm-lang.org/hints/0.19.0/shadowing> for more details on
this choice.

My suspicion is that some sort of infinite type was created before shadowing was restricted. Not sure though. Anyway, thank you for the report!