mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Extract generic_args function
This commit is contained in:
parent
ed32347689
commit
db35f1de2f
@ -8,7 +8,9 @@
|
|||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use crate::rustc_internal::{self, opaque};
|
use crate::rustc_internal::{self, opaque};
|
||||||
use crate::stable_mir::ty::{FloatTy, GenericArgKind, GenericArgs, IntTy, Movability, RigidTy, TyKind, UintTy};
|
use crate::stable_mir::ty::{
|
||||||
|
FloatTy, GenericArgKind, GenericArgs, IntTy, Movability, RigidTy, TyKind, UintTy,
|
||||||
|
};
|
||||||
use crate::stable_mir::{self, Context};
|
use crate::stable_mir::{self, Context};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
@ -97,22 +99,7 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
},
|
},
|
||||||
ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
|
ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
|
||||||
rustc_internal::adt_def(adt_def.did()),
|
rustc_internal::adt_def(adt_def.did()),
|
||||||
GenericArgs(
|
self.generic_args(generic_args),
|
||||||
generic_args
|
|
||||||
.iter()
|
|
||||||
.map(|arg| match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(region) => {
|
|
||||||
GenericArgKind::Lifetime(opaque(®ion))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => {
|
|
||||||
GenericArgKind::Type(self.intern_ty(ty))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(const_) => {
|
|
||||||
GenericArgKind::Const(opaque(&const_))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
ty::Foreign(def_id) => {
|
ty::Foreign(def_id) => {
|
||||||
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
|
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
|
||||||
@ -130,67 +117,21 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
}
|
}
|
||||||
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
|
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
|
||||||
rustc_internal::fn_def(*def_id),
|
rustc_internal::fn_def(*def_id),
|
||||||
GenericArgs(
|
self.generic_args(generic_args),
|
||||||
generic_args
|
|
||||||
.iter()
|
|
||||||
.map(|arg| match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(region) => {
|
|
||||||
GenericArgKind::Lifetime(opaque(®ion))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => {
|
|
||||||
GenericArgKind::Type(self.intern_ty(ty))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(const_) => {
|
|
||||||
GenericArgKind::Const(opaque(&const_))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
ty::FnPtr(_) => todo!(),
|
ty::FnPtr(_) => todo!(),
|
||||||
ty::Dynamic(_, _, _) => todo!(),
|
ty::Dynamic(_, _, _) => todo!(),
|
||||||
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
||||||
rustc_internal::closure_def(*def_id),
|
rustc_internal::closure_def(*def_id),
|
||||||
GenericArgs(
|
self.generic_args(generic_args),
|
||||||
generic_args
|
|
||||||
.iter()
|
|
||||||
.map(|arg| match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(region) => {
|
|
||||||
GenericArgKind::Lifetime(opaque(®ion))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => {
|
|
||||||
GenericArgKind::Type(self.intern_ty(ty))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(const_) => {
|
|
||||||
GenericArgKind::Const(opaque(&const_))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator(
|
ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator(
|
||||||
rustc_internal::generator_def(*def_id),
|
rustc_internal::generator_def(*def_id),
|
||||||
GenericArgs(
|
self.generic_args(generic_args),
|
||||||
generic_args
|
|
||||||
.iter()
|
|
||||||
.map(|arg| match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(region) => {
|
|
||||||
GenericArgKind::Lifetime(opaque(®ion))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => {
|
|
||||||
GenericArgKind::Type(self.intern_ty(ty))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(const_) => {
|
|
||||||
GenericArgKind::Const(opaque(&const_))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
match movability {
|
match movability {
|
||||||
hir::Movability::Static => Movability::Static,
|
hir::Movability::Static => Movability::Static,
|
||||||
hir::Movability::Movable => Movability::Movable,
|
hir::Movability::Movable => Movability::Movable,
|
||||||
|
},
|
||||||
}
|
|
||||||
)),
|
)),
|
||||||
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
||||||
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
||||||
@ -217,6 +158,24 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
self.types.push(ty);
|
self.types.push(ty);
|
||||||
stable_mir::ty::Ty(id)
|
stable_mir::ty::Ty(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generic_args(
|
||||||
|
&mut self,
|
||||||
|
generic_args: &ty::GenericArgs<'tcx>,
|
||||||
|
) -> stable_mir::ty::GenericArgs {
|
||||||
|
GenericArgs(
|
||||||
|
generic_args
|
||||||
|
.iter()
|
||||||
|
.map(|arg| match arg.unpack() {
|
||||||
|
ty::GenericArgKind::Lifetime(region) => {
|
||||||
|
GenericArgKind::Lifetime(opaque(®ion))
|
||||||
|
}
|
||||||
|
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(self.intern_ty(ty)),
|
||||||
|
ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a stable mir crate from a given crate number.
|
/// Build a stable mir crate from a given crate number.
|
||||||
|
Loading…
Reference in New Issue
Block a user