unisonweb / base_v1

Unison base libraries, published using V1 codebase format
24 stars 14 forks source link

Recursive generators crash with a bug #39

Closed runarorama closed 4 years ago

runarorama commented 4 years ago

Using the following test

test.optional : '{Gen} a -> '{Gen} Optional a
test.optional gen =
  'let
    b = !test.boolean
    if b then None else Some !gen

test.boolean =
  '(Gen.sample (Weighted.fromList [false, true]))

test> Trie.union.tests.keys = runs 2 'let
  t1 = !(Trie.gen nat nat)
  t2 = !(Trie.gen nat nat)
  t2vs = Trie.values t2
  uvs = Trie.values (Trie.union t1 t2)
  expect (List.all (v -> uvs `List.contains` v) t2vs)

Trie.gen : '{Gen} k ->{} '{Gen} v ->{} '{Gen} (Trie k v)
Trie.gen k v = 'let
  h = !(optional v)
  g = Trie.gen k v
  t = !(mapOf k g)
  Trie h t

Results in this crash:

 💔💥

  I stopped evaluation after encountering an unhandled request:

    Gen.sample
      let
        use Nat + drop
        use Weighted Fail
        ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o3
          m n =
          match (m, n) with
            (Fail, n)                 -> n
            (Yield x m, n)            ->
              Yield
                x
                (ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                  m n)
            (Weight w m, Fail)        -> Weight w m
            (Weight w m, Yield x n)   ->
              Yield
                x
                (ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                  (Weight w m) n)
            (Weight w m, Weight w' n) ->
              if w < w' then
                Weight
                  w
                  '(ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                    !m (Weight (drop w' w) n))
              else
                if w == w' then
                  Weight
                    w
                    '(ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                      !m !n)
                else
                  Weight
                    w
                    '(ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                      (Weight (drop w w') m) !n)
        go8 =
          (go
          ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
          ℍ#e2dsohsu6ra6kgimsi1i32lln9s7e4vc4ua66afag9k8o9vm0omv28ilolsvlju5o5ioq0bm9vfu2o92akk2ddkrekmpk1vudl3vak8
          ℍ#tbb39c2i34bkepv8r43il0auhnbao55ftft9d18c5fq31f0gk6utf7v6ghnt76h8r8l1eesrsgsac4b0klqpoktofq6m7p2esck5id0
          n ->
            ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
              (ℍ#tbb39c2i34bkepv8r43il0auhnbao55ftft9d18c5fq31f0gk6utf7v6ghnt76h8r8l1eesrsgsac4b0klqpoktofq6m7p2esck5id0
                n)
              (ℍ#e2dsohsu6ra6kgimsi1i32lln9s7e4vc4ua66afag9k8o9vm0omv28ilolsvlju5o5ioq0bm9vfu2o92akk2ddkrekmpk1vudl3vak8
                1 '(go (n + 1))))
            go
            ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
            (w ws -> Weight w ws)
            (a -> Yield a Fail)
        Yield
          0
          (Weight
            1
            ((go n -> '(go (n + 1)))
              ((go
              ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
              ℍ#e2dsohsu6ra6kgimsi1i32lln9s7e4vc4ua66afag9k8o9vm0omv28ilolsvlju5o5ioq0bm9vfu2o92akk2ddkrekmpk1vudl3vak8
              ℍ#tbb39c2i34bkepv8r43il0auhnbao55ftft9d18c5fq31f0gk6utf7v6ghnt76h8r8l1eesrsgsac4b0klqpoktofq6m7p2esck5id0
              n ->
                ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                  (ℍ#tbb39c2i34bkepv8r43il0auhnbao55ftft9d18c5fq31f0gk6utf7v6ghnt76h8r8l1eesrsgsac4b0klqpoktofq6m7p2esck5id0
                    n)
                  (ℍ#e2dsohsu6ra6kgimsi1i32lln9s7e4vc4ua66afag9k8o9vm0omv28ilolsvlju5o5ioq0bm9vfu2o92akk2ddkrekmpk1vudl3vak8
                    1 '(go (n + 1))))
                ((go
                ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                ℍ#e2dsohsu6ra6kgimsi1i32lln9s7e4vc4ua66afag9k8o9vm0omv28ilolsvlju5o5ioq0bm9vfu2o92akk2ddkrekmpk1vudl3vak8
                ℍ#tbb39c2i34bkepv8r43il0auhnbao55ftft9d18c5fq31f0gk6utf7v6ghnt76h8r8l1eesrsgsac4b0klqpoktofq6m7p2esck5id0
                n ->
                  ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                    (ℍ#tbb39c2i34bkepv8r43il0auhnbao55ftft9d18c5fq31f0gk6utf7v6ghnt76h8r8l1eesrsgsac4b0klqpoktofq6m7p2esck5id0
                      n)
                    (ℍ#e2dsohsu6ra6kgimsi1i32lln9s7e4vc4ua66afag9k8o9vm0omv28ilolsvlju5o5ioq0bm9vfu2o92akk2ddkrekmpk1vudl3vak8
                      1 '(go (n + 1))))
                  go
                  ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                  (w ws -> Weight w ws)
                  (a -> Yield a Fail))
                (m n ->
                  (match (m, n) with
                    (Fail, n)                 -> n
                    (Yield x m, n)            ->
                      Yield
                        x
                        (ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                          m n)
                    (Weight w m, Fail)        -> Weight w m
                    (Weight w m, Yield x n)   ->
                      Yield
                        x
                        (ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                          (Weight w m) n)
                    (Weight w m, Weight w' n) ->
                      if w < w' then
                        Weight
                          w
                          '(ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                            !m (Weight (drop w' w) n))
                      else
                        if w == w' then
                          Weight
                            w
                            '(ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                              !m !n)
                        else
                          Weight
                            w
                            '(ℍ#b3tl0p6em4l1l9flulpe7mksfe4egpbp84rfh4iacfriqp01k3p617tr4h32s4i1s9pkd6jgp02vlhtatb6rrgeha2b6j5rbptk3r7o
                              (Weight (drop w w') m) !n)))
                (w ws -> Weight w ws)
                (a -> Yield a Fail))
              0))

  This happens when using a handler that doesn't handle all possible requests.

  I'm sorry this message doesn't have more detail about the location of the
  failure. My makers plan to fix this in a future release. 😢
runarorama commented 4 years ago

This appears to be fixed.