vvvv / VL-Language

The official repo for the design of the VL programming language
31 stars 0 forks source link

[Proposal] Control lifetime of state per region #47

Open azeno opened 3 years ago

azeno commented 3 years ago

Addressing quest #44

This proposal is not yet completely finished. Consider it WIP!

Summary

This proposal introduces three lifetimes which can be applied on a region level. They define how long a process inside of such a region is alive.

The three lifetimes are

Visualization

In order to reason about a patch we need to be able to see what lifetime currently applies.

Implications

The language gets simplified drastically.

Implementation

OnStack

using var myState = new MyState();
// ...

ByParent

object state = default;
() =>
{
  var myState = state as MyState ?? new MyState(...);
  state = myState;
}

BySink

The state needs to be passed explicitly through a object stateInput and out object StateOutput parameters on a delegate. The system generated delegates will recognize that parameter and initialize it accordingly:

(stateInput, ..., out stateOutput) =>
{
  var myState = stateInput as MyState ?? new MyState(...);
  // ...
  stateOutput = myState;
}

The pseudo code for a sink would be:

// OnCreate
this.state = null;
// OnUpdate
function.Invoke(state, ..., out state)
this.state = state;
// OnDispse
(this.state as IDisposable)?.Dispose()