unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

`knn-search-demo` doesn't round-trip #5436

Open aryairani opened 3 weeks ago

aryairani commented 3 weeks ago

Describe and demonstrate the bug

...> clone @aryairani/knn-search-demo/_5436
...> edit.namespace

First there's a round-trip error for this test:

test> hnsw.test.searchLayerTest = Stopwatch.ignore do
  Log.ignore do
    test.verify do
      test.ensureEqual
        let
          o = on Universal.ordering at2
          query = 6.125
          distance = test.distance query
          epList = Nat.range 1 10 |> List.map Float.fromNat
          add : Float -> heap.Heap (Float, Distance) -> heap.Heap (Float, Distance)
          add p = heap.Heap.insert o (p, distance p)
          h = List.foldLeft (flip add) Heap.empty epList
          searchLayer distance neighbors h 4 |> KMin.toList
        [(8.0, Distance 1.875), (5.0, Distance 1.125), (7.0, Distance 0.875), (6.0, Distance 0.125)]

In the current rendering, the last line is part of the second-to-last line, which doesn't typecheck. The let and the list are meant to be separate arguments to test.ensureEqual. When the last two lines are combined, it appears to be an argument to KMin.toList, which is a type error.

After correcting that, 24 definitions are slurped as "changed" when they shouldn't have changed with an edit.namespace:

@unison/knn-search-demo/main> 

  Loading changes detected in ~/work/knns/bpq.u.

  I found and typechecked these definitions in ~/work/knns/bpq.u. If you do an
  `add` or `update`, here's how your codebase would change:

    ⊡ Previously added definitions will be ignored: Fragment README ReadTfIdf
      ReadTfIdf.compareG ReadTfIdf.compareG.modify ReadTfIdf.compareG.set
      ReadTfIdf.getCorpusSize ... 224 more. Try moving these below the `---`
      "fold" in your file.

    ⍟ These names already exist. You can `update` them to your new definition:

      deploy                         : '{IO, Exception} URI
      hnsw.HNSW.fromList             : HNSW {h} node
                                       -> (node ->{g} node ->{g} Distance)
                                       -> [node]
                                       ->{g, h, Random, Log, Stopwatch} ()
      hnsw.HNSW.insert               : HNSW {h} node
                                       -> (node ->{g} node ->{g} Distance)
                                       -> node
                                       ->{g, h, Random, Log, Stopwatch} ()
      hnsw.knnSearch                 : HNSW {h} node
                                       -> (query ->{g} node ->{g} Distance)
                                       -> query
                                       -> Nat
                                       -> Nat
                                       ->{g, h, Remote, Log, Stopwatch} KMin
                                         node Distance
      hnsw.searchLayer               : (node ->{g} Distance)
                                       -> (node ->{g} [node])
                                       -> heap.Heap (node, Distance)
                                       -> Nat
                                       ->{g, Log, Stopwatch} KMin
                                         node Distance
      hnsw.test.searchLayerTest      : [Result]
      hnsw.test.searchLayerTest2     : [Result]
      hnsw.test.setupSearchLayerTest : (a ->{g} a ->{g} Distance)
                                       -> (a ->{g} [a])
                                       -> [a]
                                       -> Nat
                                       -> a
                                       ->{g, Log, Stopwatch} [(a, Distance)]
      hnsw.util.data.KMax.empty      : Nat -> (b -> b -> Ordering) -> KMax a b
      hnsw.util.data.KMax.fromList   : Nat
                                       -> (b -> b -> Ordering)
                                       -> [(a, b)]
                                       -> KMax a b
      hnsw.util.data.KMax.singleton  : Nat
                                       -> (b -> b -> Ordering)
                                       -> value
                                       -> b
                                       -> KMax value b
      hnsw.util.data.KMax.test       : [Result]
      hnsw.util.data.KMin.empty      : Nat -> (b -> b -> Ordering) -> KMin a b
      hnsw.util.data.KMin.fromList   : Nat
                                       -> (b -> b -> Ordering)
                                       -> [(a, b)]
                                       -> KMin a b
      hnsw.util.data.KMin.singleton  : Nat
                                       -> (b -> b -> Ordering)
                                       -> value
                                       -> b
                                       -> KMin value b
      hnsw.util.data.KMin.test       : [Result]
      initializeMemoryGraph          : ReadTfIdf
                                         {g} (Play, Fragment) (Play, Fragment)
                                       ->{g, IO, Exception, Log, Stopwatch} ( mutable.Ref
                                         {IO}
                                         (Optional (Layer, Play, Fragment)),
                                         mutable.Ref
                                         {IO}
                                         (data.Map
                                           Layer
                                           (data.Map
                                             (Play, Fragment)
                                             (Set (Play, Fragment)))))
      performSearch                  : Database
                                       -> HNSW {Transaction} (Play, Fragment)
                                       -> ReadTfIdf
                                         {Remote} Text (Play, Fragment)
                                       -> '{Route, Remote, Log, Stopwatch} ()
      populatePlayGraph3             : HNSW {g} node
                                       -> ReadTfIdf {h} node node
                                       -> [node]
                                       ->{g, h, Log, Stopwatch} ()
      saveGraph                      : '{IO, Exception} ()
      server                         : Database
                                       -> HNSW {Transaction} (Play, Fragment)
                                       -> ReadTfIdf
                                         {Remote} Text (Play, Fragment)
                                       -> HttpRequest
                                       ->{Exception, Http, Remote, Log} HttpResponse
      styles                         : Text
      toHtml                         : Html
      toHtmlDocument                 : Text

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here.