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

[Long-term] Specialize wrapper functions for 0-sized closures #108

Open
tomaka opened this issue Dec 26, 2016 · 2 comments
Open

[Long-term] Specialize wrapper functions for 0-sized closures #108

tomaka opened this issue Dec 26, 2016 · 2 comments

Comments

@tomaka
Copy link
Owner

tomaka commented Dec 26, 2016

Very long term issue. Requires specialization to be stable and a way to specialize for functions and closures that don't borrow any environment.

@tomaka tomaka changed the title Specialize wrapper functions for 0-sized closures [Long-term] Specialize wrapper functions for 0-sized closures Dec 26, 2016
@tomaka
Copy link
Owner Author

tomaka commented Dec 27, 2016

In order to be a bit more specific, in Rust a closure is composed of two things: a function and an "environment". The environment contains all the local variables that were captured by the closures.

For example if you do let a = 5; move || a + 3 then the environment of the closure is the variable a.

In order to make this work, hlua asks lua to allocate some memory, copies the environment inside it, pushes the environment as a "hidden parameter" for the C callback, and when the C callback is called the environment is loaded and the closure is recreated.

However many closures and all freestanding functions don't have any environment at all. In this situation hlua still asks lua to allocate 0 byte of memory, pushes the hidden parameter, and when the C callback is called it asks lua to load the zero-sized data. This issue is about removing all these useless steps.

@jonas-schievink
Copy link
Contributor

rust-lang/rust#39817 can possibly help here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants