Skip to content
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

Conversation

davidtwco
Copy link
Member

Fixes #75326.

This PR 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.

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2020
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 <david@davidtw.co>
@davidtwco davidtwco force-pushed the issue-75326-polymorphization-symbol-mangling-v0-predicates branch from f80f2da to bf3ef26 Compare August 14, 2020 22:01
@davidtwco davidtwco requested a review from lcnr August 14, 2020 22:01
@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2020

While I think that this restriction is somewhat unfortunate this does look correct to me now.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 14, 2020

📌 Commit bf3ef26 has been approved by lcnr

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2020
@@ -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> {
Copy link
Member

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);
Copy link
Member

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.

Comment on lines +152 to 175
// 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());
}
}
}
Copy link
Member

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 include self_ty so some of this code already seems redundant with itself
  • .types() makes me wonder: what about const generics?

@bors
Copy link
Contributor

bors commented Aug 15, 2020

⌛ Testing commit bf3ef26 with merge 1e58871...

@bors
Copy link
Contributor

bors commented Aug 15, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: lcnr
Pushing 1e58871 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 15, 2020
@bors bors merged commit 1e58871 into rust-lang:master Aug 15, 2020
@davidtwco davidtwco deleted the issue-75326-polymorphization-symbol-mangling-v0-predicates branch August 15, 2020 12:00
@davidtwco
Copy link
Member Author

I'll address @eddyb's comments in a follow-up.

@davidtwco
Copy link
Member Author

Filed #75595 to address @eddyb's comments.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 20, 2020
…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
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol ambiguity with polymorphization and new mangling scheme
6 participants