Ooh, I hadn't considered that the return of a complex proc could be isolated. 
That does indeed help matters. I modified your initial example to use a proc 
which generates a JSON object given a number and a string and it worked fine. 
But for my example it still doesn't work. Looking at the list of requirements 
to be "isolate"-able it seems like it's because the `Test` branches in my 
`Tree` type would be able to alias the `Test` that is input. But it seems like 
it's even stricter than this. Consider this example:
    
    
    import std / [json, isolation]
    import threading / channels
    
    type
      Test = ref object
        data: string
      Branch = ref object
        data: string
      Tree = ref object
        left, right: Branch
    
    var chan = newChan[Tree]()
    var thr: Thread[void]
    
    proc worker() {.thread.} =
      var x: Tree
      chan.recv(x) # somebody should fix this API...
      echo "received ", x.left.data, " ", x.right.data
    
    proc createTree(hello: Test): Tree =
      echo hello.data
      Tree(left: Branch(data: "Hello"), right: Branch(data: "world"))
    
    createThread thr, worker
    let hello = Test(data: "Hello")
    chan.send isolate(createTree(hello))
    joinThread thr
    
    
    Run

It fails to be able to isolate the result of `createTree` even though there is 
nothing in `Tree` which can alias the `Test` type passed in. In fact the `Test` 
type passed in doesn't have anything to do with how the object is generated at 
all. I am however able to pass in a `string` and store that as the `data` field 
in one of my `Branch` objects, so I'm not entirely sure why it doesn't allow me 
to pass in this `Test` object. Am I missing something here? It would be nice if 
we could name or number the isolation rules and tell you which one is broken 
instead of just saying "expression cannot be isolated".

Reply via email to