Handle trait objects. Only very superficial checking of the vtable for now. (88)

This commit is contained in:
Ralf Jung 2017-07-13 23:34:08 -07:00 committed by Oliver Schneider
parent e5c6637d87
commit 769a2b5c81
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9

View file

@ -71,7 +71,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
TyBool | TyFloat(_) | TyChar | TyStr |
TyRef(..) | TyFnPtr(..) | TyNever => true,
TyAdt(adt, _) if adt.is_box() => true,
TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) => false,
TySlice(_) | TyAdt(_, _) | TyTuple(..) | TyClosure(..) | TyArray(..) | TyDynamic(..) => false,
TyParam(_) | TyInfer(_) => bug!("I got an incomplete type for validation"),
_ => return Err(EvalError::Unimplemented(format!("Unimplemented type encountered when checking validity."))),
};
@ -178,6 +178,20 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
Ok(())
}
TyDynamic(_data, _region) => {
// Check that this is a valid vtable
let vtable = match lvalue {
Lvalue::Ptr { extra: LvalueExtra::Vtable(vtable), .. } => vtable,
_ => bug!("acquire_valid of a TyDynamic given non-trait-object lvalue: {:?}", lvalue),
};
self.read_size_and_align_from_vtable(vtable)?;
// TODO: Check that the vtable contains all the function pointers we expect it to have.
// TODO: Is there anything we can/should validate here? Trait objects cannot have any operations performed
// on them directly. We cannot, in general, even acquire any locks as the trait object *could*
// contain an UnsafeCell. If we call functions to get access to data, we will validate
// their return values. So, it doesn't seem like there's anything to do.
Ok(())
}
TyAdt(adt, subst) => {
if Some(adt.did) == self.tcx.lang_items.unsafe_cell_type() {
// No locks for unsafe cells. Also no other validation, the only field is private anyway.