Skip to content

RFC: Rethink argument modes #2030

Closed
Closed
@marijnh

Description

@marijnh

The distinction between && and ++ (by address and by value) is clearly an annoyance, and can be removed for Rust functions now that generics are monomorphized.

I maintain that by-move is strictly less useful than by-copy, and should probably also be removed. By-copy is still needed to efficiently construct things, unless we want to force callers of constructor functions to explicitly move things (some(move my_local_vec)) or pay for a copy, which seems unfortunate to me.

Another thing is that having explicit control over passing style for native functions is necessary. If you have a multi-word-sized thing, you sometimes want to pass it by pointer, and sometimes as a whole, depending on the signature of the native. One option is to always pass things by-value to natives, and make the argument type an unsafe pointer when calling by pointer. Again, this puts a burden on the caller, but native functions are usually wrapped by a rust adaptor function already, so this is probably not all that bad. An unfortunate side effect is that taking the value of a native function would require wrapping it in some kind of adapter, because its calling convention isn't the same as that of a Rust function with the same signature.

My proposal would be: Keep modes, but only have copy and normal, where by-copy gives the callee ownership of the argument (moving when possible, making a copy otherwise), and normal leaves ownership with the caller. Automatically pick a suitable passing convention based on the type of the value (immediates are passed directly, all other things are passed by pointer), except for (directly called) native functions, which never take things by-pointer, as outlined above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions