Carp icon indicating copy to clipboard operation
Carp copied to clipboard

The `c` command should handle generic dependencies gracefully

Open eriksvedang opened this issue 4 years ago • 5 comments

Somewhat related to https://github.com/carp-lang/Carp/issues/1347#issuecomment-1003168056, the c command (defined in Eval.hs, function commandC on line 975) spits out a lot of errors if a definition generates generic functions as dependencies.

Example:

鲤 (defn f [] (fn [x] x))
鲤 (c f)

I found an unresolved generic type `(Fn [t2] t2 t4)` for the expression `(defn <> _Lambda_f_7_env__?_? [x] x)` at line 2, column 12 in 'REPL', can't print resulting code.
I found an unresolved generic type `(Fn [t2] t2 t4)` for the expression `(defn <> _Lambda_f_7_env__?_? [x] x)` at line 2, column 12 in 'REPL', can't print resulting code.
I found an unresolved generic type `(Fn [(Fn [t2] t2 t4)] ())` for the expression `(instantiate Function.delete__?_?)` at unknown line, unknown column in 'Function.delete__?_? template', can't print resulting code.
I found an unresolved generic type `(Fn [] (Fn [a] a b))` for the expression `(defn f [] (fn <> [x] x))` at line 2, column 2 in 'REPL', can't print resulting code.

A better behaviour would be to simply not try print generic dependencies.

eriksvedang avatar Jan 09 '22 14:01 eriksvedang

I can add this to #1373 or open a new PR with this functionality.

hellerve avatar Jan 09 '22 19:01 hellerve

I played around with this a bit. The offending function is this one:

https://github.com/carp-lang/Carp/blob/330dc52308c157c9c833b157cf0eb29dd9ca8327/src/Eval.hs#L1005-L1011

It’s clearly part of it’s intended behavior to show these errors. We can instead ignore those errors and just not print anything, of course, but that might mean that we swallow too much; what do you think?

hellerve avatar Jan 10 '22 09:01 hellerve

I think this function should only be called for the function passed to c, for the dependencies we can check if it's generic and only print if not. Makes sense?

eriksvedang avatar Jan 10 '22 09:01 eriksvedang

Somewhat, but it’s important to note that C works with arbitrary forms:

> (defdynamic x '(Int.+ 1 1))
> (c x)
int _3 = Int__PLUS_(1, 1);

hellerve avatar Jan 10 '22 10:01 hellerve

Sure, whatever is passed to c should still have the warning, but generic deps should be filtered out.

eriksvedang avatar Jan 10 '22 10:01 eriksvedang