Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Rethink argument modes #2030

Closed
marijnh opened this issue Mar 20, 2012 · 1 comment
Closed

RFC: Rethink argument modes #2030

marijnh opened this issue Mar 20, 2012 · 1 comment
Labels
A-codegen Area: Code generation A-typesystem Area: The type system
Milestone

Comments

@marijnh
Copy link
Contributor

marijnh commented Mar 20, 2012

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.

@ghost ghost assigned marijnh Mar 20, 2012
@marijnh marijnh reopened this Mar 20, 2012
@graydon
Copy link
Contributor

graydon commented Jul 25, 2012

Modes are going away. Region pointers handle the case explicitly and users are perpetually confused by the compiler choosing by-ref or by-val on their behalf.

@graydon graydon closed this as completed Jul 25, 2012
@marijnh marijnh removed their assignment Jun 16, 2014
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants