Skip to content

Slow compilation times for type-level Nat #3696

@joelberkeley

Description

@joelberkeley

Steps to Reproduce

data Bar : Nat -> Type where
  B : Unit -> Bar n

Bars : Type
Bars = (
      (Bar 4, Bar 120)
    , (Bar 120, Bar 84)
    , (Bar 84, Bar 2)
  )

bar : (a, b, c, d, e : Unit) -> Unit

foo : Bars -> Unit
foo ((B a, B b), (B c, B d), (B e, B f)) =  id $ bar a b c d e

Expected Behavior

Reasonable compilation times

Observed Behavior

time idris2 --build tinker.ipkg 
1/1: Building Main (src/Main.idr)
Now compiling the executable: tinker

real  2m3.780s
user  2m3.028s
sys   0m0.649s

Notes

I assume the problem is that Idris is manipulating large inductive Nats in a nested type, but I can't help but wonder if there's a principled way to avoid this in the compiler, since it compiles almost instantly if I parametrize over the Nat and only apply 120, 84 at a higher level.

Bars : (m, n : Nat) -> Type
Bars m n = (
      (Bar 4, Bar m)
    , (Bar m, Bar n)
    , (Bar n, Bar 2)
  )

foo : (m, n : Nat) -> Bars m n -> Unit
foo _ _ ((B a, B b), (B c, B d), (B e, B f)) =  id $ bar a b c d e

main : IO ()
main = do
  let _ = foo 120 84 ((B (), B ()), (B (), B ()), (B (), B ()))
  pure ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions