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

Get rid of the "rust-call" hack #41058

Open
aochagavia opened this issue Apr 4, 2017 · 7 comments
Open

Get rid of the "rust-call" hack #41058

aochagavia opened this issue Apr 4, 2017 · 7 comments
Labels
A-closures Area: closures (`|args| { .. }`) C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aochagavia
Copy link
Contributor

Based on rust-lang/rfcs#1921 (comment)

Currently, we fake variadics by defining functions with the rust-call ABI. These functions receive a tuple as parameter (of arbitrary arity and types), but in their ABI the tuple is expanded. It would be great to get rid of this hack and in the process pave the way for the eventual feature of variadic generics.

@aochagavia
Copy link
Contributor Author

@eddyb would you be willing to mentor me on this issue?

@eddyb
Copy link
Member

eddyb commented Apr 6, 2017

@aochagavia Sure thing, poke me on IRC.

@eddyb
Copy link
Member

eddyb commented Apr 6, 2017

One way to start would be to modify

pub fn mk_fn_sig<I>(self,
to replace RustCall with Rust by expanding the last argument in-place, if it's a concrete tuple (not a parameter).
However, that might not be the only place that you'd need to modify to get that working.
But if you get it to consistently do that, then trans should be able to expect RustCall to never exist.

@aochagavia
Copy link
Contributor Author

aochagavia commented Apr 10, 2017

I think I am missing some context. Just to make things clear for myself, this issue is about implementing variadic generics in rustc without changing the syntax, right? In my understanding, variadic generics provide the ability to create traits where functions accept arbitrary arguments, specified by the implementor. Something like the code below:

trait VariadicTrait<Args> {
    fn variadic_fn(&self, args: Args);
}

impl VariadicTrait<(&'static str,)> for () {
    fn variadic_fn(&self, (s,): (&'static str,)) {
        println!("{}", s)
    }
}

fn main() {
    ().variadic_fn(("hi",))
}

Previous code compiles perfectly in stable Rust, though it looks ugly. From my perspective, this looks like we already have variadic generics. However, this can't be true, so what am I missing?

Also, one of the problems with the code above is that the tuple is not expanded in the ABI, which is bad for performance (IIRC). Is this the problem we are trying to solve here? Would it be enough to infer whether a tuple parameter needs to be expanded? That way we wouldn't need "rust-call" anymore.

@eddyb
Copy link
Member

eddyb commented Apr 10, 2017

@aochagavia The problem is that you can't write this:

trait VariadicTrait<Args> {
    fn variadic_fn(&self, ...Args);
}

That is, true variadic functions, that for Args being a given tuple they become regular functions (e.g. fn(&self, A, B) for Args = (A, B)).

Removing "rust-call" from the source would more or less require VG to be implemented, at that's ways off - what we can do now, however, is desugar "rust-call" into an internal VG-like form, or at least expand it into regular functions as early as possible - so that it doesn't have to be manually handled by backends.

@Mark-Simulacrum Mark-Simulacrum added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 20, 2017
@steveklabnik
Copy link
Member

Triage: no changes I'm aware of.

@eddyb
Copy link
Member

eddyb commented Sep 24, 2018

I started a branch of this but had to lower priority on it.

@jonas-schievink jonas-schievink added the A-closures Area: closures (`|args| { .. }`) label Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: closures (`|args| { .. }`) C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants