-
Notifications
You must be signed in to change notification settings - Fork 13k
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
polymorphize: I
used if T
used in I: Foo<T>
#75518
polymorphize: I
used if T
used in I: Foo<T>
#75518
Conversation
This commit adjusts polymorphization's handling of predicates so that after ensuring that `T` is used in `I: Foo<T>` if `I` is used, it now ensures that `I` is used if `T` is used in `I: Foo<T>`. This is necessary to mark generic parameters that only exist in impl parameters as used - thereby avoiding symbol clashes when using the new mangling scheme. Signed-off-by: David Wood <[email protected]>
f80f2da
to
bf3ef26
Compare
While I think that this restriction is somewhat unfortunate this does look correct to me now. @bors r+ rollup |
📌 Commit bf3ef26 has been approved by |
@@ -318,3 +373,36 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UsedGenericParametersVisitor<'a, 'tcx> { | |||
} | |||
} | |||
} | |||
|
|||
/// Visitor used to check if a generic parameter is used. | |||
struct IsUsedGenericParams<'a> { |
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.
Maybe this should be called HasUsedGenericParams
?
debug!("mark_used_by_predicates: checking projection ty"); | ||
if is_ty_used(unused_parameters, proj.ty) { | ||
debug!("mark_used_by_predicates: used!"); | ||
mark_ty(unused_parameters, self_ty); |
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 think this is overly simplistic, I suspect you can replace I: Iterator<...>
with (): WeirdIterator<I, ...>
.
Any treatment of the Self
parameter as special is suspicious by default, IMO.
// Consider `T` used if `I` is used in predicates of the form | ||
// `I: Iterator<Item = T>` | ||
debug!("mark_used_by_predicates: checking self"); | ||
if is_ty_used(unused_parameters, trait_ref.self_ty()) { | ||
debug!("mark_used_by_predicates: used!"); | ||
for ty in trait_ref.substs.types() { | ||
mark_ty(unused_parameters, ty); | ||
} | ||
|
||
// No need to check for a type being used in the substs if `self_ty` was | ||
// used. | ||
continue; | ||
} | ||
|
||
// Consider `I` used if `T` is used in predicates of the form | ||
// `I: Iterator<Item = &'a (T, E)>` (see rust-lang/rust#75326) | ||
debug!("mark_used_by_predicates: checking substs"); | ||
for ty in trait_ref.substs.types() { | ||
debug!("unused_generic_params: (trait) ty={:?}", ty); | ||
mark_ty(unused_parameters, ty); | ||
if is_ty_used(unused_parameters, ty) { | ||
debug!("mark_used_by_predicates: used!"); | ||
mark_ty(unused_parameters, trait_ref.self_ty()); | ||
} | ||
} | ||
} |
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 sounds like an overly complicated way to handle "if any parameters are used, all are".
Notable strangeness:
substs.types()
will includeself_ty
so some of this code already seems redundant with itself.types()
makes me wonder: what about const generics?
☀️ Test successful - checks-actions, checks-azure |
I'll address @eddyb's comments in a follow-up. |
…simplification-correction, r=eddyb polymorphize: if any param in a predicate is used, then all are used Addresses [review](rust-lang#75518 (comment)) [comments](rust-lang#75518 (comment)) [from](rust-lang#75518 (comment)) @eddyb in rust-lang#75518 that I didn't get to resolve before bors merged. This PR modifies polymorphization's handling of predicates so that if any generic parameter is used in a predicate then all parameters in that predicate are used. r? @eddyb
Fixes #75326.
This PR adjusts polymorphization's handling of predicates so that after ensuring that
T
is used inI: Foo<T>
ifI
is used, it now ensures thatI
is used ifT
is used inI: Foo<T>
. This is necessary to mark generic parameters that only exist in impl parameters as used - thereby avoiding symbol clashes when using the new mangling scheme.With this PR, rustc will now fully bootstrap with polymorphization and the new symbol mangling scheme enabled - not all tests pass, but I'm not sure how much of that is the interaction of the two features, I'll be looking into that soon. All tests pass with only polymorphization enabled.
r? @lcnr (this isn't sufficiently complex that I need to add to eddy's review queue)
cc @eddyb