Skip to content

consider switching from manual indirect passing to byval #10030

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

Closed
thestinger opened this issue Oct 23, 2013 · 7 comments
Closed

consider switching from manual indirect passing to byval #10030

thestinger opened this issue Oct 23, 2013 · 7 comments
Labels
A-codegen Area: Code generation I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@thestinger
Copy link
Contributor

If we did this, LLVM would generate the copy for us, but only if needed (not a readonly parameter). It also conveys more information to the body of the function, by letting it know the pointer is valid.

@pnkfelix
Copy link
Member

I don't understand what this ticket is asking for. Is it about the code being generated by trans for LLVM to process, or is it actually proposing a deep change to the language itself?

@thestinger
Copy link
Contributor Author

Just a codegen change (tagged properly now). We currently generate a copy in the caller ourselves for non-immediate values, and pass by-pointer. LLVM has a byval attribute to generate the copy for you from a pointer, although it might have ABI implications too (might be something we get wrong for foreign functions).

@nikomatsakis
Copy link
Contributor

Makes sense, though I think we may also have more information than LLVM -- I've been wanting to optimize trans by passing in information about when a "by value" parameter can be used "in place". Though the ability to declare parameters as mut kind of throws a wrench into that, but I guess we can export whether parameters are declared as mut as part of the fn sig, used only for optimization purposes.

@nikomatsakis
Copy link
Contributor

Still I tend to agree we should generate the most "semantically correct" LLVM bitcode that we can.

@huonw
Copy link
Member

huonw commented Oct 23, 2013

Isn't a parameter declared as mut just sugar? i.e. the following are equivalent:

fn foo(mut x: Type) { 
    ... 
}

fn bar(x: Type) {
    let mut x = x;
    ...
}

@nikomatsakis
Copy link
Contributor

Isn't a parameter declared as mut just sugar? i.e. the following are equivalent:

Equivalent from the language POV, yes, but not necessarily the
codegen. I have to double check, though, whether or not a mut
parameter winds up being mutated in place or not. Certainly we could
ensure that this is not the case if we wanted, which would prob be
better than exporting whether or not a parameter is declared as mut.

@thestinger
Copy link
Contributor Author

I don't think we should do this now that we have dereferenceable.

Jarcho pushed a commit to Jarcho/rust that referenced this issue Feb 26, 2023
Add `impl_trait_in_params` lint

As this is a lint about style, and using `impl Trait` is purely cosmetical (even with downsides), a lot of unrelated files needed to allow this lint.

---

Resolves rust-lang#10030

changelog: New lint: [`impl_trait_in_params`]
[10197](rust-lang/rust-clippy#10197)
<!-- changelog_checked -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

4 participants