nevalang / neva

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

Implicit `any` in node expressions causes problems #761

Open emil14 opened 1 week ago

emil14 commented 1 week ago

Problem

Let's first look at this Main component and specifically on how For is used

def Main(start any) (stop any) {
    For{Next2Lines}, Wait
    ---
    :start -> 99..-1 -> for -> wait -> :stop
}

As we can see it used without type-arguments even though it has one type-parameter

pub def For<T>(data stream<T>) (res stream<T>) {
    ...
    handler IForEachHandler<T>
    lock1 Lock<stream<T>>
    ...
    ---
    ...
    lock1 -> handler // FIXME compiler must not allow this connection
    ...
}

pub interface IForEachHandler<T>(data T) (sig any)

This is because compiler allows this and implicitly uses any as a default type-argument. This is however lead to a non-obvious bug that lock1 -> handler connection is allowed even though T and stream<T> cannot be same thing... Right? Well, turns out they can if T is any!

stream<any> :> any

Proposal

Get rid of this feature and enforce explicit type-arguments. Implicit any is basically type inference of smoker. Unless we heave real type-inference we must not make assumptions