Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 1558: Allow coercing non-capturing closures to function pointers #39817
Comments
aturon
added
B-RFC-approved
T-lang
labels
Feb 14, 2017
aturon
referenced this issue
Feb 14, 2017
Merged
RFC: Allow coercing non-capturing closures to function pointers. #1558
This comment has been minimized.
This comment has been minimized.
|
I'd like to implement this. Which steps are required? |
This comment has been minimized.
This comment has been minimized.
|
@est31 Awesome, thank you! @eddyb or @nikomatsakis, can one of you give some pointers? |
This comment has been minimized.
This comment has been minimized.
|
I'd reuse the existing "reify to Then HIR+Ty->HAIR lowering of the reify coercion has to generate something like... wait, no |
This comment has been minimized.
This comment has been minimized.
|
Hmm seems its more than I thought. As I'm rather tight with time this week, is it a problem if I implement it only next week? |
This comment has been minimized.
This comment has been minimized.
|
@est31 Absolutely! I don't know of anyone chomping at the bit to do this implementation work. |
jonas-schievink
referenced this issue
Feb 14, 2017
Open
[Long-term] Specialize wrapper functions for 0-sized closures #108
This comment has been minimized.
This comment has been minimized.
|
@eddyb I am not so sure how I feel about using this coercion. In particular, as we discussed in the RFC thread itself, it would imply that the closure from which we coerce is a "zero-capture" closure -- well, I guess we can actually check that eagerly easily enough, since the list of upvars that a closure uses is something we analyze very early. (i.e., the freevars list is available quite early.) |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I've assumed we use that early check all along ;). |
This comment has been minimized.
This comment has been minimized.
|
@eddyb well as usual you're two steps ahead of me. =) Have pity on an old man. That said, do we want to allow said coercion is you only capture zero-sized types? I guess I'm happy not to permit that for now. =) |
eddyb
added a commit
to eddyb/rust
that referenced
this issue
Feb 25, 2017
eddyb
added a commit
to eddyb/rust
that referenced
this issue
Feb 25, 2017
brson
added
the
B-unstable
label
Mar 1, 2017
eddyb
referenced this issue
Mar 8, 2017
Closed
Convert Dependency Graph Tasks from `in_task`s to `with_task`s #40376
This comment has been minimized.
This comment has been minimized.
|
cc @rust-lang/lang Is this ready for FCP? Can it get in for 1.19? |
brson
added
the
I-nominated
label
May 3, 2017
This comment has been minimized.
This comment has been minimized.
|
It seems to be fully implemented, but I don't know if anyone has actually had any experience using it. Any users who have, it would be great to hear from you. I don't have any objection to stabilizing in principle, don't know about anyone else. I'd like to know that someone has used it and not had any ICEs or anything though. |
This comment has been minimized.
This comment has been minimized.
|
Use case I found for this: |
This comment has been minimized.
This comment has been minimized.
this gives a list of people using the feature on github. Maybe ask them? I personally was (positively) surprised that the Rust ABI for having |
This comment has been minimized.
This comment has been minimized.
archshift
commented
May 3, 2017
•
|
@withoutboats #40204 (which affects this feature) is yet unresolved. |
This comment has been minimized.
This comment has been minimized.
|
One problem I had trying to use this feature was the type inference for the expected type of arguments doesn't work. For example, this code does not compile https://is.gd/FNoLWg: #![feature(closure_to_fn_coercion)]
fn foo(f: fn(Vec<u32>) -> usize) { }
fn main() {
foo(|x| x.len())
}UPDATE: Opened an issue (#41755) with some mentoring instructions. |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
May 6, 2017
•
I tried to use thing in ring here: briansmith/ring@44170d4. However, I got the error:
The type of The problem is that the implementation doesn't allow closures where |
This comment has been minimized.
This comment has been minimized.
|
Yeah, converting to extern "C" is not really possible right now. Implementing that to a satisfying degree is a bit bigger than the initial implementation. First the ABI of the closure needs to be inferred, and then the code that creates the actual closure function needs to be changed, to use the inferred type. Also, one needs to create an error when you put the closure into a local variable and use it in both extern "C" and normal extern "rust" contexts. |
This comment has been minimized.
This comment has been minimized.
I would think we would generate a wrapper for the closure's (internal) function. (Though I guess ideally we'd do this more uniformly or not at all, probably.) |
eddyb
referenced this issue
May 11, 2017
Closed
Allow coercing non-capturing closures to function pointers #1555
aturon
removed
the
I-nominated
label
May 11, 2017
This comment has been minimized.
This comment has been minimized.
|
Now that the outstanding bugs have been resolved, this feature is ready at least for consideration for stabilization. @rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
May 11, 2017
•
|
Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
2 weeks to get this in for 1.19 |
This comment has been minimized.
This comment has been minimized.
If we want it in until then, this can become tight. In the optimal case, people can already prepare PRs to the respective repositories for the neccessary steps required for stabilisation, like documentation. Also, as the time is pressing, it would be nice to have contributors for this who can devote enough time to get the PRs through review in a timely manner. All of this of course only if we actually want this feature in 1.19. |
This comment has been minimized.
This comment has been minimized.
|
So I've opened PRs to document and stabilize the feature, to hopefully speed up the process around those. @steveklabnik do you think the book requires documentation of this feature before stabilization? |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
May 23, 2017
|
|
rfcbot
added
the
final-comment-period
label
May 23, 2017
This comment has been minimized.
This comment has been minimized.
|
@est31 I think this is a bit in-the-weeds for the book, so I'm leaning towards no. @carols10cents ? |
This comment has been minimized.
This comment has been minimized.
Agreed, I think the reference and the API docs (if those are relevant?) is more appropriate. |
This comment has been minimized.
This comment has been minimized.
I'm not aware of any examples in the documentation that could be written more concisely with this feature present, nor do I know of an easy way to spot them if there are any. When replacing the There is also (to my knowledge) no api page for the So I'd say API docs would require no updating. |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
May 27, 2017
IIUC, that would not "zero cost" and so it would break the language design principles. It would be zero-cost if the closure's internal function were always inlined into the wrapper, I guess. But then that's the same as not having a wrapper, right? |
This comment has been minimized.
This comment has been minimized.
|
@briansmith The ABI could be part of monomorphization such that the closure isn't translated until it's either used with a Fn trait or coerced to an fn pointer and the latter would choose the ABI of the closure body itself. @michaelwoerister would be able to say if the trans item collector could reasonably do this. |
aturon commentedFeb 14, 2017
•
edited by nikomatsakis
RFC
Summary:
Outstanding issues: