chc4 / lineiform

A meta-JIT library for Rust interpreters
156 stars 4 forks source link

Use argument and output info for correct Cranelift function prototype declaration #2

Open chc4 opened 2 years ago

chc4 commented 2 years ago

Currently, we just hardcode the input and output registers for closures we do partial evaluation on: we tell Cranelift (in lift.rs Jit::new) that all functions we compile have the prototype ptr, ptr, int -> int. This means we would miscompile e.g. jit.speedup(|| return (1u64, 2u64) since it wouldn't know that it has to feed the 2 immediate into the output register sink.

We should instead be using mem::size_of<A>() and mem::size_of<O>() to fill out the proper SystemV ABI calling convention for a function that takes and returns arguments of those size. I think this is fairly straightforward - too big arguments/outputs are turned into an argument to a stack buffer to write to, but we should be able to just tell Cranelift that's a ptr afaik since it never optimizes away stores.