Added initial processing of UserAssertTy statements.

This commit is contained in:
David Wood 2018-03-01 14:31:14 +00:00
parent 1331cd4a8c
commit 5f21aa8734
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
3 changed files with 40 additions and 17 deletions

View file

@ -761,12 +761,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
);
};
}
StatementKind::UserAssertTy(ref ty, ref local) => {
let local_ty = mir.local_decls()[*local].ty;
debug!("check_stmt: user_assert_ty ty={:?} local_ty={:?}", ty, local_ty);
if let Err(terr) =
self.eq_types(ty, local_ty, location.at_successor_within_block())
{
span_mirbug!(
self,
stmt,
"bad type assert ({:?} = {:?}): {:?}",
ty,
local_ty,
terr
);
}
}
StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::InlineAsm { .. }
| StatementKind::EndRegion(_)
| StatementKind::Validate(..)
| StatementKind::UserAssertTy(..)
| StatementKind::Nop => {}
}
}

View file

@ -38,7 +38,7 @@ use rustc::mir::visit::{MutVisitor, Visitor, TyContext};
use rustc::ty::{Ty, RegionKind, TyCtxt};
use transform::{MirPass, MirSource};
pub struct CleanupPostBorrowck;
pub struct CleanEndRegions;
struct GatherBorrowedRegions {
seen_regions: FxHashSet<region::Scope>,
@ -48,24 +48,19 @@ struct DeleteTrivialEndRegions<'a> {
seen_regions: &'a FxHashSet<region::Scope>,
}
pub struct DeleteUserAssertTy;
impl MirPass for CleanupPostBorrowck {
impl MirPass for CleanEndRegions {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
mir: &mut Mir<'tcx>) {
if tcx.emit_end_regions() {
let mut gather = GatherBorrowedRegions {
seen_regions: FxHashSet()
};
gather.visit_mir(mir);
if !tcx.emit_end_regions() { return; }
let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions };
delete.visit_mir(mir);
}
let mut gather = GatherBorrowedRegions {
seen_regions: FxHashSet()
};
gather.visit_mir(mir);
let mut delete = DeleteUserAssertTy;
let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions };
delete.visit_mir(mir);
}
}
@ -115,6 +110,20 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DeleteTrivialEndRegions<'a> {
}
}
pub struct CleanUserAssertTy;
pub struct DeleteUserAssertTy;
impl MirPass for CleanUserAssertTy {
fn run_pass<'a, 'tcx>(&self,
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
mir: &mut Mir<'tcx>) {
let mut delete = DeleteUserAssertTy;
delete.visit_mir(mir);
}
}
impl<'tcx> MutVisitor<'tcx> for DeleteUserAssertTy {
fn visit_statement(&mut self,
block: BasicBlock,

View file

@ -192,9 +192,8 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea
let mut mir = tcx.mir_built(def_id).steal();
run_passes![tcx, mir, def_id, 0;
// Remove all `UserAssertTy` statements and all `EndRegion` statements that are not
// involved in borrows.
cleanup_post_borrowck::CleanupPostBorrowck,
// Remove all `EndRegion` statements that are not involved in borrows.
cleanup_post_borrowck::CleanEndRegions,
// What we need to do constant evaluation.
simplify::SimplifyCfg::new("initial"),