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

Improve the fn pointer types #1037

Open
nikomatsakis opened this issue Apr 6, 2015 · 2 comments
Open

Improve the fn pointer types #1037

nikomatsakis opened this issue Apr 6, 2015 · 2 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@nikomatsakis
Copy link
Contributor

The current function pointer types have some downsides:

  1. They assume that all functions are static code that lives forever. This isn't true for JITs or DLLs.
  2. They are always non-nullable, safe pointers. This may not be what you want -- particularly the nullable aspect. This is connected to the previous point, because it implies that there is no place to attach a lifetime in the current syntax.

This is a "postponement issue". There have been various RFCs aiming to improve this:

It should be possible to adapt these schemes backwards compatibly.

@nikomatsakis nikomatsakis changed the title Incorporate lifetimes into function pointers Improve the fn pointer types Apr 6, 2015
@CloudiDust
Copy link
Contributor

I am currently of the opinion that if function pointers are not considered pointers by the language, then we'd better call them something else, like "function handles". This can be the first step towards improving fn types.

"Function pointers are not considered pointers" feels like a flaw in Rust's design, but "function handles are not considered pointers" doesn't.

Also, if later "true" function pointers are introduced, we need to disamiguate fns and "true" function pointers. Renaming fns to "function handles" is a good way to do so.

I wonder if such a renaming proposal should be an RFC? :)

@jarcode-foss
Copy link

jarcode-foss commented Mar 18, 2017

We still need a way to specify lifetimes for fn types, and I don't feel like representing function pointers as actual borrows in Rust is really nessecary. I favour an approach similar to #252 -- fn 'a (A, B) -> R, where if the lifetime is omitted, 'static is assumed.

However, when it comes to DLL loading (see #661), lifetimes of functions that are being used outside of the loaded code will be bound by the lifetime of the library (handle) itself, which the loaded code is unaware of. In this sense, 'static' in all the library code refers to the lifetime of the libray.

This means that when symbols are resolved from a DLL, a 'static lifetime needs to be translated into 'a, where 'a is the lifetime of the library handle. This also means the definition of static lifetimes in Rust may need to be changed.

Additionally, there should be some similar way to specify lifetimes for Fn closures.

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants