-
Notifications
You must be signed in to change notification settings - Fork 7
Always make the "upvar types" a tuple of the actual upvar types (Parent issue#53488) #4
Always make the "upvar types" a tuple of the actual upvar types (Parent issue#53488) #4
Comments
This comment has been minimized.
This comment has been minimized.
@nikomatsakis so we think that we should not even group We will just use the similar logic directly in the Can you explain, as a motivation for the upcoming PR, why was this done this way and what does it buys us now ? I guess we discussed this but it escapes me now. Sorry for the repeated question. I am trying to tie the strings together as how this helps us achieve the over arching goal of just capturing the individual fields of an aggregate type (e.g struct) that are referenced in the |
IIUC, not forcing the tuple shape early means the number of tuple entries can be inferred, and they can be field paths into the direct upvars (i.e. the ones computed from HIR by the |
Although, hang on @nikomatsakis, the upvars in the type are what layouts are computed from. |
@eddyb I don't remember to what extent we worked out an answer to that question. Obviously, the more "field paths" we are able to capture, the fewer errors you get from borrow checking (i.e., because we are borrowing more precise paths), but there is also a bit of overhead in that the number of capturing things go up. At the moment, I am mostly interested in laying the groundwork that allows the number of upvar paths to be inferred. I think we're going to want this no matter what we do. |
I guess there's no harm in separately borrowing paths as long as it's opt-in behind the feature-gate, and we don't apply it to stable code (wait, that'd be bad anyway because it would have the borrowck effects, so there's no way stable code is affected size-wise at all). |
@blitzerr To elaborate a bit on the context (let me know if this helps):
|
@nikomatsakis So I guess my dumb question is if we are not creating the tuple of upvars here then what shall we do here? https://github.com/rust-lang/rust/blob/1a87c49e33d87955e28fa92a8d59a17264ac6044/src/librustc_typeck/check/closure.rs#L91-L101 Go back to what it used to be here ? |
@blitzerr not a dumb question, and yes, I think we would go back to the older behavior -- so we would just create a plain old type variable, instead of a tuple of type variables. Then we'd have to modify the upvar code that is iterating over the upvar types: so that it instead does something like // Build a tuple (U0..Un) of the final upvar types U0..Un
// and unify the upvar tupe type in the closure with it:
let final_upvar_tuple_type = tcx.mk_tuple(final_upvar_tys);
self.demand_suptype(span, substs.upvar_tuple_ty(), final_upvar_tuple_ty); |
Thanks a lot @nikomatsakis Will get on it. |
@blitzerr let me know how it goes :) |
Depends on #7 |
Update:
|
…losures, r=nikomatsakis Replace tuple of infer vars for upvar_tys with single infer var This commit allows us to decide the number of captures required after completing capture ananysis, which is required as part of implementing RFC-2229. closes rust-lang/project-rfc-2229#4 r? `@nikomatsakis`
closed by rust-lang/rust#77873 |
Updated by nikomatsakis with current status:
In rust-lang/rust#69968, @eddyb landed the "first step" here of introducing a tuple into the upvar types. However, in current rustc, we create that tuple "eagerly", as soon as we create the closure type:
https://github.com/rust-lang/rust/blob/1a87c49e33d87955e28fa92a8d59a17264ac6044/src/librustc_typeck/check/closure.rs#L90-L103
The next step is to move that tuple creation "late", so that it occurs during the "upvar analysis" code, so somewhere around here:
https://github.com/rust-lang/rust/blob/1a87c49e33d87955e28fa92a8d59a17264ac6044/src/librustc_typeck/check/upvar.rs#L194-L202
The problem with this is that the current accessor,
ClosureSubsts::upvar_tys
, assumes that the upvar types are a tuple with known arity. Thus any calls toupvar_tys
that occur before the upvar analysis code runs will ICE.Last time, we added an accessor
upvar_tuple_ty
that returned the tuple itself (or an unbound type variable), since it turned out that many of the calls toupvar_tys
could be replaced by a call that operated on the tuple. Most notably, in the trait system, for example here:https://github.com/rust-lang/rust/blob/1a87c49e33d87955e28fa92a8d59a17264ac6044/src/librustc_trait_selection/traits/select.rs#L2239-L2242
We changed this to yield the tuple always. The problem with that was that it was effecting the error messages, because the tuple was being introduced into the "backtrace" and we somehow never got things quiite right to remove it.
I still think that is perhaps the right approach, but there is an alternative we could try: we could get the tuple ty and check whether it's been "resolved" yet (via a call to
self.infcx.shallow_resolve
). If so, we can put each of its components as we do today, but if not, we can returnAmbiguous
, as we do here.The text was updated successfully, but these errors were encountered: