-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Add TyAlias into rustc_type_ir TyKind enum #97974
Closed
GuillaumeGomez
wants to merge
28
commits into
rust-lang:master
from
GuillaumeGomez:rustc-middle-ty-alias
Closed
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a197c45
Add rustc_type_ir::TyKind::TyAlias variant
GuillaumeGomez 61705b3
Add TyKind::TyAlias support in rustc_middle
GuillaumeGomez ed3f028
Add TyKind::TyAlias support in rustc_symbol_mangling
GuillaumeGomez 2a25b28
Add TyKind::TyAlias support in rustc_infer
GuillaumeGomez 71357dc
Add TyKind::TyAlias support in rustc_codegen_ssa
GuillaumeGomez 02ee18f
Add TyKind::TyAlias support in rustc_trait_selection
GuillaumeGomez 5cb94e7
Add TyKind::TyAlias support in rustc_ty_utils
GuillaumeGomez 5ea1e63
Add TyKind::TyAlias support in rustc_traits
GuillaumeGomez 87df978
Add TyKind::TyAlias support in rustc_lint
GuillaumeGomez db39bcd
Add traits::NonStructuralMatchTy::TyAlias support in rustc_mir_build
GuillaumeGomez 5aa4e3c
Add TyKind::TyAlias support in rustc_mir_build
GuillaumeGomez b756929
Add TyKind::TyAlias support in rustc_const_eval
GuillaumeGomez 8b20c6a
Add TyKind::TyAlias support in rustc_typeck
GuillaumeGomez 2e215cd
Add TyKind::TyAlias support in rustc_privacy
GuillaumeGomez 61b0cf7
Add TyKind::TyAlias support in librustdoc
GuillaumeGomez 83ce044
Add HAS_TY_ALIAS into TypeFlags
GuillaumeGomez 042c9ed
Replace `.type_of()` calls with `.bound_type_of()`
GuillaumeGomez 4f632c3
Update failing mangling ui tests
GuillaumeGomez cc95610
Update ui-fulldeps test
GuillaumeGomez 45f038f
crash if invalid type kind in const_to_valtree_inner
GuillaumeGomez 94da537
Add missing mk_ty_alias call into astconv
GuillaumeGomez 3381673
Add UI test for ty alias mangling
GuillaumeGomez 29d628c
Fix compilation errors for TyAlias
GuillaumeGomez 4815a60
Improve code
GuillaumeGomez dcca5d5
Update clippy to handle TyAlias
GuillaumeGomez 7d76dc9
Improve TyCtxt::peel_off_ty_alias
GuillaumeGomez 9e7f02b
Update some UI tests
GuillaumeGomez c383c9d
Fix missing type alias cycle detection
GuillaumeGomez 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -1726,6 +1726,37 @@ impl<'tcx> TyCtxt<'tcx> { | |
pub fn local_visibility(self, def_id: LocalDefId) -> Visibility { | ||
self.visibility(def_id).expect_local() | ||
} | ||
|
||
/// As long as the kind of `ty` is `TyAlias`, then it'll continue to peel it off and return | ||
/// the type below it. | ||
pub fn peel_off_ty_alias<T: ty::TypeFoldable<'tcx>>(self, ty: T) -> T { | ||
struct TyAliasPeeler<'t> { | ||
tcx: TyCtxt<'t>, | ||
} | ||
Comment on lines
+1733
to
+1735
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 we detect the |
||
|
||
impl<'t> ty::TypeFolder<'t> for TyAliasPeeler<'t> { | ||
fn tcx<'a>(&'a self) -> TyCtxt<'t> { | ||
self.tcx | ||
} | ||
|
||
fn fold_ty(&mut self, t: Ty<'t>) -> Ty<'t> { | ||
use crate::ty::fold::{TypeFoldable, TypeSuperFoldable}; | ||
use crate::ty::visit::TypeVisitable; | ||
|
||
match *t.kind() { | ||
ty::TyAlias(def_id, substs) => { | ||
let binder_ty = self.tcx.bound_type_of(def_id); | ||
let ty = binder_ty.subst(self.tcx, substs); | ||
ty.fold_with(self) | ||
} | ||
_ if !t.has_ty_alias() => t, | ||
_ => t.super_fold_with(self), | ||
} | ||
} | ||
} | ||
|
||
ty.fold_with(&mut TyAliasPeeler { tcx: self }) | ||
} | ||
} | ||
|
||
/// A trait implemented for all `X<'a>` types that can be safely and | ||
|
@@ -1996,7 +2027,7 @@ pub mod tls { | |
} | ||
|
||
macro_rules! sty_debug_print { | ||
($fmt: expr, $ctxt: expr, $($variant: ident),*) => {{ | ||
($fmt: expr, $ctxt: expr, $($variant: ident),* $(,)?) => {{ | ||
// Curious inner module to allow variant names to be used as | ||
// variable names. | ||
#[allow(non_snake_case)] | ||
|
@@ -2095,7 +2126,8 @@ impl<'tcx> TyCtxt<'tcx> { | |
Infer, | ||
Projection, | ||
Opaque, | ||
Foreign | ||
Foreign, | ||
TyAlias, | ||
)?; | ||
|
||
writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?; | ||
|
@@ -2633,6 +2665,11 @@ impl<'tcx> TyCtxt<'tcx> { | |
self.mk_ty(Opaque(def_id, substs)) | ||
} | ||
|
||
#[inline] | ||
pub fn mk_ty_alias(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { | ||
self.mk_ty(TyAlias(def_id, substs)) | ||
} | ||
|
||
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { | ||
self.mk_place_elem(place, PlaceElem::Field(f, ty)) | ||
} | ||
|
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.
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.
We should keep the name of the type alias being expanded in the main message.