-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Unsized rvalues: implement boxed closure impls. #55431
Conversation
r? @frewsxcv (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@TimNN ^ not very helpful |
|
I've re-assigned this to @nikomatsakis since I think it'll probably want lang/compiler team discussion or review. |
Triage; @nikomatsakis Hello, have you been able to get back to this PR? |
CI fails with:
|
Pinging from triage @rust-lang/compiler can anyone review this? |
This is not really a compiler change. Maybe @rust-lang/lang + @rust-lang/libs? |
@eddyb I think it is compiler-relevant since one of the core questions in the PR description is how to make use of the new impls unstable:
This isn't possible today, and it's hard for me to understand how it could become possible: we'd have to somehow gate all coercions, where clauses, transitive uses (e.g. |
@cramertj I think that's a lang team discussion topic - that is, whether we should just stabilize now, given that feature-gating is hard (or even impossible). |
@rfcbot fcp merge This change introduces the following (insta-stable) trait impls: impl<A, F: FnOnce<A> + ?Sized> FnOnce<A> for Box<F> { .. }
impl<A, F: FnMut<A> + ?Sized> FnMut<A> for Box<F> { .. }
impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> { .. } Defining these impls requires the use of the However, we don't have the machinery (and possibly won't ever have the machinery) to make trait impls unstable. As such, merging this PR makes These implementations have been desired for a long time but have been impossible to add until now. I'm not sure of any other reasonable ways to implement them, or any ways that we might want to change the implementations going forward in a user-observable way. |
Team member @cramertj has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
Once a majority of reviewers approve (and none object), 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. |
Is there a particular reason to stabilize these impls now rather than to wait until |
@Centril The surface area is much smaller for these three impls, I guess, and they cover a large portion of the urgent demand for unsized locals at the same time. |
@rfcbot concern unimplementable-if-unsized-does-not-pan-out Historically we've avoiding expanding the stable API surface area of the standard library with unstable features. One of the best examples here is specialization where we've exclusively used it so far for performance improvements and we haven't started to use it for actually expanding trait impls yet. The rationale for this is that we can probably recover performance via other means if absolutely necessary if the unstable feature (specialization) doesn't pan out. Do we have a similar recourse for this? What if the unstable feature doesn't pan out? Are we confident enough that we can provide this implementation for all of time? |
@alexcrichton So I'd argue this is implementable even if the current unsized-rvalues-using-alloca proposal doesn't shake out-- we can still pass Compared with specialization, where exactly which implementations are allowed and when overlaps may occur is still open to soundness-related debate, the likelihood of the API surface needing to change here is far smaller. Basically the only thing that's being promised here is "there is some way to call |
|
@rfcbot resolve unimplementable-if-unsized-does-not-pan-out Sounds solid to me, thanks for the explanation! |
Sounds like #45417 |
@kennytm Sorry, I see you marked this as waiting-on-author-- is there something that needs to be changed here, or is CI just flaking? |
@cramertj the error is #55431 (comment) on the gnux32 target, and it doesn't look like an existing spurious error. Probably hit an LLVM bug. So this is waiting for the author (or anybody else) to debug why is this happening and how to fix/workaround it. |
Easily reproduced in my machine by setting |
ping from triage @qnighy any updates? |
ping frm triage @qnighy |
Procedurally it seems a bit odd to me to close a perfectly fine PR due to it being unmergable as a result of happening to trigger a suspected LLVM bug. To be clear, there's no requested change to the code in this PR-- only a change to LLVM to successfully compile it. |
@cramertj This is entirely by the book:
Once the LLVM issues can be fixed the PR should be reopened. |
This sounds like we're asking the author for changes. There are no changes being requested here. |
Or generally actions (e.g. "fix LLVM") that unblocks the PR. Perhaps this should be labeled as |
Are there any investigations have been done on LLVM? Can anyone find a workaround (maybe not optimal; we need it to be workable)? |
…mertj Unsized rvalues: implement boxed closure impls. (2nd try) This is a rebase of S-blocked-closed PR rust-lang#55431 to current master. LLVM has moved forward since then, so maybe we can check whether the new LLVM 8.0 version unblocked this work.
…mertj Unsized rvalues: implement boxed closure impls. (2nd try) This is a rebase of S-blocked-closed PR rust-lang#55431 to current master. LLVM has moved forward since then, so maybe we can check whether the new LLVM 8.0 version unblocked this work.
Unsized rvalues: implement boxed closure impls. (2nd try) This is a rebase of S-blocked-closed PR #55431 to current master. LLVM has moved forward since then, so maybe we can check whether the new LLVM 8.0 version unblocked this work.
Has this bug been reported to LLVM? Does anyone have a link? |
So, it looks like this PR has effectively been implemented and merged in #59500. Great! |
This pull request contains
boxed_closure_impls
that provides long-hoped three impls:This has been blocked by several reasons; see
FnBox
#28796 for details.Now that #48055 is (partly) implemented, we're ready to introduce the above impls, replacing existing
FnBox
workarounds.There are two major concerns, however.
Major concern 1: instability
I think these impls should be introduced as an unstable feature first, mainly because it relies on unsized rvalues. However,
impl
itself can't stand as unstable; all existing unstable features are tied with functions, methods, or types. I tried putting#[unstable]
on the impls but that didn't work.I'll mark this PR as [WIP] until it is resolved. I'll just remove[WIP]
and let the compiler team decide how to deal with the instability.Major concern 2: compatibility with
FnBox
I'm not really sure, but
FnBox
may be widely used in the nightly world. Although unstable features may regress, it's good if there's a path for gradual migration. It can be done in the following way:FnBox
a subtrait ofFnOnce
. This ensures thatdyn FnBox
implementsFnOnce
.FnOnce
impls forBox<impl FnOnce>
andBox<dyn FnBox>
.I believe that this minimizes breakage of crates that use
FnBox
.Minor concern: feature name and tracking issue
I currently assign
boxed_closure_impls
as the name and #48055 as the tracking issue. I'll prepare a separate tracking issue when the Major Concern 1 is resolved.