So far, I have coded the following:

  * A simple "string-in-shared-heap" module (I know there is something like 
that already in the standard lib, mine caches the hashcode).
  * A seq-in-shared-heap module.
  * A Table-in-shared-heap (I know there is something like that already in the 
standard lib, but mine is on purpose NOT thread-safe).
  * A thread-safe "register", that maps a key both to a value and a unique ID 
on the shared heap, using the above "seq" and "Table".
  * A register for "types", built on the above "register". It uses the 
"string-in-shared-heap" as "key".
  * A module that exports a few "atomics" method (load, store, exchange, cas), 
that it works on pthreads AND Windows.
  * Concurrent message-queues on the shared heap, using all of the above.



All of this seems to work (except the message-queues), at least in the "inline" 
tests writen with "when isMainModule: ..."

My issue is, that when I use the "type register" in the message-queues, 
suddenly the "shared heap table" cannot find the hash function of the "shared 
heap string". The code in the message queues calls the same procs as the test 
code in the "type register", so I see no reason why the hash() proc could not 
be found.

The whole code is rather large now, mostly due to containing a clone of 
"tables.nim", so I don't want to post it here, but I'll create some github 
repo(s) for it, once it has been cleaned up. I'm only posting the (simplified) 
"string-in-heap" module for now, to show how the hash() proc is defined.

Do I need to do anything more, so that a module that receives the SharedText as 
generic parameter can find the hash(SharedText) proc?
    
    
    import hashes
    
    type
      SharedText* = object
        txt*: cstring
        txthash*: Hash
        txtlen*: int
    
    proc hash*(st: SharedText): Hash {.inline, noSideEffect.} =
      result = st.txthash
    
    proc len*(st: SharedText): int {.inline, noSideEffect.} =
      result = st.txtlen
    
    proc `$`*(st: SharedText): string {.inline.} =
      result = $st.txt
    
    proc `==`*(a, b: SharedText): bool {.inline, noSideEffect.} =
      (a.txthash == b.txthash) and (a.len == b.len) and (cmp(a.txt, b.txt) == 0)
    
    proc initSharedText*(s: cstring): SharedText {.inline, noSideEffect.} =
      result.txt = s
      result.txtlen = len(s)
      result.txthash = hash(s)
    

And the compiler error message looks something like:
    
    
    # ...
    mysharedtable.nim(153, 12) Error: type mismatch: got (SharedText)
    but expected one of:
    proc hash(sBuf: string; sPos, ePos: int): Hash
    proc hash(x: uint64): Hash
    # ...
    

Reply via email to