Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Silent crash when calling procs from slice-of-procs within parapoly proc

Open ChuuniMage opened this issue 3 years ago • 4 comments

If I try to call applier, then the compiler silently crashes.

The exact same process of iterating over a slice of procs, and calling each proc, outside of the parapoly applier proc works just fine.

So, something funky is happening specifically regarding the parapoly.


import "core:fmt";
import "core:slice"


//Compile fails if this is called
applier :: proc(s: $S/[]$U, fs: []proc(U) -> $V, allocator := context.allocator) -> []V {
	new_len := len(s) * len(fs)
	rs := make([]V, new_len)
	i := 0
	for i < new_len {
		for f in fs {
			for v in s {
				rs[i] = f(v)
				i += 1
			}
		}
	}
	return rs
}

import "core:strings"

main :: proc(){

	make_honks :: proc (count:int) -> string {
		return strings.repeat("honk!", count)
	}

	juggle_bananas :: proc (count:int) -> string {
		return fmt.tprintf("%v bananas juggled!", count)
	}

	procs := []proc(int)->string{make_honks, juggle_bananas}
	input_ints := []int{4,2,6}
	// fmt.printf("APPLIER PARAPOLY: Expect 4,2,6 honks, bananas juggled %v \n", applier(input_ints, procs)) // If uncommented, there is a compile failure


	//Below is the same logic as inside applier, but there is a compile failure if the generic is attempted
	new_len := len(input_ints) * len(procs)
	outside_of_generic := make([]string, new_len)
	i := 0
	for i < new_len {
		
		for f in procs {
			for v in input_ints {
				outside_of_generic[i] = f(v)
				i += 1
			}
		}
	}
	fmt.printf("OUTSIDE OF PARAPOLY: Expect 4,2,6 honks, bananas juggled %v \n", outside_of_generic)
};

ChuuniMage avatar Oct 21 '22 10:10 ChuuniMage

Ran it through remedyBG and got this. No idea what to do with it - but this is where the exception happens image

ChuuniMage avatar Nov 10 '22 01:11 ChuuniMage

Does this still happen?

gingerBill avatar Nov 21 '22 11:11 gingerBill

Yes, it still happens.

ChuuniMage avatar Nov 22 '22 03:11 ChuuniMage