1
Fork 0

Add docs, remove code, change subtyper code

This commit is contained in:
ouz-a 2023-08-28 11:19:19 +03:00
parent 3148e6a993
commit cd7f471931
24 changed files with 106 additions and 363 deletions

View file

@ -665,9 +665,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let mut op = self.local_to_op(self.frame(), mir_place.local, layout)?;
// Using `try_fold` turned out to be bad for performance, hence the loop.
for elem in mir_place.projection.iter() {
if elem.is_subtype() {
continue;
}
op = self.project(&op, elem)?
}

View file

@ -319,6 +319,8 @@ where
OpaqueCast(ty) => {
span_bug!(self.cur_span(), "OpaqueCast({ty}) encountered after borrowck")
}
// We don't want anything happening here, this is here as a dummy.
Subtype(_) => base.transmute(base.layout(), self)?,
Field(field, _) => self.project_field(base, field.index())?,
Downcast(_, variant) => self.project_downcast(base, variant)?,
Deref => self.deref_pointer(&base.to_op(self)?)?.into(),
@ -332,7 +334,6 @@ where
self.project_constant_index(base, offset, min_length, from_end)?
}
Subslice { from, to, from_end } => self.project_subslice(base, from, to, from_end)?,
Subtype(ty) => base.transmute(self.layout_of(ty)?, self)?,
})
}
}

View file

@ -16,6 +16,8 @@ use rustc_target::spec::abi::Abi;
use crate::util::is_within_packed;
use crate::util::is_subtype;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum EdgeKind {
Unwind,
@ -602,35 +604,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
return true;
}
crate::util::is_subtype(self.tcx, self.param_env, src, dest)
return crate::util::is_subtype(self.tcx, self.param_env, src, dest);
}
}
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
match operand {
Operand::Copy(place) | Operand::Move(place) => {
if let Some(stmt) = self.body.stmt_at(location).left() {
match &stmt.kind {
StatementKind::Assign(box (lval, rvalue)) => {
let place_ty = place.ty(&self.body.local_decls, self.tcx).ty;
let lval_ty = lval.ty(&self.body.local_decls, self.tcx).ty;
if !place.is_subtype()
&& place_ty != lval_ty
&& rvalue.ty(&self.body.local_decls, self.tcx) != lval_ty
&& (rvalue.ty(&self.body.local_decls, self.tcx).is_closure()
!= lval_ty.is_closure())
{
self.fail(location, format!("Subtyping is not allowed between types {place_ty:#?} and {lval_ty:#?}"))
}
}
_ => (),
}
}
}
_ => (),
}
// This check is somewhat expensive, so only run it when -Zvalidate-mir is passed.
if self.tcx.sess.opts.unstable_opts.validate_mir
&& self.mir_phase < MirPhase::Runtime(RuntimePhase::Initial)
@ -776,6 +755,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
}
}
ProjectionElem::Subtype(ty) => {
if !is_subtype(
self.tcx,
self.param_env,
ty,
place_ref.ty(&self.body.local_decls, self.tcx).ty,
) {
self.fail(
location,
format!(
"Failed subtyping {ty:#?} and {:#?}",
place_ref.ty(&self.body.local_decls, self.tcx).ty
),
)
}
}
_ => {}
}
self.super_projection_elem(place_ref, elem, context, location);