Stream: compiler development

Topic: code gen panic when sending struct to host


view this post on Zulip Richard Feldman (Sep 19 2023 at 21:48):

anyone run into this before or know what it is? It happened when I switched mainForHost from a function which takes a RocStr to a function which takes a struct with two RocStrs and a RocList:

$ RUST_BACKTRACE=1 roc build
🔨 Rebuilding platform...
thread 'main' panicked at 'Found StructValue(StructValue { struct_value: Value { name: "", address: 0x600002114ac8, is_const: false, is_null: false, is_undef: false, llvm_value: "{ %list.RocList, %str.RocStr, %str.RocStr } %1", llvm_type: "{ %list.RocList, %str.RocStr, %str.RocStr }" } }) but expected PointerValue variant', /Users/rtfeldman/.cargo/git/checkouts/inkwell-55729a4c43239568/95a3a13/src/values/enums.rs:302:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: inkwell::values::enums::BasicValueEnum::into_pointer_value
   3: roc_gen_llvm::llvm::build::expose_function_to_host_help_c_abi
   4: roc_gen_llvm::llvm::build::build_procedures_help
   5: roc_gen_llvm::llvm::build::build_procedures
   6: roc_build::program::gen_from_mono_module
   7: roc_build::program::build_loaded_file
   8: roc_build::program::build_file
   9: roc_cli::build
  10: roc::main

view this post on Zulip Richard Feldman (Sep 19 2023 at 21:49):

I'm guessing from the error that one part of code gen thinks it's passing a pointer to the struct, but something else is expecting the contents of the struct to be on the stack directly, and the disagreement is leading to an Inkwell panic

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 23:40):

I think that is likely exactly the error. We are assuming types wrong. That said, this is in the conversion from the roc version of the function to a c abi friendly wrapper function.


Last updated: Jul 06 2025 at 12:14 UTC