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

Function pointer lifetimes #252

Closed
wants to merge 1 commit into from
Closed

Function pointer lifetimes #252

wants to merge 1 commit into from

Conversation

Tobba
Copy link

@Tobba Tobba commented Sep 20, 2014

Rendered

(looks like I accidently removed the template by using the github quick commit, be careful)

@emberian
Copy link
Member

I think no lifetime should behave just like an reference does. I imagine that there are few if any use cases that need the function pointer to escape.

@eddyb
Copy link
Member

eddyb commented Sep 20, 2014

@cmr I checked and virtually every use of non-extern fn() as an argument was escaping (by being stored in a structure).
This becomes more clear when you compare closures with non-escaping fn() pointers: you're almost always going to use a closure in those cases.

@Kimundi
Copy link
Member

Kimundi commented Sep 20, 2014

+1, this is the first step to enabling safe dynamic code loading.

@Ericson2314
Copy link
Contributor

Turn fn() into a quasi-unsized type, in such a way that the current fn() would represent &'static fn().

I think that alternative is the way to go. It doesn't commit us to adding more features today, but unlike the status quo and other proposals, it seems way more forwards compatible.

C confuses arrays with pointers, and functions with function pointers. Rust fixed the former, it's high time it addressed the latter.

@eddyb
Copy link
Member

eddyb commented Sep 22, 2014

@Ericson2314 The big issue with that though is that they are not and cannot be DSTs because they do not support dynamic queries of size and alignment.
That may not seem significant, but it would require duplicating all the DST logic dealing with Sized? and add more kinds to support these "non-sized" types.
That's too much of a language design and implementation cost compared to the original proposal.

@Ericson2314
Copy link
Contributor

@eddyb Would adding length and alignment words before the code ptr work (i.e. [size, align, code....])? If not, won't there be some duplication either way as the RFC as written means a lot of borrowed pointer logic must be duplication?

@eddyb
Copy link
Member

eddyb commented Sep 24, 2014

@Ericson2314 No, that would not work for, e.g extern "C" fn().
There won't be a duplication of borrowed pointer logic because borrowed pointers are just one type containing a lifetime, all the marker types, trait objects and old closures also have lifetimes and most of the logic is common.

@nikomatsakis
Copy link
Contributor

This RFC has gotten quite old by now, and there are newer RFCs that offer more comprehensive solutions. I'm closing this RFC as postponed under #1037. Thanks very much for the suggestion!

withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
Implement `s.split()` for `Stream + Sink`
wycats pushed a commit to wycats/rust-rfcs that referenced this pull request Mar 5, 2019
Browser Support Changes RFC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants