Get rid of StructurallyRelateAliases#158731
Conversation
|
changes to the core type system cc @lcnr |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| (ty::Infer(ty::TyVar(a_vid)), _) => { | ||
| infcx.equate_ty_var_raw(a_vid, b); |
There was a problem hiding this comment.
can you add a debug_assert to instantiate_ty_var_raw tht the type we instantiate it with does not refer to anything from a higher universe?
There was a problem hiding this comment.
same for regions and consts :>
There was a problem hiding this comment.
The debug_assert in instantiate_ty_var_eq_raw would make tests/ui/async-await/async-closures/post-mono-higher-ranked-hang.rs hang again, probably due to max_universe being slow on deeply nested types.
And these asserts are likely unnecessary as we need to replace the universes anyway? We do meet higher universes in response. Generalization handles this by creating infer vars in current universe and I copied that.
We can't assert for regions either as we encounter higher universes in response var_values.
In proof tree visitor we have newly created original_values in lower universe.
Related #154329 (comment)
There was a problem hiding this comment.
hmm, having this assert right after we have a type folder whicih should do it correctly feels 🤷 to me
I worry about type_variables().instantiate more generally and would love to have that assert in there.
The
debug_assertininstantiate_ty_var_eq_rawwould maketests/ui/async-await/async-closures/post-mono-higher-ranked-hang.rshang again, probably due tomax_universebeing slow on deeply nested types.
does the max_universe visitor use a cache?
| let a = infcx.shallow_resolve_const(a); | ||
| let b = infcx.shallow_resolve_const(b); |
There was a problem hiding this comment.
we should be able to not do that but debug_assert that this is a noop?
There was a problem hiding this comment.
partially, see the fixme.
| if let Some(a_inner) = a.no_bound_vars() | ||
| && let Some(b_inner) = b.no_bound_vars() |
There was a problem hiding this comment.
a and b have exactly the same bound vars here. we don't have to bother with the rebinding 🤔 actually, we can just recurse without instantiating bound vars at all
we can just assert that the bound vars are equal, and then recurse :>
This comment has been minimized.
This comment has been minimized.
4a27c1d to
5920ca5
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…=<try> Get rid of `StructurallyRelateAliases`
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a8102e7): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 2.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -11.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 488.508s -> 490.377s (0.38%) |
| self.inner.borrow_mut().const_unification_table().union(a, b); | ||
| } | ||
|
|
||
| fn instantiate_ty_var_eq_raw(&self, vid: ty::TyVid, ty: Ty<'tcx>) { |
There was a problem hiding this comment.
rename instantiate_ty_var_raw to generalize_and_instantiate_ty_var_raw maybe? Not a big fan of the eq in instantiate_ty_var_eq_raw
actually, just rename it to instantiate_ty_var. I don't think the _raw is useful and its impl is called instantiate_ty_var already
| return answer; | ||
| } | ||
|
|
||
| let folded = if let ty::Infer(ty::TyVar(vid)) = t.kind() { |
There was a problem hiding this comment.
can you change this to a match and also add an assert that the universe of placeholders is "correct"
There was a problem hiding this comment.
or I guess don't handle placeholders but do keep the debug_assert 🤔
| // We always set the universes in generalized term to the infer var's | ||
| // in generalization, if those universes are higher than the infer var's. | ||
| // We replicate the behavior here. | ||
| struct UniverseFolder<'a, 'tcx> { |
There was a problem hiding this comment.
| // We always set the universes in generalized term to the infer var's | |
| // in generalization, if those universes are higher than the infer var's. | |
| // We replicate the behavior here. | |
| struct UniverseFolder<'a, 'tcx> { | |
| /// Canonicalizing inputs puts all inference variables and placeholders | |
| /// into the root universe. | |
| /// | |
| /// This means when instantiating the query response we need to pull | |
| /// down the universe of returned `var_values` to the universe of | |
| /// the inference variable in `orig_values`. | |
| /// | |
| /// This folder is similar to the `Generalizer`, except that it simply | |
| /// structurally folds non-rigid aliases as these should have already | |
| /// been generalized in the query so we shouldn't try to do it again. | |
| struct LowerUniverseFolder<'a, 'tcx> { |
| } | ||
| } | ||
|
|
||
| impl<Infcx, I> PredicateEmittingRelation<Infcx> for ResponseRelating<'_, Infcx, I> |
There was a problem hiding this comment.
given that we don't use super_combine, do we even need to implement this?
| return answer; | ||
| } | ||
|
|
||
| let folded = if let ty::Infer(ty::TyVar(vid)) = t.kind() { |
There was a problem hiding this comment.
or I guess don't handle placeholders but do keep the debug_assert 🤔
5920ca5 to
33d6455
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. |
|
The job Click to see the possible cause of the failure (guessed by this bot)Important For more information how to resolve CI failures of this job, visit this link. |
| debug_assert!( | ||
| self.for_universe.can_name(p.universe), | ||
| "variable in universe {:?} can't name type in universe {:?}", | ||
| self.for_universe, | ||
| p.universe | ||
| ); |
There was a problem hiding this comment.
can you instead do a separate max_universe check after this folder has returned. Given that we have a fast path for
if !(t.has_free_regions() || t.has_infer()) {
return t;
}
this is unreachable
| @@ -1,3 +1,4 @@ | |||
| use rustc_data_structures::fx::FxHashSet; | |||
There was a problem hiding this comment.
we should lint on using rustc_data_structures in rustc_type_ir as it breaks rustanalyzer.
there's rustc_type_ir::data_structures::HashMap instead
| // FIXME: make this a debug_assert. | ||
| // Currently proof tree evaluation can unify infer vars in original | ||
| // vars while not resolving them. | ||
| // See `tests/ui/traits/next-solver/transmute-from-async-closure.rs` |
There was a problem hiding this comment.
I feel like proof tree evaluation really shouldn't use this at all 😁
proof trees are just generally deeply annoying 😅 :x I guess this is fine for now
View all comments
Part of #155345
Finally we can get rid of the last use of
StructurallyRelateAliases::Yes.r? lcnr