On 9/30/11 12:14 AM, Marijn Haverbeke wrote:
Now that every parameter is passed by reference, our ABI is no longer
compatible with C.

Are you talking about calling C functions from rust, or calling rust
from C? In the first case, we are generating a wrapper anyway, which
currently makes sure things are passed by value.

Not anymore, with the C decl.

I agree the current everything-by-reference situation is awful. I'm
not keen on bringing back references though. One relatively simple
solution would be partial monomorphizing: For each type parameter that
a function takes, we generate one version for immediate (by value)
types, and one version for structural types. You'd get 2^N (where N is
the number of type params, rarely more than 2) version of each generic
function. They can be generated in the crate that defines the
function, so no involved cross-crate magic is needed yet. This'd make
it predictable again whether an argument is passed by value or by
reference, so the everything-by-reference hack can go again. It'd also
make generic functions much more efficient when called on immediate
values.

What do you think?

How about what I proposed earlier: the '+' sigil means by-value, the '&' sigil means by-immutable-reference, and leaving it off has the compiler choose a sensible default based on the type? (Word-sized immutable stuff would get +, and others would get &.) You might still have to have & in a few corner cases involving generics, although I can't think of any concrete instances off the top of my head in which this would be the case.

I have a feeling this would avoid all the & noise we had before while maintaining ABI predictability.

Patrick
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to