add tainted_by_errors to mir::Body

This commit is contained in:
Michael Goulet 2022-02-07 22:00:15 -08:00
parent 29c2bb51c0
commit a431174c23
10 changed files with 37 additions and 23 deletions

View File

@ -120,7 +120,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
fn in_return_place(
&mut self,
ccx: &'mir ConstCx<'mir, 'tcx>,
error_occured: Option<ErrorReported>,
tainted_by_errors: Option<ErrorReported>,
) -> ConstQualifs {
// Find the `Return` terminator if one exists.
//
@ -134,7 +134,9 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
.map(|(bb, _)| bb);
let return_block = match return_block {
None => return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), error_occured),
None => {
return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), tainted_by_errors);
}
Some(bb) => bb,
};
@ -166,7 +168,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
custom_eq,
error_occured,
tainted_by_errors,
}
}
}

View File

@ -17,14 +17,14 @@ use super::ConstCx;
pub fn in_any_value_of_ty<'tcx>(
cx: &ConstCx<'_, 'tcx>,
ty: Ty<'tcx>,
error_occured: Option<ErrorReported>,
tainted_by_errors: Option<ErrorReported>,
) -> ConstQualifs {
ConstQualifs {
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
error_occured,
tainted_by_errors,
}
}

View File

@ -974,6 +974,7 @@ pub fn promote_candidates<'tcx>(
vec![],
body.span,
body.generator_kind(),
body.tainted_by_errors,
);
let promoter = Promoter {

View File

@ -13,6 +13,7 @@ use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::{self, List, Ty, TyCtxt};
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
use rustc_errors::ErrorReported;
use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc_hir::{self, GeneratorKind};
@ -284,6 +285,8 @@ pub struct Body<'tcx> {
predecessor_cache: PredecessorCache,
is_cyclic: GraphIsCyclicCache,
pub tainted_by_errors: Option<ErrorReported>,
}
impl<'tcx> Body<'tcx> {
@ -297,6 +300,7 @@ impl<'tcx> Body<'tcx> {
var_debug_info: Vec<VarDebugInfo<'tcx>>,
span: Span,
generator_kind: Option<GeneratorKind>,
tainted_by_errors: Option<ErrorReported>,
) -> Self {
// We need `arg_count` locals, and one for the return place.
assert!(
@ -329,6 +333,7 @@ impl<'tcx> Body<'tcx> {
is_polymorphic: false,
predecessor_cache: PredecessorCache::new(),
is_cyclic: GraphIsCyclicCache::new(),
tainted_by_errors,
};
body.is_polymorphic = body.has_param_types_or_consts();
body
@ -356,6 +361,7 @@ impl<'tcx> Body<'tcx> {
is_polymorphic: false,
predecessor_cache: PredecessorCache::new(),
is_cyclic: GraphIsCyclicCache::new(),
tainted_by_errors: None,
};
body.is_polymorphic = body.has_param_types_or_consts();
body

View File

@ -228,7 +228,7 @@ pub struct ConstQualifs {
pub needs_drop: bool,
pub needs_non_const_drop: bool,
pub custom_eq: bool,
pub error_occured: Option<ErrorReported>,
pub tainted_by_errors: Option<ErrorReported>,
}
/// After we borrow check a closure, we are left with various

View File

@ -253,6 +253,7 @@ TrivialTypeFoldableAndLiftImpls! {
crate::ty::UniverseIndex,
crate::ty::Variance,
::rustc_span::Span,
::rustc_errors::ErrorReported,
}
///////////////////////////////////////////////////////////////////////////

View File

@ -104,8 +104,8 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
let span_with_body = span_with_body.unwrap_or_else(|| tcx.hir().span(id));
tcx.infer_ctxt().enter(|infcx| {
let body = if let Some(ErrorReported) = typeck_results.tainted_by_errors {
build::construct_error(&infcx, def, id, body_id, body_owner_kind)
let body = if let Some(error_reported) = typeck_results.tainted_by_errors {
build::construct_error(&infcx, def, id, body_id, body_owner_kind, error_reported)
} else if body_owner_kind.is_fn_or_closure() {
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
@ -715,6 +715,7 @@ fn construct_error<'a, 'tcx>(
hir_id: hir::HirId,
body_id: hir::BodyId,
body_owner_kind: hir::BodyOwnerKind,
err: ErrorReported,
) -> Body<'tcx> {
let tcx = infcx.tcx;
let span = tcx.hir().span(hir_id);
@ -769,6 +770,7 @@ fn construct_error<'a, 'tcx>(
vec![],
span,
generator_kind,
Some(err),
);
body.generator.as_mut().map(|gen| gen.yield_ty = Some(ty));
body
@ -857,6 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.var_debug_info,
self.fn_span,
self.generator_kind,
self.typeck_results.tainted_by_errors,
)
}

View File

@ -145,6 +145,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
Default::default(),
body.span,
body.generator_kind(),
body.tainted_by_errors,
);
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold

View File

@ -252,8 +252,11 @@ fn mir_promoted<'tcx>(
// Ensure that we compute the `mir_const_qualif` for constants at
// this point, before we steal the mir-const result.
// Also this means promotion can rely on all const checks having been done.
let _ = tcx.mir_const_qualif_opt_const_arg(def);
let const_qualifs = tcx.mir_const_qualif_opt_const_arg(def);
let mut body = tcx.mir_const(def).steal();
if let Some(error_reported) = const_qualifs.tainted_by_errors {
body.tainted_by_errors = Some(error_reported);
}
let mut required_consts = Vec::new();
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
@ -358,13 +361,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
return tcx.mir_drops_elaborated_and_const_checked(def);
}
// (Mir-)Borrowck uses `mir_promoted`, so we have to force it to
// execute before we can steal.
if let Some(param_did) = def.const_param_did {
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
} else {
tcx.ensure().mir_borrowck(def.did);
}
let mir_borrowck = tcx.mir_borrowck_opt_const_arg(def);
let is_fn_like = tcx.hir().get_by_def_id(def.did).fn_kind().is_some();
if is_fn_like {
@ -379,6 +376,9 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
let (body, _) = tcx.mir_promoted(def);
let mut body = body.steal();
if let Some(error_reported) = mir_borrowck.tainted_by_errors {
body.tainted_by_errors = Some(error_reported);
}
// IMPORTANT
pm::run_passes(tcx, &mut body, &[&remove_false_edges::RemoveFalseEdges]);
@ -544,15 +544,13 @@ fn promoted_mir<'tcx>(
return tcx.arena.alloc(IndexVec::new());
}
if let Some(param_did) = def.const_param_did {
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
} else {
tcx.ensure().mir_borrowck(def.did);
}
let (_, promoted) = tcx.mir_promoted(def);
let mut promoted = promoted.steal();
let tainted_by_errors = tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors;
let mut promoted = tcx.mir_promoted(def).1.steal();
for body in &mut promoted {
if let Some(error_reported) = tainted_by_errors {
body.tainted_by_errors = Some(error_reported);
}
run_post_borrowck_cleanup_passes(tcx, body);
}

View File

@ -235,6 +235,8 @@ fn new_body<'tcx>(
vec![],
span,
None,
// FIXME(compiler-errors): is this correct?
None,
)
}