jank icon indicating copy to clipboard operation
jank copied to clipboard

Running a raw cpp form after fixing the error in it

Open shantanu-sardesai opened this issue 4 months ago • 3 comments

jank health check

○ jank check-health                                                                                               □ jank/compiler+runtime △⎪●◦◌◦◃◈⎥via △ v4.0.3  15:46
─ system ───────────────────────────────────────────────────────────────────────────────────────────
─ ✅ operating system: macos
─ ✅ default triple: arm64-apple-darwin23.4.0

─ jank install ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank version: jank-0.1-67c06d9d7ad8582d94de258d0a4dce46332bf737
─ ✅ jank assertions are enabled; performance will be impacted
─ ✅ jank resource dir: ../lib/jank/0.1  (not found)
─ ✅ jank resolved resource dir: /Users/shantanusardesai/Desktop/code/projects/jank/compiler+runtime/build/../lib/jank/0.1  (ignored for dev build)
─ ✅ jank user cache dir: /Users/shantanusardesai/.cache/jank/arm64-apple-darwin23.4.0-c7b867340f14b40e3a001dc29ec887c0e4a02cebbb645862d8ebf5114714dd39  (not found)
─ ✅ jank pch path: /Users/shantanusardesai/.cache/jank/arm64-apple-darwin23.4.0-c7b867340f14b40e3a001dc29ec887c0e4a02cebbb645862d8ebf5114714dd39 (found)

─ clang install ────────────────────────────────────────────────────────────────────────────────────
─ ✅ configured clang path: /opt/homebrew/opt/llvm@22/bin/clang++ (found)
─ ✅ configured clang resource dir: /opt/homebrew/Cellar/llvm/22.0.0/lib/clang/22 (found)

─ jank runtime ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank runtime initialized
─ ✅ jank can jit compile c++
─ ✅ jank can jit compile llvm ir

Description of the issue with reproduction steps

I originally added a raw form without a ; in it, which as expected didn't compile but when I immediately afterwards entered the exact same form with the missing ; the REPL crashed.

user => (cpp/raw "std::vector<int> list{1, 2, 3, 4, 5}")        ; input_line_2:1:37: error: expected ';' after top level declarator. <omitted stack trace>
user => (cpp/raw "std::vector<int> list{1, 2, 3, 4, 5};")       ; Crash!

Pasting the message printed after the crash for completeness:

JIT session error: Symbols not found: [ __ZNSt3__117__libcpp_allocateB8ne220000IiEEPT_NS_15__element_countEm, __ZNSt3__119__libcpp_deallocateB8ne220000IiEEvPNS_15__type_identityIT_E4typeENS_15__element_countEm, __ZNSt3__120__throw_length_errorB8ne220000EPKc ]                                                                           Failure value returned from cantFail wrapped call                                                                                                                      Failed to materialize symbols: { (main, { __ZNSt3__16vectorIiNS_9allocatorIiEEED1B8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEED2B8ne220000Ev, _user_cpp_raw_9_0, __ZNSt3__119__unwrap_range_implIPKiS2_E8__unwrapB8ne220000ES2_S2_, __ZNSt3__116reverse_iteratorIPiEppB8ne220000Ev, __ZNSt3__116__non_trivial_ifILb1ENS_9allocatorIiEEEC2B8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEEC1B8ne220000ES5_, __ZNKSt3__16vectorIiNS_9allocatorIiEEE4sizeB8ne220000Ev, __ZNKSt3__16vectorIiNS_9allocatorIiEEE19__annotate_increaseB8ne220000Em, __ZNSt3__116reverse_iteratorIPiEC2B8ne220000ES1_, __ZNKSt3__16vectorIiNS_9allocatorIiEEE14__annotate_newB8ne220000Em, __ZNSt3__13minB8ne220000ImEERKT_S3_S3_, __ZNSt3__16vectorIiNS_9allocatorIiEEE18__construct_at_endIPKiS6_EEvT_T0_m, __ZNSt3__128__exception_guard_exceptionsINS_6vectorIiNS_9allocatorIiEEE16__destroy_vectorEEC2B8ne220000ES5_, _user_repl_fn_11_0, __ZNSt3__14pairIPKiS2_EC2B8ne220000IS2_S2_TnNS_9enable_ifIXclsr25__check_pair_constructionIS2_S2_EE23__is_pair_constructibleIT_T0_EEEiE4typeELi0EEEOS6_OS7_, ____orc_init_func.user$user_cpp_raw_9-14, _jank_global_init_13, __ZNKSt16initializer_listIiE3endB8ne220000Ev, __ZNSt3__14pairIPKiS2_EC1B8ne220000IS2_S2_TnNS_9enable_ifIXclsr25__check_pair_constructionIS2_S2_EE23__is_pair_constructibleIT_T0_EEEiE4typeELi0EEEOS6_OS7_, __ZNSt3__130__uninitialized_allocator_copyB8ne220000INS_9allocatorIiEEPKiS4_PiEET2_RT_T0_T1_S6_, _list, __ZNSt3__16vectorIiNS_9allocatorIiEEE16__destroy_vectorclB8ne220000Ev, __ZNSt3__112__to_addressB8ne220000IKiEEPT_S3_, __ZNSt3__16vectorIiNS_9allocatorIiEEE21_ConstructTransactionC2B8ne220000ERS3_m, __ZNSt3__129_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEC1B8ne220000ERS2_RS3_S6_, __ZNSt3__19allocatorIiE10deallocateB8ne220000EPim, __ZNSt3__112__destroy_atB8ne220000IiTnNS_9enable_ifIXntsr8is_arrayIT_EE5valueEiE4typeELi0EEEvPS2_, ___clang_call_terminate, __ZNSt3__16vectorIiNS_9allocatorIiEEE21_ConstructTransactionD2B8ne220000Ev, __ZNSt3__113__unwrap_iterB8ne220000IPiNS_18__unwrap_iter_implIS1_Lb1EEETnNS_9enable_ifIXsr21is_copy_constructibleIT_EE5valueEiE4typeELi0EEEDTclsrT0_8__unwrapclsr3stdE7declvalIS5_EEEES5_, __ZNSt3__13minB8ne220000ImNS_6__lessIvvEEEERKT_S5_S5_T0_, __ZNSt3__128__exception_guard_exceptionsINS_6vectorIiNS_9allocatorIiEEE16__destroy_vectorEEC1B8ne220000ES5_, __ZNSt3__116reverse_iteratorIPiEC1B8ne220000ES1_, __ZNSt3__16vectorIiNS_9allocatorIiEEE20__throw_length_errorB8ne220000Ev, __ZNSt3__114__unwrap_rangeB8ne220000IPKiS2_EEDaT_T0_, __ZNKSt16initializer_listIiE5beginB8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEEC2B8ne220000ESt16initializer_listIiE, __ZNSt3__113__rewrap_iterB8ne220000IPiS1_NS_18__unwrap_iter_implIS1_Lb1EEEEET_S4_T0_, __ZNKSt3__16vectorIiNS_9allocatorIiEEE17__annotate_deleteB8ne220000Ev, __ZNSt3__19allocatorIiE8allocateB8ne220000Em, __ZNKSt3__16vectorIiNS_9allocatorIiEEE31__annotate_contiguous_containerB8ne220000EPKvS5_, __ZNSt3__16vectorIiNS_9allocatorIiEEE22__base_destruct_at_endB8ne220000EPi, __ZNSt3__128__exception_guard_exceptionsINS_6vectorIiNS_9allocatorIiEEE16__destroy_vectorEED1B8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEE16__destroy_vectorC1B8ne220000ERS3_, __ZNSt3__116allocator_traitsINS_9allocatorIiEEE10deallocateB8ne220000ERS2_Pim, __ZNKSt3__16vectorIiNS_9allocatorIiEEE8max_sizeB8ne220000Ev, __ZNSt3__122__make_exception_guardB8ne220000INS_6vectorIiNS_9allocatorIiEEE16__destroy_vectorEEENS_28__exception_guard_exceptionsIT_EES7_, __ZNSt3__16vectorIiNS_9allocatorIiEEE11__vallocateB8ne220000Em, __ZNSt3__19allocatorIiEC2B8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_6vectorIiNS_9allocatorIiEEE16__destroy_vectorEED2B8ne220000Ev, __ZNKSt3__16vectorIiNS_9allocatorIiEEE4dataB8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEE21_ConstructTransactionC1B8ne220000ERS3_m, __ZNSt3__116allocator_traitsINS_9allocatorIiEEE8max_sizeB8ne220000IS2_TnNS_9enable_ifIXnt16__has_max_size_vIKT_EEiE4typeELi0EEEmRKS2_, __ZNSt3__112__to_addressB8ne220000IiEEPT_S2_, __ZNSt3__19allocatorIiEC1B8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEE16__init_with_sizeB8ne220000IPKiS6_EEvT_T0_m, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEED1B8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEE16__destroy_vectorC2B8ne220000ERS3_, __ZNSt3__16vectorIiNS_9allocatorIiEEE21_ConstructTransactionD1B8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEEC1B8ne220000ESt16initializer_listIiE, __ZNKSt3__116reverse_iteratorIPiEdeB8ne220000Ev, __ZNKSt3__16vectorIiNS_9allocatorIiEEE17__annotate_shrinkB8ne220000Em, __ZNSt3__135__uninitialized_allocator_copy_implB8ne220000INS_9allocatorIiEEPKiS4_PiEET2_RT_T0_T1_S6_, __ZNSt3__16vectorIiNS_9allocatorIiEEED2B8ne220000Ev, __ZNSt3__129_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEC2B8ne220000ERS2_RS3_S6_, __ZNSt3__118__unwrap_iter_implIPiLb1EE8__rewrapB8ne220000ES1_S1_, __ZNSt3__122__make_exception_guardB8ne220000INS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEEENS_28__exception_guard_exceptionsIT_EES7_, __ZNSt3__1neB8ne220000IPiS1_EEbRKNS_16reverse_iteratorIT_EERKNS2_IT0_EEQrqXnecldtfp_4baseEcldtfp0_4baseERNS_14convertible_toIbEEE, __ZNKSt3__16__lessIvvEclB8ne220000ImmEEbRKT_RKT0_, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEE10__completeB8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEEC2B8ne220000ES5_, __ZNKSt3__16vectorIiNS_9allocatorIiEEE8capacityB8ne220000Ev, __ZNSt3__16vectorIiNS_9allocatorIiEEE5clearB8ne220000Ev, __ZNSt3__114__construct_atB8ne220000IiJRKiEPiEEPT_S5_DpOT0_, __ZNSt3__118__unwrap_iter_implIPiLb1EE8__unwrapB8ne220000ES1_, __ZNSt3__123__libcpp_numeric_limitsImLb1EE3maxB8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_6vectorIiNS_9allocatorIiEEE16__destroy_vectorEE10__completeB8ne220000Ev, __ZNKSt16initializer_listIiE4sizeB8ne220000Ev, __ZNSt3__131__annotate_contiguous_containerB8ne220000INS_9allocatorIiEEEEvPKvS4_S4_S4_, __ZNSt3__116allocator_traitsINS_9allocatorIiEEE7destroyB8ne220000IiTnNS_9enable_ifIXnt15__has_destroy_vIS2_PT_EEiE4typeELi0EEEvRS2_S7_, __ZNSt3__112construct_atB8ne220000IiJRKiEPiEEPT_S5_DpOT0_, __ZNSt3__119__allocate_at_leastB8ne220000INS_9allocatorIiEEEENS_19__allocation_resultINS_16allocator_traitsIT_E7pointerEEERS5_m, __ZNSt3__113__unwrap_iterB8ne220000IPKiNS_18__unwrap_iter_implIS2_Lb1EEETnNS_9enable_ifIXsr21is_copy_constructibleIT_EE5valueEiE4typeELi0EEEDTclsrT0_8__unwrapclsr3stdE7declvalIS6_EEEES6_, __ZNKSt3__116reverse_iteratorIPiE4baseB8ne220000Ev, __ZNKSt3__129_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEclB8ne220000Ev, __ZNSt3__123__libcpp_numeric_limitsIlLb1EE3maxB8ne220000Ev, __ZNSt3__119__allocator_destroyB8ne220000INS_9allocatorIiEENS_16reverse_iteratorIPiEES5_EEvRT_T0_T1_, $.user$user_cpp_raw_9-14.__inits.0, __ZNSt3__118__unwrap_iter_implIPKiLb1EE8__unwrapB8ne220000ES2_, __ZNSt3__116allocator_traitsINS_9allocatorIiEEE9constructB8ne220000IiJRKiETnNS_9enable_ifIXnt17__has_construct_vIS2_PT_DpT0_EEiE4typeELi0EEEvRS2_S9_DpOSA_, __ZNSt3__114numeric_limitsImE3maxB8ne220000Ev, __ZNSt3__114numeric_limitsIlE3maxB8ne220000Ev, __ZSt28__throw_bad_array_new_lengthB8ne220000v }) }
UNREACHABLE executed at /opt/homebrew/Cellar/llvm/22.0.0/include/llvm/Support/Error.h:779!

Stack trace

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x0000000190dcea60 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x190dcea60 <+8>:  b.lo   0x190dcea80    ; <+40>
    0x190dcea64 <+12>: pacibsp
    0x190dcea68 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x190dcea6c <+20>: mov    x29, sp
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x0000000190dcea60 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x0000000190e06c20 libsystem_pthread.dylib`pthread_kill + 288
    frame #2: 0x0000000190d13a20 libsystem_c.dylib`abort + 180
    frame #3: 0x000000011298afe4 libLLVM.dylib`llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 564
    frame #4: 0x00000001000c6da0 jank`llvm::cantFail(Err=(Payload = 0x0000600000472d00), Msg="Failure value returned from cantFail wrapped call\nFailed to materialize symbols: { (main, { __ZNSt3__16vectorIiNS_9allocatorIiEEED1B8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEED2B8ne220000Ev, _user_cpp_raw_9_0, __ZNSt3__119__unwrap_range_implIPKiS2_E8__unwrapB8ne220000ES2_S2_, __ZNSt3__116reverse_iteratorIPiEppB8ne220000Ev, __ZNSt3__116__non_trivial_ifILb1ENS_9allocatorIiEEEC2B8ne220000Ev, __ZNSt3__128__exception_guard_exceptionsINS_29_AllocatorDestroyRangeReverseINS_9allocatorIiEEPiEEEC1B8ne220000ES5_, __ZNKSt3__16vectorIiNS_9allocatorIiEEE4sizeB8ne220000Ev, __ZNKSt3__16vectorIiNS_9allocatorIiEEE19__annotate_increaseB8ne220000Em, __ZNSt3__116reverse_iteratorIPiEC2B8ne220000ES1_, __ZNKSt3__16vectorIiNS_9allocatorIiEEE14__annotate_newB8ne220000Em, __ZNSt3__13minB8ne220000ImEERKT_S3_S3_, __ZNSt3__16vectorIiNS_9allocatorIiEEE18__construct_at_endIPKiS6_EEvT_T0_m, __ZNSt3__128__exception_guard_exceptionsINS_6vectorIiNS_9allocatorIiEEE16__destroy_ve"...) at Error.h:779:5
    frame #5: 0x0000000100b0758c jank`jank::jit::processor::load_ir_module(this=0x0000000102c35cf8, m=0x000000010d6046f0) const at processor.cpp:253:5
    frame #6: 0x0000000100a1fb6c jank`jank::evaluate::eval(expr=jank::analyze::expr::function_ref @ 0x000000016fdfc768) at evaluate.cpp:598:25
    frame #7: 0x0000000100a23d44 jank`jank::evaluate::eval(expr=jank::analyze::expr::cpp_raw_ref @ 0x000000016fdfcac0) at evaluate.cpp:719:25
    frame #8: 0x0000000100a59b04 jank`_ZZN4jank8evaluate4evalEN3jtl3refINS_7analyze10expressionEEEENK3$_0clINS2_INS3_4expr7cpp_rawEEEEEDaT_(this=0x000000016fdfcef8, typed_ex=jtl::ref<jank::analyze::expr::cpp_raw> @ 0x000000016fdfcb08) at evaluate.cpp:273:52
    frame #9: 0x0000000100a18784 jank`auto jank::analyze::visit_expr<jank::evaluate::eval(jtl::ref<jank::analyze::expression>)::$_0>(f=0x000000016fdfcef8, e=jank::analyze::expression_ref @ 0x000000016fdfceb8) at visit.hpp:89:16
    frame #10: 0x0000000100a18218 jank`jank::evaluate::eval(ex=jank::analyze::expression_ref @ 0x000000016fdfcf40) at evaluate.cpp:273:5
    frame #11: 0x00000001006a17f0 jank`jank::runtime::context::eval_string(this=0x0000000102c35c00, code=0x000000016fdfdeb0) at context.cpp:176:13
    frame #12: 0x00000001006a14d4 jank`jank::runtime::context::eval_file(this=0x0000000102c35c00, path=0x000000016fdfe158) at context.cpp:159:12
    frame #13: 0x00000001000048dc jank`jank::repl() at main.cpp:199:34
    frame #14: 0x0000000100003ad4 jank`main::$_0::operator()(this=0x000000016fdfe87f, argc=2, argv=0x000000016fdfebe8) const at main.cpp:336:9
    frame #15: 0x00000001000038c4 jank`main::$_0::__invoke(argc=2, argv=0x000000016fdfebe8) at main.cpp:293:60
    frame #16: 0x000000010019eb24 jank`jank_init(argc=2, argv=0x000000016fdfebe8, init_default_ctx='\0', fn=(jank`main::$_0::__invoke(int, char const**) at main.cpp:293)) at c_api.cpp:988:14
    frame #17: 0x0000000100002f6c jank`main(argc=2, argv=0x000000016fdfebe8) at main.cpp:293:10
    frame #18: 0x0000000190a7e0e0 dyld`start + 2360

shantanu-sardesai avatar Aug 23 '25 10:08 shantanu-sardesai

This is a Clang bug. We can easily reproduce using clang-repl. There's nothing jank can do about this aside from report it as a Clang bug on Github.

clang-repl> #include <vector>

clang-repl> std::vector<int> list{1, 2, 3, 4, 5}
In file included from <<< inputs >>>:1:
input_line_2:1:37: error: expected ';' after top level declarator
    1 | std::vector<int> list{1, 2, 3, 4, 5}
      |                                     ^
      |                                     ;
error: Parsing failed.

clang-repl> std::vector<int> list{1, 2, 3, 4, 5};
JIT session error: Symbols not found: [ _ZSt8_DestroyIPiiEvT_S1_RSaIT0_E, _ZSt22__uninitialized_copy_aIPKiPiiET0_T_S4_S3_RSaIT1_E, _ZSt8distanceIPKiENSt15iterator_traitsIT_E15difference_typeES3_S3_ ]
error: Failed to materialize symbols: { (main, { _ZNKSt16initializer_listIiE4sizeEv, _ZNSt6vectorIiSaIiEE19_M_range_initializeIPKiEEvT_S5_St20forward_iterator_tag, _ZNSt12_Vector_baseIiSaIiEE19_M_get_Tp_allocatorEv, _ZNSt6vectorIiSaIiEE17_S_check_init_lenEmRKS0_, _ZNSt12_Vector_baseIiSaIiEE12_Vector_implD2Ev, __clang_call_terminate, _ZNSt6vectorIiSaIiEE11_S_max_sizeERKS0_, __orc_init_func.incr_module_3, _ZNSt12_Vector_baseIiSaIiEE13_M_deallocateEPim, list, _ZNKSt16initializer_listIiE5beginEv, _ZNSt12_Vector_baseIiSaIiEE11_M_allocateEm, _ZNSt15__new_allocatorIiE8allocateEmPKv, _ZNSt12_Vector_baseIiSaIiEED2Ev, _ZNSt12_Vector_baseIiSaIiEEC2ERKS0_, _ZNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataC2Ev, $.incr_module_3.__inits.0, _ZNSt6vectorIiSaIiEED2Ev, _ZSt3minImERKT_S2_S2_, _ZNSt12_Vector_baseIiSaIiEE12_Vector_implC2ERKS0_, _ZNSt6vectorIiSaIiEEC2ESt16initializer_listIiERKS0_, _ZNSt15__new_allocatorIiE10deallocateEPim, DW.ref.__gxx_personality_v0, _ZNSt15__new_allocatorIiED2Ev, _ZNKSt16initializer_listIiE3endEv }) }

clang-repl> int a{};
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_3 }) }

clang-repl> int b{};

clang-repl>

jeaye avatar Aug 29 '25 21:08 jeaye

Shall I close this since it seems like it's fixed?

jank's REPL:

user=> (cpp/raw "std::vector<int> list{1, 2, 3, 4, 5}")
In file included from <<< inputs >>>:1:
input_line_2:1:37: error: expected ';' after top level declarator
    1 | std::vector<int> list{1, 2, 3, 4, 5}
      |                                     ^
      |                                     ;
Uncaught exception: Unable to parse 'cpp/raw' expression.

user=> (cpp/raw "std::vector<int> list{1, 2, 3, 4, 5};")
nil

C++ REPL:

native> std::vector<int> list{1, 2, 3, 4, 5}
In file included from <<< inputs >>>:1:
input_line_2:1:37: error: expected ';' after top level declarator
    1 | std::vector<int> list{1, 2, 3, 4, 5}
      |                                     ^
      |                                     ;
error: Parsing failed.
native> std::vector<int> list{1, 2, 3, 4, 5};
native> int a{};
native> int b{};

shantanu-sardesai avatar Sep 27 '25 18:09 shantanu-sardesai

Nothing was done to fix this.

jeaye avatar Sep 27 '25 18:09 jeaye