elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Unexpected infinite loop with strange workaround #2276

Open HugoPeters1024 opened 1 year ago

HugoPeters1024 commented 1 year ago

Quick Summary: ???

I am making a pure, recursive, transformation over an AST type and noticed that in some cases there is an infinite loop (or at the very least the applications hangs), which is weird because every case arm makes progress. What is REALLY weird is that manually eliminating a shared expression with a let binding resolves the issue.

SSCCE

eraseTypesExpr : Expr -> Expr
eraseTypesExpr expr = case expr of
    -- some other cases
    EApp f a -> case eraseTypesExpr a of
          EVar x -> if H.isTyBinderId x then (eraseTypesExpr f) else EApp (eraseTypesExpr f) (eraseTypesExpr a)
          EType _ -> eraseTypesExpr f
          _ -> EApp (eraseTypesExpr f) (eraseTypeExpr a)

Eliminating two occs of eraseTypeExpr a results in a perfectly responsive application:

eraseTypesExpr : Expr -> Expr
eraseTypesExpr expr = case expr of
   -- some other cases
    EApp f a -> 
        let ea = eraseTypesExpr a
        in case ea of
          EVar x -> if H.isTyBinderId x then (eraseTypesExpr f) else EApp (eraseTypesExpr f) (eraseTypesExpr a)
          EType _ -> eraseTypesExpr f
          _ -> EApp (eraseTypesExpr f) ea
github-actions[bot] commented 1 year ago

Thanks for reporting this! To set expectations:

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