-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Downgrade ProjectionTy's TraitRef to its substs #42388
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/librustc/ty/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty::tls::with
is not for regular consumption, only for pretty-printing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gone now thanks to your other comment.
src/librustc/ty/structural_impls.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, use folder.tcx()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/ty/structural_impls.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, use visitor.tcx()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No such thing, unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right, visitor. You'll have to update all the implementers that overload visit_trait_ref
to handle TyProjection
themselves. At this rate I doubt visit_trait_ref
is useful anymore since it shouldn't appear in a Ty
. What you have to do here fwiw is to visit only substitutions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should just replace this code with:
let ty::ProjectionTy { ref substs, item_def_id: _ } = *self;
substs.visit_with(visitor)
and be done with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/util/ppaux.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is okay, I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I don't think I agree with the indentation, the closure arguments should be on the previous line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to change the indentation to what you prefer. In the meantime, moved |tcx|
up where it belongs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said, I think this can use parametrized
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass tcx
in from the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still have two more cases here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/traits/trans/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prof.item_def_id
might be good enough? cc @nikomatsakis @michaelwoerister
src/librustc/ty/instance.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #42388 (comment)
src/librustc/ty/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't implement ToPolyTraitRef
- nor does that make sense IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean/what would you like me to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the ToPolyTraitRef
impl and see what breaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still applicable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I track all comments that I haven't answered in the affirmative.
Removing the impl breaks, among other places, process_predicate
:
ty::Predicate::Projection(ref data) => {
let project_obligation = obligation.with(data.clone());
match project::poly_project_and_unify_type(selcx, &project_obligation) {
Ok(None) => {
pending_obligation.stalled_on =
trait_ref_type_vars(selcx, data.to_poly_trait_ref());
Ok(None)
}
Ok(v) => Ok(v),
Err(e) => Err(CodeProjectionError(e))
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that could do the work itself. Not sure if data.trait_ref(tcx).to_poly_trait_ref()
works though (it might assert).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, going through .trait_ref
wouldn't work, TraitRef::to_poly_trait_ref
will assert, you need to move this to an inherent method that takes TyCtxt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @eddyb that it is what dubious for this type to implement to_poly_trait_ref
. An inherent function seems better. Basically is converting a predicate like T: Iterator<Item=Foo>
into the underlying T: Iterator
trait-reference -- that's not wrong, but it feels like it merits an explicit "cast". This was (however) equally true before, I guess -- but still better to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm looking at this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Moved the method off the trait, supplied the tcx in the ~4 call sites.
src/librustc/ty/mod.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace trait_inputs
with data.substs.types()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (assume you mean changing to data.0.projection_ty.substs.types().chain(Some(data.0.ty)).collect()
☔ The latest upstream changes (presumably #42189) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mk_projection
should not do the lookup itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you are suggesting that mk_projection
should change its signature, and in particular likely take item_def_id
directly? Before I go wild on this, what would the final signature be? There would be some fallout, some call sites have exactly trait_ref
and item_name
available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefId
and Substs
. No callsites should really need to search for the associated item if they don't already, e.g. anything to do with lang item traits with an associated type should just get the associated type ignoring its name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Did the easy part of this - some call sites remain. I'll take another look at those. For example, what am I doing below? Refactor ast_path_to_mono_trait_ref
?
let trait_ref = self.ast_path_to_mono_trait_ref(span,
trait_def_id,
self_ty,
trait_segment);
debug!("qpath_to_ty: trait_ref={:?}", trait_ref);
self.normalize_ty(span, tcx.mk_deprecated_projection(trait_ref, item_segment.name))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is where trait_def_id
comes from there - there should be an associated type DefId somewhere, and you can combine that with trait_ref.substs
.
src/librustc/traits/project.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed this is projection_ty.item_def_id
. In general avoid using the new trait_ref
method where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/traits/project.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, looks like an earlier PR didn't clean all of these up. Calls of item_name
should also be rare.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/traits/project.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to call trait_ref
to get something from the substs. Maybe add self_ty
to ProjectionTy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/ty/relate.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relate substitutions directly. Also the name check above is silly now, should check DefId
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/ty/structural_impls.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should lift substitutions instead. from_ref_and_name
should likely not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (from_ref_and_name
still exists, but I'll keep knocking 'em down and when you're satisfied look at the whole diff again to see what else can go).
src/librustc/ty/structural_impls.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can folding a trait ref be overloaded? i.e. is there any fold_trait_ref
? If not you can just fold substitutions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's this:
fn fold_trait_ref(&mut self, p: TraitRef) -> TraitRef {
noop_fold_trait_ref(p, self)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it overloaded by anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm I think I removed on master recently. So no, it wasn't needed, you can just fold substs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fold_trait_ref
should be gone now. Oh wait. What you found is an AST folder facepalms.
Apologies, you could've done this before the rebase too. Just fold the substs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc/ty/sty.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation is off to the right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. WDYT about the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Irrelevant and there is a method to get the DefId
anyway, that'd make this cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, here and in the other place.
src/librustc/ty/walk.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc_privacy/lib.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just call proj.substs.visit_with
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc_save_analysis/lib.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unnecessary search for a DefId
that is already known.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/librustc_typeck/astconv.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reminds me that ExistentialProjection
also needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
Thanks @eddyb! Addressed parts of your comments, will come back to the rest later. Avoiding the rebase intentionally for now until the dust has settled. |
src/librustc_typeck/astconv.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably just work on .item_def_id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
☔ The latest upstream changes (presumably #43008) made this pull request unmergeable. Please resolve the merge conflicts. |
ping @nikomatsakis - rebased & green. |
@bors r+ |
📌 Commit 0d436ed has been approved by |
⌛ Testing commit 0d436edf030c4afea671069456e1f0084040d1dd with merge 63ff04c3ec23fe9760cc9fe876a3c5d7b989f0d4... |
💔 Test failed - status-travis |
b2cd0bf
to
3166a02
Compare
The new commits look good to me. r=me, did you want to fixup first though? (your comment titles suggest you did :) |
Yep, done. Ready to hit the queue. |
@bors r+ |
📌 Commit 0b321bf has been approved by |
⌛ Testing commit 0b321bfe9b47fb4114968497ed3a4cb50b017b70 with merge 5a89479419a0b2823a93041206ed0dad2dc16feb... |
💔 Test failed - status-travis |
☔ The latest upstream changes (presumably #43028) made this pull request unmergeable. Please resolve the merge conflicts. |
Addresses the second part of rust-lang#42171 by removing the `TraitRef` from `ProjectionTy`, and directly storing its `Substs`. Closes rust-lang#42171.
@bors r+ |
📌 Commit 687ee7f has been approved by |
☀️ Test successful - status-appveyor, status-travis |
Addresses the second part of #42171 by removing the
TraitRef
fromProjectionTy
, and directly storing itsSubsts
.Closes #42171.