roc icon indicating copy to clipboard operation
roc copied to clipboard

Stack overflow only when debugging Unificaitons

Open wizard7377 opened this issue 1 year ago • 1 comments

Roc overflows the stack whenever the cargo run is passed ROC_PRINT_UNIFICATIONS=1 for the first time. That is, it does not overflow if it is ROC_PRINT_UNIFICATIONS=0, nor if, since the last cargo clean it has at any point been run with ROC_PRINT_UNIFICATIONS=0, even if it is then run with ROC_PRINT_UNIFICATIONS=1

module []

ConsList a : [Cons a (ConsList a), Empty]

cons : b, ConsList b -> ConsList b
cons = \h, t -> Cons h t

empty : ConsList *
empty = Empty

consList : List c -> ConsList c
consList = \l -> l |> List.walkBackwards empty \state, elem -> cons elem state

(file.rc, from issue #6879)

Steps to Reproduce

  1. Run cargo clean
  2. Run cargo run file.rc (the Roc compiler will give an error, but it will not itself overflow)
  3. Run cargo clean
  4. Run ROC_PRINT_UNIFICATIONS=1 cargo run file.rc (the Roc compiler itself will overflow)
  5. Run cargo run file.rc (the Roc compiler will give an error, but it will not itself overflow)
  6. Run ROC_PRINT_UNIFICATIONS=1 cargo run file.rc (now the compiler will not overflow, unlike before, even though it does give an error)

wizard7377 avatar Dec 15 '24 02:12 wizard7377

This means the overflow is happening while print unifications when typechecking the standard library. The standard library's types are cached after the first build.

This is not particularly surprising because recursive types are not yet marked as recursive will be printed to full (infinite) depth.

On Sat, Dec 14, 2024 at 9:06 PM Asher Frost @.***> wrote:

Roc overflows the stack whenever the cargo run is passed ROC_PRINT_UNIFICATIONS=1 for the first time. That is, it does not overflow if it is ROC_PRINT_UNIFICATIONS=0, nor if, since the last cargo clean it has at any point been run with ROC_PRINT_UNIFICATIONS=0, even if it is then run with ROC_PRINT_UNIFICATIONS=1

module [] ConsList a : [Cons a (ConsList a), Empty] cons : b, ConsList b -> ConsList bcons = \h, t -> Cons h t empty : ConsList *empty = Empty consList : List c -> ConsList cconsList = \l -> l |> List.walkBackwards empty \state, elem -> cons elem state

(file.rc, from issue #6879 https://github.com/roc-lang/roc/issues/6879) Steps to Reproduce

  1. Run cargo clean
  2. Run cargo run file.rc (the Roc compiler will give an error, but it will not itself overflow)
  3. Run cargo clean
  4. Run ROC_PRINT_UNIFICATIONS=1 cargo run file.rc (the Roc compiler itself will overflow)
  5. Run cargo run file.rc (the Roc compiler will give an error, but it will not itself overflow)
  6. Run ROC_PRINT_UNIFICATIONS=1 cargo run file.rc (now the compiler will not overflow, unlike before, even though it does give an error)

— Reply to this email directly, view it on GitHub https://github.com/roc-lang/roc/issues/7375, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE6GL6T5BCIJSCW5UWQJDNL2FTPZ3AVCNFSM6AAAAABTUCF3SGVHI2DSMVQWIX3LMV43ASLTON2WKOZSG42DAMRTGE2TEMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ayazhafiz avatar Dec 15 '24 02:12 ayazhafiz