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

Switch to EarlyBinder for collect_return_position_impl_trait_in_trait_tys #110498

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

kylematsuda
Copy link
Contributor

Part of the work to finish #105779.

This PR adds EarlyBinder to the return type of the collect_return_position_impl_trait_in_trait_tys query and removes bound_return_position_impl_trait_in_trait_tys.

r? @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 18, 2023
@@ -579,7 +579,7 @@ fn compare_asyncness<'tcx>(
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m_def_id: LocalDefId,
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
) -> Result<ty::EarlyBinder<&'tcx FxHashMap<DefId, Ty<'tcx>>>, ErrorGuaranteed> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be EarlyBinder<Result<T, E>> in the return type of bound_return_position_impl_trait_in_trait_tys, but I changed it to Result<EarlyBinder<T>, E> to be more consistent with some of the other queries (like impl_trait_ref). Does it seem alright like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter. Whichever one's easier to use.

@@ -1328,7 +1328,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if tcx.impl_method_has_trait_impl_trait_tys(def_id)
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
{
record!(self.tables.trait_impl_trait_tys[def_id] <- table);
record!(self.tables.trait_impl_trait_tys[def_id] <- table.skip_binder());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super happy with having to skip_binder here and then add it back in the decoding stage (cstore_impl.rs), but I had some trouble storing the EarlyBinder directly in the metadata table and this seemed like the simplest alternative

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't like this either. What trouble exactly were you having here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's during the encoding stage (record! call above). The query returns an EarlyBinder<&'tcx HashMap<..>>, but the type would be stored in the table as LazyValue<EarlyBinder<HashMap<..>>> (without the borrow inside the EarlyBinder). The record! macro above works automatically if the EarlyBinder isn't there, but if it is, it gives a type error about getting EarlyBinder<&HashMap> instead of EarlyBinder<HashMap>.

I'll play around with it a bit, I might just be missing an easy way to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's due to this signature of fn lazy<T: ParameterizedOverTcx, B: Borrow<T::Value<'tcx>>>(..). When the EarlyBinder isn't there, we have no trouble encoding HashMap<K, V> using a &HashMap<K, V>, but the early binder is messing up the deref I think...?

Anyways, maybe it's actually better to store the EarlyBinder inside of the values of the hashmap, i.e. make it a HashMap<DefId, EarlyBinder<Ty<'tcx>>>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense!

Sounds good, I'll try putting the EarlyBinder around the Ty. I was actually considering that initially, just wasn't sure if it was intentionally around the whole HashMap before. Do those two things convey slightly different meanings? EarlyBinder<HashMap<..>> suggests to me that there is one substs for all of the hashmap values, while HashMap<DefId, EarlyBinder<Ty>> suggests that each Ty could have a different substs. (But I'm not sure if that distinction actually matters in practice...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm could it maybe also work as Result<&'tcx EarlyBinder<HashMap<DefId, Ty<'tcx>>>, Error> instead of Result<EarlyBinder<&'tcx HashMap<DefId, Ty>>, Error>?

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 a HashMap<DefId, EarlyBinder<Ty<'tcx>>> is the best representation of the data here, and it probably simplifies the indexing that we do in project.rs if the values are wrapped in early binders instead of the whole hashmap.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do those two things convey slightly different meanings?

Uh, it could I guess? It doesn't really matter in practice, yeah.

In my head, wrapping the whole HashMap in an EarlyBinder signifies that the whole hashmap should be substituted all at once, where we never do that in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay thanks! I'll change it to that then 👍

.map_or_else(
|guar| ty::EarlyBinder(tcx.ty_error(guar)),
|tys| tys.map_bound(|tys| tys[&obligation.predicate.def_id]),
)
.subst(tcx, impl_fn_substs),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably just push this subst call into the "Ok" branch of the map_or_else, rather than wrapping the ty::Error in a binder.

@rustbot rustbot added the A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) label Apr 18, 2023
@compiler-errors
Copy link
Member

@kylematsuda can you squash this into one commit? We don't need so many commits, especially for example 5c49e1e243cc745c86316ec39817f60de9f69c53 which undoes a commit that's lower in the stack.

After that I can approve. Thanks!

@kylematsuda
Copy link
Contributor Author

Okay, squashed. Thanks!!

@compiler-errors
Copy link
Member

r? @compiler-errors @bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 18, 2023

📌 Commit 522bc5f has been approved by compiler-errors

It is now in the queue for this repository.

@rustbot rustbot assigned compiler-errors and unassigned lcnr Apr 18, 2023
@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 Apr 18, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#110432 (Report more detailed reason why `Index` impl is not satisfied)
 - rust-lang#110451 (Minor changes to `IndexVec::ensure_contains_elem` & related methods)
 - rust-lang#110476 (Delay a good path bug on drop for `TypeErrCtxt` (instead of a regular delayed bug))
 - rust-lang#110498 (Switch to `EarlyBinder` for `collect_return_position_impl_trait_in_trait_tys`)
 - rust-lang#110507 (boostrap: print output during building tools)
 - rust-lang#110510 (Fix ICE for transmutability in candidate assembly)
 - rust-lang#110513 (make `non_upper_case_globals` lint not report trait impls)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9f0b16b into rust-lang:master Apr 19, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 19, 2023
@kylematsuda kylematsuda deleted the earlybinder-rpitit-tys branch April 19, 2023 15:55
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 25, 2023
…tem-bounds, r=compiler-errors

Switch to `EarlyBinder` for `explicit_item_bounds`

Part of the work to finish rust-lang#105779.

This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`.

r? `@compiler-errors` (hope it's okay to request you, since you reviewed rust-lang#110299 and rust-lang#110498 😃)
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 5, 2023
…tem-bounds, r=compiler-errors

Switch to `EarlyBinder` for `explicit_item_bounds`

Part of the work to finish rust-lang#105779.

This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`.

r? `@compiler-errors` (hope it's okay to request you, since you reviewed rust-lang#110299 and rust-lang#110498 😃)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants