unisonweb / unison

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

`update` renders typecheckedunisonfile without leading `.` #5427

Open aryairani opened 4 weeks ago

aryairani commented 4 weeks ago

Describe and demonstrate the bug On this hash: @unison/knn-search-demo/main> ⊙ 1. #htonjt947k

do an update with this scratch file,

db : '{Exception, Cloud} Database
db = do Database.named "shakespeare-hnsw2"

initializeMemoryGraph :
  '{IO, Exception} ( mutable.Ref {IO} (Optional (Layer, Play, Text)),
    mutable.Ref
    {IO} (data.Map Layer (data.Map (Play, Text) (Set (Play, Text)))))
initializeMemoryGraph = do
  use Debug trace
  use IO ref
  ep = ref None
  edges = ref data.Map.empty
  List.foreach
    (p -> let
      trace "loading to memory" p
      nodes = Http.run do streamPlayHunk p
      trace "nodes" (List.size nodes)
      nodes |> populatePlayGraph3 (memoryHNSW ep edges)) plays
  (ep, edges)

saveGraph : '{IO, Exception} ()
saveGraph = do
  Debug.trace "Initializing memory graph" ()
  (ep, edges) = initializeMemoryGraph()
  Debug.trace "done." ()
  Cloud.run do
    use Database named
    use mutable.Ref read
    clearDatabase()
    db = .db()
    Database.assign db Environment.default()
    ep' = read ep
    edges' = read edges
    copyMemoryToHNSW2 db ep' edges' (buildPlayGraph db)

and we get this in the resulting scratch file, which uses the wrong identifier db for .db

saveGraph : '{IO, Exception} ()
saveGraph = do
  use Debug trace
  use mutable.Ref read
  trace "Initializing memory graph" ()
  let
    (ep, edges) = initializeMemoryGraph()
    trace "done." ()
    Cloud.run do
      clearDatabase()
      db = db()
      Database.assign db Environment.default()
      ep' = read ep
      edges' = read edges
      copyMemoryToHNSW2 db ep' edges' (buildPlayGraph db)

Screenshots

Environment (please complete the following information): release/0.5.27

Additional context