cbaggers / varjo

Lisp to GLSL Language Translator
BSD 2-Clause "Simplified" License
223 stars 23 forks source link

Incorrect error message on code with (apaprently) no errors #197

Closed psilord closed 6 years ago

psilord commented 6 years ago

Hello,

The intention of this code is to select a function and bind it to a symbol.

The shader code:

  (let ((easing-func
          (cond
            ((= easing-func-id 0)
             #'umbra.easing:bounce-in)
            ((= easing-func-id 1)
             #'umbra.easing:bounce-out)
            (t
             #'umbra.easing:bounce-in))))

     (some-other-func easing-func 1 2 3 4 5)

    .....)
results in:
    Varjo: Found an invalid attempt to make a local variable EASING-FUNC with the
type (OR (FUNCTION (FLOAT) FLOAT)
         (OR (FUNCTION (FLOAT) FLOAT) (FUNCTION (FLOAT) FLOAT)))

This usually happens due to the use of a conditions (like an 'if') where the
different branches of the conditional have different types. Due to this CEPL
can't infer a single valid type for this form and this is triggering this
issue.
[Condition of type VARJO-CONDITIONS:LET-OR]

Thank you!

cbaggers commented 6 years ago

Ah ok, so the error message is a bit bad here. The problem is that varjo needs to be able to resolve function calls statically and there is no way to know the value of easing-func until runtime. Of course if we had constant propagation there would be resolvable in more cases, however this would still apply sometimes.

cbaggers commented 6 years ago

I'll close this once I've made a better error for this case

psilord commented 6 years ago

What I really need, though is the ability to have an array of higher order functions and then index it in the shader. Is this concept possible in Varjo? Thank you!

cbaggers commented 6 years ago

Nope, the only way would involve passing around an identifier (e.g. an int) and having a switch at every call site. This would work but would have non-obvious implications on performance (think divergence) which would require folks to always debug against the glsl (as it would be too hard to predict the resulting code)

It's a bummer though as otherwise it would be a dope feature :D

cbaggers commented 6 years ago

Pushed a better error message for the cases when the all the branches of the or type are functions