mratsim / weave

A state-of-the-art multithreading runtime: message-passing based, fast, scalable, ultra-low overhead
Other
532 stars 22 forks source link

Prevent copying of Flowvar and Pending results #152

Open mratsim opened 4 years ago

mratsim commented 4 years ago

Some assumptions of Weave is that there is a single consumer of a future result (Flowvar or Pending) and that it tried to consume that result only once.

While we can't prevent the latter at compile-time, we can prevent the first by only allowing the sink/move operation on the type and making copies a compile-time error:

type
  Flowvar[T] = object

proc `=`[T](dst: var Flowvar[T], src: Flowvar[T]) {.error: "copying not allowed".}

proc newFlowvar(T: typedesc): Flowvar[T] =
  discard

let x = newFlowvar(int)

However we get unresolved generic parameter at the moment due to upstream bug https://github.com/nim-lang/Nim/issues/14315