1
Fork 0

Fix generics type parameter handling in miri

This commit is contained in:
varkor 2018-03-12 12:47:03 +00:00
parent 5b4e2b7fbc
commit a9622dc5c6
7 changed files with 12 additions and 15 deletions

View file

@ -616,10 +616,9 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
// during trans.
let generics = self.tcx.generics_of(def_id);
let parent_len = generics.parent_count();
let substs = self.tcx.mk_substs(substs.substs.iter().enumerate().map(
|(index, &kind)| {
if index < parent_len {
if index < generics.parent_count {
// Accommodate missing regions in the parent kinds...
self.fold_kind_mapping_missing_regions_to_empty(kind)
} else {

View file

@ -252,7 +252,6 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
}
for def in &defs.params {
assert_eq!(def.index() as usize, substs.len());
let param = match def {
ty::GenericParam::Lifetime(ref lt) => {
mk_region(lt, substs).into()
@ -265,6 +264,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
mk_type(ty, substs).into()
}
};
assert_eq!(def.index() as usize, substs.len());
substs.push(param);
}
}

View file

@ -184,7 +184,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
// evaluate the promoted and replace the constant with the evaluated result
Literal::Promoted { index } => {
let generics = self.tcx.generics_of(self.source.def_id);
if generics.parent_types as usize + generics.types.len() > 0 {
if generics.has_type_parameters(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
@ -295,7 +295,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
self.source.def_id
};
let generics = self.tcx.generics_of(def_id);
if generics.parent_types as usize + generics.types.len() > 0 {
if generics.has_type_parameters(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
@ -317,8 +317,7 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
self.source.def_id
};
let generics = self.tcx.generics_of(def_id);
let has_generics = generics.parent_types as usize + generics.types.len() > 0;
if has_generics {
if generics.has_type_parameters(self.tcx) {
// FIXME: can't handle code with generics
return None;
}

View file

@ -280,7 +280,8 @@ crate fn adt_dtorck_constraint<'a, 'tcx>(
if def.is_phantom_data() {
let result = DtorckConstraint {
outlives: vec![],
dtorck_types: vec![tcx.mk_param_from_def(&tcx.generics_of(def_id).types[0])],
dtorck_types: vec![tcx.mk_param_from_def(&tcx.generics_of(def_id).types().next()
.expect("should be at least one type parameter"))],
overflows: vec![],
};
debug!("dtorck_constraint: {:?} => {:?}", def, result);

View file

@ -117,7 +117,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}) => {
let def_id = tcx.hir.local_def_id(node_id);
let generics = tcx.generics_of(def_id);
if (generics.parent_types == 0 && generics.types.is_empty()) &&
if !generics.has_type_parameters(tcx) &&
// Functions marked with #[inline] are only ever translated
// with "internal" linkage and are never exported.
!Instance::mono(tcx, def_id).def.requires_local(tcx) {

View file

@ -369,13 +369,13 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
let generics = tcx.generics_of(def_id);
let is_our_default = |def: &ty::TypeParameterDef|
def.has_default && def.index >= generics.parent_count() as u32;
def.has_default && def.index >= generics.parent_count as u32;
// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
// For example this forbids the declaration:
// struct Foo<T = Vec<[u32]>> { .. }
// Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
for d in generics.types.iter().cloned().filter(is_our_default).map(|p| p.def_id) {
for d in generics.types().cloned().filter(is_our_default).map(|p| p.def_id) {
let ty = fcx.tcx.type_of(d);
// ignore dependent defaults -- that is, where the default of one type
// parameter includes another (e.g., <T, U = T>). In those cases, we can't

View file

@ -970,10 +970,8 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
.map(|param| (param.def_id, param.index))
.collect();
let lifetimes: Vec<ty::GenericParam> =
regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt));
let types: Vec<ty::GenericParam> =
types.into_iter().map(|ty| ty::GenericParam::Type(ty));
let lifetimes = regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt));
let types = types.into_iter().map(|ty| ty::GenericParam::Type(ty));
let params = lifetimes.chain(types).collect();
tcx.alloc_generics(ty::Generics {