koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.29k stars 165 forks source link

open type codegen bug (c target) #198

Open codehz opened 3 years ago

codehz commented 3 years ago

minimal example:

open type bug

extend type bug
  A

extend type bug
  B(: int)

fun test-bug(v: bug)
  match v
    A -> 0
    B(i) -> i
result ``` In file included from .koka/v2.3.1/clang-cl-debug/open.c:2: .koka/v2.3.1/clang-cl-debug/open.h(70,28): error: redefinition of 'kk_open__bug_dup' static inline kk_open__bug kk_open__bug_dup(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(17,28): note: previous definition is here static inline kk_open__bug kk_open__bug_dup(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(73,20): error: redefinition of 'kk_open__bug_drop' static inline void kk_open__bug_drop(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(20,20): note: previous definition is here static inline void kk_open__bug_drop(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(76,20): error: redefinition of 'kk_open__bug_is_unique' static inline bool kk_open__bug_is_unique(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(23,20): note: previous definition is here static inline bool kk_open__bug_is_unique(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(79,20): error: redefinition of 'kk_open__bug_free' static inline void kk_open__bug_free(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(26,20): note: previous definition is here static inline void kk_open__bug_free(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(82,20): error: redefinition of 'kk_open__bug_decref' static inline void kk_open__bug_decref(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(29,20): note: previous definition is here static inline void kk_open__bug_decref(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(85,26): error: redefinition of 'kk_open__bug_dropn_reuse' static inline kk_reuse_t kk_open__bug_dropn_reuse(kk_open__bug _x, kk_ssize_t _scan_fsize, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(32,26): note: previous definition is here static inline kk_reuse_t kk_open__bug_dropn_reuse(kk_open__bug _x, kk_ssize_t _scan_fsize, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(88,20): error: redefinition of 'kk_open__bug_dropn' static inline void kk_open__bug_dropn(kk_open__bug _x, kk_ssize_t _scan_fsize, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(35,20): note: previous definition is here static inline void kk_open__bug_dropn(kk_open__bug _x, kk_ssize_t _scan_fsize, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(91,26): error: redefinition of 'kk_open__bug_reuse' static inline kk_reuse_t kk_open__bug_reuse(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(38,26): note: previous definition is here static inline kk_reuse_t kk_open__bug_reuse(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(94,28): error: redefinition of 'kk_open__bug_hole' static inline kk_open__bug kk_open__bug_hole() { ^ .koka/v2.3.1/clang-cl-debug/open.h(41,28): note: previous definition is here static inline kk_open__bug kk_open__bug_hole() { ^ .koka/v2.3.1/clang-cl-debug/open.h(97,24): error: redefinition of 'kk_open__bug_box' static inline kk_box_t kk_open__bug_box(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(44,24): note: previous definition is here static inline kk_box_t kk_open__bug_box(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(100,28): error: redefinition of 'kk_open__bug_unbox' static inline kk_open__bug kk_open__bug_unbox(kk_box_t _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(47,28): note: previous definition is here static inline kk_open__bug kk_open__bug_unbox(kk_box_t _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.c(9,5): error: call to 'kk_open__bug_dropn' is ambiguous kk_open__bug_dropn(v, ((int32_t)KI32(0)), _ctx); ^~~~~~~~~~~~~~~~~~ .koka/v2.3.1/clang-cl-debug/open.h(88,20): note: candidate function static inline void kk_open__bug_dropn(kk_open__bug _x, kk_ssize_t _scan_fsize, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(143,20): note: candidate function static inline void kk_open__bug_dropn(kk_open__bug _x, kk_ssize_t _scan_fsize, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.c(15,19): error: call to 'kk_open__bug_is_unique' is ambiguous if (kk_likely(kk_open__bug_is_unique(v))) { ^~~~~~~~~~~~~~~~~~~~~~ C:/Users/***/AppData/Local/koka/share/koka/v2.3.1/kklib/include/kklib/platform.h(157,29): note: expanded from macro 'kk_likely' #define kk_likely(x) (x) ^ .koka/v2.3.1/clang-cl-debug/open.h(76,20): note: candidate function static inline bool kk_open__bug_is_unique(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(131,20): note: candidate function static inline bool kk_open__bug_is_unique(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.c(16,7): error: call to 'kk_open__bug_free' is ambiguous kk_open__bug_free(v); ^~~~~~~~~~~~~~~~~ .koka/v2.3.1/clang-cl-debug/open.h(79,20): note: candidate function static inline void kk_open__bug_free(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.h(134,20): note: candidate function static inline void kk_open__bug_free(kk_open__bug _x) { ^ .koka/v2.3.1/clang-cl-debug/open.c(20,7): error: call to 'kk_open__bug_decref' is ambiguous kk_open__bug_decref(v, _ctx); ^~~~~~~~~~~~~~~~~~~ .koka/v2.3.1/clang-cl-debug/open.h(82,20): note: candidate function static inline void kk_open__bug_decref(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(137,20): note: candidate function static inline void kk_open__bug_decref(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.c(25,5): error: call to 'kk_open__bug_drop' is ambiguous kk_open__bug_drop(v, _ctx); ^~~~~~~~~~~~~~~~~ .koka/v2.3.1/clang-cl-debug/open.h(73,20): note: candidate function static inline void kk_open__bug_drop(kk_open__bug _x, kk_context_t* _ctx) { ^ .koka/v2.3.1/clang-cl-debug/open.h(128,20): note: candidate function static inline void kk_open__bug_drop(kk_open__bug _x, kk_context_t* _ctx) { ^ 16 errors generated. ```
daanx commented 3 years ago

yikes -- thanks for the report I think I know how to fix it. (for now, putting extensions in separate modules will probably work)

codehz commented 3 years ago

@daanx Another example, there only one extend type, but use types from core:

extend type exception-info
  ExnWhatever

got similar error as well

TimWhiting commented 9 months ago

This should be fixed now. I'll close the issue. Please reopen, or create a new issue if you find further bugs.

jasigal commented 5 months ago

This seems to be back in 3.1.1 (libc x64 (gcc)) unfortunately:

module exception-bug

extend type exception-info
  ExnMyCon

produces

In file included from /usr/local/share/koka/v3.1.1/kklib/include/kklib.h:1371,
                 from .koka/v3.1.1-ubuntu/gcc-debug-190b89/exception_dash_bug.h:5,
                 from .koka/v3.1.1-ubuntu/gcc-debug-190b89/exception_dash_bug.c:2:
.koka/v3.1.1-ubuntu/gcc-debug-190b89/exception_dash_bug.c:3:35: error: static declaration of ‘kk_exception_dash_bug__tag_ExnMyCon’ follows non-static declaration
    3 | kk_declare_string_literal(static, kk_exception_dash_bug__tag_ExnMyCon, 22, "exception-bug/ExnMyCon")
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/share/koka/v3.1.1/kklib/include/kklib/string.h:132:20: note: in definition of macro ‘kk_declare_string_literal’
  132 |   decl kk_string_t name = { { kk_datatype_null_init } };
      |                    ^~~~
.koka/v3.1.1-ubuntu/gcc-debug-190b89/exception_dash_bug.h:35:20: note: previous declaration of ‘kk_exception_dash_bug__tag_ExnMyCon’ with type ‘kk_string_t’ {aka ‘struct kk_string_s’}
   35 | extern kk_string_t kk_exception_dash_bug__tag_ExnMyCon;
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^
exception-bug(1, 1): build error: user error (error  : command failed (exit code 1)
command: /usr/bin/gcc -Wall -Wextra -Wpointer-arith -Wshadow -Wstrict-aliasing -Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-variable -Wno-unused-value -Wno-unused-but-set-variable -g -Og -c -I /usr/local/share/koka/v3.1.1/kklib/include -DKK_MIMALLOC=8 -o .koka/v3.1.1-ubuntu/gcc-debug-190b89/exception_dash_bug.o .koka/v3.1.1-ubuntu/gcc-debug-190b89/exception_dash_bug.c)
TimWhiting commented 5 months ago

This is a different issue actually.

Add pub to your definition.

module exception-bug

pub extend type exception-info
  ExnMyCon

Of course we still need to fix the error message or fix the code generation in this case.