nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

Array outports indexing #29

Closed emil14 closed 1 year ago

emil14 commented 2 years ago

Case

For tasks like "subtract numbers from first to last" where:

  1. Arguments count unknown
  2. Order matters

We need a way to represent ordered variadic arguments

Problem

Imagine some component with an array-outport in a module's network. It's dangerous to refer specific indexes of that outport because we don't know how many indexes will be used inside that component.

Another case is when some module has an array-inport. It's dangerous to refer some specific indexes of that inport because we don't know how many indexes will be used by parent network.

But port reference assumes some index!

Actually these two cases are the same though we talking about outport in the first one and about inport in the second. This happens because for module's network - inport is actually an outport, the port to read from!


UPD: array ports are like variadic arguments / rest in Go/TS. We shouldn't use specific positions args[2] from ...args as well as we should't use results = returnList(); results[2]. By using only args/results as is we are safe. This is what bypass is!

emil14 commented 2 years ago

Array bypass solution

Just forbid array outport indexing and introduce new type of port reference / connection - "array bypass". It must be used when we want to connect some array-outport with some array-inport. Both part of the connection must be array-ports.

Problems

emil14 commented 2 years ago

Only array-inport indexing

Allow only referencing array element if its inport

Problem

  1. Probably not solves the routing problem
  2. It could be impossible or VERY hard to figure out incoming connections count (e.g Parent network could use bypass connection)
emil14 commented 2 years ago

Only allow if incoming connections count is known

Problems

emil14 commented 2 years ago

Don't implement array ports

Just use List

Problems

emil14 commented 2 years ago

Allow array outports

Just aware programmer that array-outports must be used with caution

Pros

Cons

emil14 commented 2 years ago

Strong type system

Introduce some complicated type system that will be able to figure out complex cases for even operators. Especially it must answer the question - how many port elements this operator will use?

emil14 commented 2 years ago

Only N:N

Allow arr-ports and outports to be only 1:1 inports to outports

Problem

TODO

emil14 commented 2 years ago

Check for holes only

If there is a[2] then there must be a[0] and a[1]. Because if there is a[3] then there is 0,1 elements that must be used because someone is must be sending values to those ports.

Problems

  1. Unread values - If there's n ports filled but only <n ports are used outside (could be solved in #54)
  2. Unfilled values - if there's <n ports filled but n ports used #55
emil14 commented 2 years ago

Make sure indexing errors are startup errors

Allow outports indexing but make sure any indexing errors will happen at startup of the program

TODO think how to implemnt

emil14 commented 2 years ago

Default/empty values

Always use all the outports but send some empty values to the ones that are not needed.

Example: p1, p2, p3 -> router -> r1, r2, r3, r4. There is no value for r4 but router will send some default value there

Problems