digego / extempore

A cyber-physical programming environment
1.41k stars 127 forks source link

Confusing compiler error when binding an anonymous function to a global variable with the wrong type. #310

Open cianoc opened 6 years ago

cianoc commented 6 years ago

When running the following code:

(bind-func my-closure
  (lambda (x:i64)
    (lambda (y) (+ x y))))

(bind-val f [i64*,i64*]* (myclosure 4))

($ (f 5)) ;; this triggers the error

I get the following message from the compiler:

Compiler Error  compiler failed
**** DECL ****
@f = external global { i8*, i8*, i64* (i8*, i8*, i64*)* }**
declare %mzone* @llvm_pop_zone_stack ()
declare void @llvm_zone_destroy (%mzone*)
declare i8* @malloc (i64)
declare i8* @memset (i8*, i32, i64)
declare i8* @strcpy (i8*, i8*)
declare %String* @toString_poly_W1N0cmluZyosaTY0Kl0q (i64*)
declare %String* @zcopy_adhoc_W1N0cmluZyosU3RyaW5nKixtem9uZSosbXpvbmUqXQ (%String*, %mzone*, %mzone*)
declare i8* @zcopy_poly_W2k4KixpOCosbXpvbmUqLG16b25lKl0q (i8*, %mzone*, %mzone*)
**** ENDDECL ****

LLVM IR: <string>:150:32: error: '%f1071' defined with type 'i64* (i8*, i8*, i64*)*'
%result1076 = call fastcc i64* %f1071(i8* %z1075, i8* %e1072, i64 5)
                               ^
digego commented 6 years ago

I agree that we need a better error message here, but the error itself is not incorrect/inconsistent.

I think what you meant was

(bind-val f [i64,i64]* (myclosure 4))

Which functions correctly.

Maybe change this issue to reflect the compilers poor error reporting of this condition.

From: cianoc Sent: Saturday, 6 January 2018 2:51 PM To: digego/extempore Cc: Subscribed Subject: [digego/extempore] Compiler error when defining an anonymous closure(#310)

When running the following code: (bind-func my-closure (lambda (x:i64) (lambda (y) (+ x y))))

(bind-val f [i64,i64]* (myclosure 4))

($ (f 5)) ;; this triggers the error I get the following message from the compiler: Compiler Error compiler failed DECL @f = external global { i8, i8, i64 (i8, i8, i64)* } declare %mzone @llvm_pop_zone_stack () declare void @llvm_zone_destroy (%mzone) declare i8 @malloc (i64) declare i8 @memset (i8, i32, i64) declare i8 @strcpy (i8, i8) declare %String @toString_poly_W1N0cmluZyosaTY0Kl0q (i64) declare %String @zcopy_adhoc_W1N0cmluZyosU3RyaW5nKixtem9uZSosbXpvbmUqXQ (%String, %mzone, %mzone) declare i8 @zcopy_poly_W2k4KixpOCosbXpvbmUqLG16b25lKl0q (i8, %mzone, %mzone) ** ENDDECL ****

LLVM IR: :150:32: error: '%f1071' defined with type 'i64 (i8, i8, i64)' %result1076 = call fastcc i64 %f1071(i8 %z1075, i8 %e1072, i64 5) ^ — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

cianoc commented 6 years ago

I think the error message should say something like f was expected a type of X, but instead got a type of Y.