compiler icon indicating copy to clipboard operation
compiler copied to clipboard

Unexpected infinite loop with strange workaround

Open HugoPeters1024 opened this issue 3 years ago • 1 comments

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

  • Elm: 0.19.1
  • Browser: Brave
  • Operating System: Ubuntu

HugoPeters1024 avatar Aug 31 '22 13:08 HugoPeters1024

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

github-actions[bot] avatar Aug 31 '22 13:08 github-actions[bot]