-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Shallow resolve ty and const vars to their root vars, attempt 2 #158447
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
Open
jdonszelmann
wants to merge
8
commits into
rust-lang:main
Choose a base branch
from
jdonszelmann:shallow-resolve-to-root-var
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b2a4942
add tests and demonstrate them working before changes
jdonszelmann fa6488f
Bump `ena`
ShoyuVanilla 9fb3736
Shallow resolve ty and const vars to their root vars
ShoyuVanilla eeaa3cd
Remove redundant `shallow_resolve` call
ShoyuVanilla 008941a
Bless tests
ShoyuVanilla f658490
bless tests that didn't exist in attempt 1
jdonszelmann 3bf1fd3
demonstrate test fail after change
jdonszelmann 31352b1
dont fudge if the output is structuarlly similar to the expectation
jdonszelmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,12 @@ use rustc_hir::{Expr, ExprKind, FnRetTy, HirId, LangItem, Node, QPath, is_range_ | |
| use rustc_hir_analysis::check::potentially_plural_count; | ||
| use rustc_hir_analysis::hir_ty_lowering::{HirTyLowerer, ResolvedStructPath}; | ||
| use rustc_index::IndexVec; | ||
| use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TypeTrace}; | ||
| use rustc_infer::infer::{ | ||
| BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TypeTrace, relate, | ||
| }; | ||
| use rustc_middle::ty::adjustment::AllowTwoPhase; | ||
| use rustc_middle::ty::error::TypeError; | ||
| use rustc_middle::ty::error::{ExpectedFound, TypeError}; | ||
| use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; | ||
| use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, Unnormalized}; | ||
| use rustc_middle::{bug, span_bug}; | ||
| use rustc_session::Session; | ||
|
|
@@ -278,12 +281,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
| formal_input_tys | ||
| .iter() | ||
| .map(|&ty| self.resolve_vars_if_possible(ty)) | ||
| .collect(), | ||
| .collect::<Vec<_>>(), | ||
| )) | ||
| }) | ||
| .ok() | ||
| }) | ||
| .unwrap_or_default(); | ||
| .unwrap_or_default() | ||
| .map(|expected_input_tys| { | ||
| expected_input_tys | ||
| .into_iter() | ||
| .zip(formal_input_tys) | ||
| // if the expected input type is structurally equal to the formal input type, | ||
| // i.e. we've only changed some inference variables around, keep the formal | ||
| // input ty as the expected input ty. | ||
| .map(|(expected_input_ty, formal_input_ty)| { | ||
| if same_type_modulo_vars(tcx, expected_input_ty, *formal_input_ty) { | ||
| // if they're the same, fall back to the formal input type | ||
| *formal_input_ty | ||
| } else { | ||
| expected_input_ty | ||
| } | ||
| }) | ||
| .collect() | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can move this map right after the |
||
|
|
||
| let mut err_code = E0061; | ||
|
|
||
|
|
@@ -3519,3 +3539,98 @@ enum SuggestionText { | |
| Reorder, | ||
| DidYouMean, | ||
| } | ||
|
|
||
| fn same_type_modulo_vars<'tcx>(tcx: TyCtxt<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool { | ||
| struct SameModuloVars<'tcx> { | ||
| tcx: TyCtxt<'tcx>, | ||
| } | ||
| impl<'tcx> TypeRelation<TyCtxt<'tcx>> for SameModuloVars<'tcx> { | ||
| fn cx(&self) -> TyCtxt<'tcx> { | ||
| self.tcx | ||
| } | ||
|
|
||
| fn relate_ty_args( | ||
| &mut self, | ||
| a_ty: Ty<'tcx>, | ||
| _b_ty: Ty<'tcx>, | ||
| _ty_def_id: DefId, | ||
| a_args: ty::GenericArgsRef<'tcx>, | ||
| b_args: ty::GenericArgsRef<'tcx>, | ||
| _mk: impl FnOnce(ty::GenericArgsRef<'tcx>) -> Ty<'tcx>, | ||
| ) -> RelateResult<'tcx, Ty<'tcx>> { | ||
| relate::relate_args_invariantly(self, a_args, b_args)?; | ||
| Ok(a_ty) | ||
| } | ||
|
|
||
| fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>( | ||
| &mut self, | ||
| _variance: ty::Variance, | ||
| _info: ty::VarianceDiagInfo<TyCtxt<'tcx>>, | ||
| a: T, | ||
| b: T, | ||
| ) -> RelateResult<'tcx, T> { | ||
| self.relate(a, b) | ||
| } | ||
|
|
||
| fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { | ||
| if a == b { | ||
| return Ok(a); | ||
| } | ||
|
|
||
| match (a.kind(), b.kind()) { | ||
| (&ty::Infer(ty::InferTy::TyVar(_)), &ty::Infer(ty::InferTy::TyVar(_))) | ||
| | (&ty::Infer(ty::InferTy::FloatVar(_)), &ty::Infer(ty::InferTy::FloatVar(_))) | ||
| | (&ty::Infer(ty::InferTy::IntVar(_)), &ty::Infer(ty::InferTy::IntVar(_))) => Ok(a), | ||
| (&ty::Infer(_), _) | (_, &ty::Infer(_)) => Err(TypeError::Mismatch), | ||
| (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(Ty::new_error(self.cx(), guar)), | ||
| _ => relate::structurally_relate_tys(self, a, b), | ||
| } | ||
| } | ||
|
|
||
| fn regions( | ||
| &mut self, | ||
| a: ty::Region<'tcx>, | ||
| _b: ty::Region<'tcx>, | ||
| ) -> RelateResult<'tcx, ty::Region<'tcx>> { | ||
| Ok(a) | ||
| } | ||
|
|
||
| fn consts( | ||
| &mut self, | ||
| mut a: ty::Const<'tcx>, | ||
| mut b: ty::Const<'tcx>, | ||
| ) -> RelateResult<'tcx, ty::Const<'tcx>> { | ||
| if a == b { | ||
| return Ok(a); | ||
| } | ||
|
|
||
| if self.tcx.features().generic_const_exprs() { | ||
| a = self.tcx.expand_abstract_consts(a); | ||
| b = self.tcx.expand_abstract_consts(b); | ||
| } | ||
|
|
||
| match (a.kind(), b.kind()) { | ||
| (ty::ConstKind::Infer(_), ty::ConstKind::Infer(_)) => return Ok(a), | ||
| (ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => { | ||
| return Err(TypeError::ConstMismatch(ExpectedFound::new(a, b))); | ||
| } | ||
| _ => {} | ||
| } | ||
|
|
||
| relate::structurally_relate_consts(self, a, b) | ||
| } | ||
|
|
||
| fn binders<T>( | ||
| &mut self, | ||
| a: ty::Binder<'tcx, T>, | ||
| b: ty::Binder<'tcx, T>, | ||
| ) -> RelateResult<'tcx, ty::Binder<'tcx, T>> | ||
| where | ||
| T: Relate<TyCtxt<'tcx>>, | ||
| { | ||
| Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?)) | ||
| } | ||
| } | ||
|
|
||
| SameModuloVars { tcx }.relate(a, b).is_ok() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
should mention why we do this :>
View changes since the review