Hi! I got stuck while contributing to the code gen phase. I'm picking up on a put-on-hold work on Tail Recursion Modulo Cons optimisation; Allowing recursive calls to be turned to loops, even if the "tail" recursive call is inside a Recursive tag union's field. I'm making it so that the recursive call can be inside of an arbitrarily nested struct in one of the tag's arguments, not just in the argument directly. So this would compile to a loop:
LinkedList a : [Nil, Cons { first : a, rest : LinkedList a }]
repeat : a, U64 -> LinkedList a
repeat = \value, n ->
when n is
0 -> Nil
_ -> Cons { first: value, rest: repeat value (n - 1) }
Dev backend is done, started llvm.
I want to extend the capabilities of generating GetElementPointer-s. I've already prepared it to potentially get a field that is somewhere deeper in a nested struct, not directly in the arguments of the recursive tag union by holding not just an index associated with the data (u64
), but rather a slice of indices &[64]
. That way you can "drill down" into a struct's field, following the indices. We only use the the first 2 elements so far (tag id & tag argument index). See here.
Essentially I want a function like union_field_ptr_at_index_help, except the builder.new_build_struct_gep(...)
should use the new_build_in_bounds_gep method that accepts a ordered_indexes: &[IntValue<'ctx>]
, not a u32
.
How do I convert a &[u64]
into a &[inkwell::values::IntValue<'ctx>]
inside the union_field_ptr_at_index_help function? I'm a beginner at rust, so allow me to shamelessly ask for a snippet, if possible. It's night time for me, tomorrow I'll check zulip, bye!
Last updated: Jul 06 2025 at 12:14 UTC