Normalize capture place tys to prevent ICE#152165
Normalize capture place tys to prevent ICE#152165JohnTitor wants to merge 9 commits intorust-lang:mainfrom
tys to prevent ICE#152165Conversation
This comment has been minimized.
This comment has been minimized.
| HirPlaceBase::Upvar(upvar_id) => { | ||
| ty::TypingEnv::post_analysis(tcx, upvar_id.closure_expr_id) | ||
| } | ||
| _ => ty::TypingEnv::fully_monomorphized(), |
There was a problem hiding this comment.
This is hacky and subtly wrong in two ways.
- even if the type is not from an upvar, we still need the right param_env to normalize
- we use this during MIR build, so it should probably use
TypingMode::Borrowckor whatever
see https://rustc-dev-guide.rust-lang.org/typing-parameter-envs.html
There was a problem hiding this comment.
Ah I see, I've switched to use try_structurally_resolve_ty as mentioned in the issue: 176bf7d (this PR)
This way, we can avoid deep normalization here, right?
a544343 to
176bf7d
Compare
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| fn try_structurally_resolve_place_ty(&self, span: Span, place: &mut Place<'tcx>) { | ||
| place.base_ty = self.try_structurally_resolve_type(span, place.base_ty); |
There was a problem hiding this comment.
use deeply_normalize here. We deeply normalize types in the writeback results, so I think we should do the same here
There was a problem hiding this comment.
Just replacing didn't work so I had to do something like this instead: 750cd53
Is this what you meant for?
There was a problem hiding this comment.
can you use at.deeply_normalize with both solvers?
There was a problem hiding this comment.
I've tried but had to construct TraitEngine there which seems an unusual way (I haven't seen such a way in other places).
Instead, I guess using ObligationCtxt might be better here, other places do this way and it shoudl call at.deeply_normalize internally: a7ea420
How about this?
| UpvarMigrationInfo::CapturingPrecise { | ||
| source_expr: capture.info.path_expr_id, | ||
| var_name: capture.to_string(self.tcx), | ||
| var_name: self.place_to_string_for_migration(capture), |
There was a problem hiding this comment.
can we move this normalization even further up so that catpure.place is already deeply normalized and we don't have to do so here?
There was a problem hiding this comment.
Moved: c22ffdb
I wonder if we should reduce scope by if next_solver as we now normalize stuff more generally, i.e. other than emitting lint rust_2021_incompatible_closure_captures and it would bring unnecessary cost for most cases 🤔
a7ea420 to
c22ffdb
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| fn try_structurally_resolve_place_ty(&self, span: Span, place: &mut Place<'tcx>) { |
There was a problem hiding this comment.
deeply_normalize should normalize arbitrary TypeFoldable things. Is Place type foldable?
Also, change this function name :>
c22ffdb to
88036b0
Compare
This comment has been minimized.
This comment has been minimized.
88036b0 to
7def3bc
Compare
|
I messed up by reviewing your commit directly yesterday, see c22ffdb#r177216090 |
7def3bc to
ecdea2c
Compare
This comment has been minimized.
This comment has been minimized.
|
|
||
| assert_eq!(self.tcx.hir_body_owner_def_id(body.id()), closure_def_id); | ||
|
|
||
| // Used by `ExprUseVisitor` when collecting closure capture information. |
There was a problem hiding this comment.
This comment feels is odd. It states information which is clearly visible 3 lines down. You could state sth like "We need to create a separate FnCtxt for nested bodies"
Creating FnCtxts for nested bodies is also something we normally do, so I don't know if that is that useful either. I think it's fine to just not have a comment here at all
| } | ||
| fn normalize_capture_place(&self, span: Span, place: &mut Place<'tcx>) { | ||
| *place = self.resolve_vars_if_possible(place.clone()); | ||
|
|
There was a problem hiding this comment.
why &mut Place instead of taking by value and returning it again?
| restrict_capture_precision(place_with_id.place.clone(), dummy_capture_kind); | ||
| let span = self.fcx.tcx.hir_span(diag_expr_id); | ||
| let mut place = place_with_id.place.clone(); | ||
| self.fcx.normalize_capture_place(span, &mut place); |
There was a problem hiding this comment.
could also eagerly normalize closure_fake_reads 🤔
There was a problem hiding this comment.
though, I guess this is fine for now as making sure the ExprUseVisitor always handles things correctly seems like a bigger change
There was a problem hiding this comment.
Alright, should I add FIXME or something else?
This comment was marked as off-topic.
This comment was marked as off-topic.
5e5de59 to
dddbf96
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
(rebase mistake, sorry for pinging) |
Fixes #151579
Fixes #120811
r? @lcnr