add tainted_by_errors to mir::Body
This commit is contained in:
parent
29c2bb51c0
commit
a431174c23
10 changed files with 37 additions and 23 deletions
|
@ -120,7 +120,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
|
||||||
fn in_return_place(
|
fn in_return_place(
|
||||||
&mut self,
|
&mut self,
|
||||||
ccx: &'mir ConstCx<'mir, 'tcx>,
|
ccx: &'mir ConstCx<'mir, 'tcx>,
|
||||||
error_occured: Option<ErrorReported>,
|
tainted_by_errors: Option<ErrorReported>,
|
||||||
) -> ConstQualifs {
|
) -> ConstQualifs {
|
||||||
// Find the `Return` terminator if one exists.
|
// Find the `Return` terminator if one exists.
|
||||||
//
|
//
|
||||||
|
@ -134,7 +134,9 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
|
||||||
.map(|(bb, _)| bb);
|
.map(|(bb, _)| bb);
|
||||||
|
|
||||||
let return_block = match return_block {
|
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,
|
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),
|
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),
|
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
|
||||||
custom_eq,
|
custom_eq,
|
||||||
error_occured,
|
tainted_by_errors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ use super::ConstCx;
|
||||||
pub fn in_any_value_of_ty<'tcx>(
|
pub fn in_any_value_of_ty<'tcx>(
|
||||||
cx: &ConstCx<'_, 'tcx>,
|
cx: &ConstCx<'_, 'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
error_occured: Option<ErrorReported>,
|
tainted_by_errors: Option<ErrorReported>,
|
||||||
) -> ConstQualifs {
|
) -> ConstQualifs {
|
||||||
ConstQualifs {
|
ConstQualifs {
|
||||||
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
|
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
|
||||||
needs_drop: NeedsDrop::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),
|
needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
|
||||||
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
|
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
|
||||||
error_occured,
|
tainted_by_errors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -974,6 +974,7 @@ pub fn promote_candidates<'tcx>(
|
||||||
vec![],
|
vec![],
|
||||||
body.span,
|
body.span,
|
||||||
body.generator_kind(),
|
body.generator_kind(),
|
||||||
|
body.tainted_by_errors,
|
||||||
);
|
);
|
||||||
|
|
||||||
let promoter = Promoter {
|
let promoter = Promoter {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::ty::subst::{Subst, SubstsRef};
|
||||||
use crate::ty::{self, List, Ty, TyCtxt};
|
use crate::ty::{self, List, Ty, TyCtxt};
|
||||||
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
|
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
|
||||||
|
|
||||||
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_hir::def::{CtorKind, Namespace};
|
use rustc_hir::def::{CtorKind, Namespace};
|
||||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
||||||
use rustc_hir::{self, GeneratorKind};
|
use rustc_hir::{self, GeneratorKind};
|
||||||
|
@ -284,6 +285,8 @@ pub struct Body<'tcx> {
|
||||||
|
|
||||||
predecessor_cache: PredecessorCache,
|
predecessor_cache: PredecessorCache,
|
||||||
is_cyclic: GraphIsCyclicCache,
|
is_cyclic: GraphIsCyclicCache,
|
||||||
|
|
||||||
|
pub tainted_by_errors: Option<ErrorReported>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Body<'tcx> {
|
impl<'tcx> Body<'tcx> {
|
||||||
|
@ -297,6 +300,7 @@ impl<'tcx> Body<'tcx> {
|
||||||
var_debug_info: Vec<VarDebugInfo<'tcx>>,
|
var_debug_info: Vec<VarDebugInfo<'tcx>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
generator_kind: Option<GeneratorKind>,
|
generator_kind: Option<GeneratorKind>,
|
||||||
|
tainted_by_errors: Option<ErrorReported>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// We need `arg_count` locals, and one for the return place.
|
// We need `arg_count` locals, and one for the return place.
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -329,6 +333,7 @@ impl<'tcx> Body<'tcx> {
|
||||||
is_polymorphic: false,
|
is_polymorphic: false,
|
||||||
predecessor_cache: PredecessorCache::new(),
|
predecessor_cache: PredecessorCache::new(),
|
||||||
is_cyclic: GraphIsCyclicCache::new(),
|
is_cyclic: GraphIsCyclicCache::new(),
|
||||||
|
tainted_by_errors,
|
||||||
};
|
};
|
||||||
body.is_polymorphic = body.has_param_types_or_consts();
|
body.is_polymorphic = body.has_param_types_or_consts();
|
||||||
body
|
body
|
||||||
|
@ -356,6 +361,7 @@ impl<'tcx> Body<'tcx> {
|
||||||
is_polymorphic: false,
|
is_polymorphic: false,
|
||||||
predecessor_cache: PredecessorCache::new(),
|
predecessor_cache: PredecessorCache::new(),
|
||||||
is_cyclic: GraphIsCyclicCache::new(),
|
is_cyclic: GraphIsCyclicCache::new(),
|
||||||
|
tainted_by_errors: None,
|
||||||
};
|
};
|
||||||
body.is_polymorphic = body.has_param_types_or_consts();
|
body.is_polymorphic = body.has_param_types_or_consts();
|
||||||
body
|
body
|
||||||
|
|
|
@ -228,7 +228,7 @@ pub struct ConstQualifs {
|
||||||
pub needs_drop: bool,
|
pub needs_drop: bool,
|
||||||
pub needs_non_const_drop: bool,
|
pub needs_non_const_drop: bool,
|
||||||
pub custom_eq: 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
|
/// After we borrow check a closure, we are left with various
|
||||||
|
|
|
@ -253,6 +253,7 @@ TrivialTypeFoldableAndLiftImpls! {
|
||||||
crate::ty::UniverseIndex,
|
crate::ty::UniverseIndex,
|
||||||
crate::ty::Variance,
|
crate::ty::Variance,
|
||||||
::rustc_span::Span,
|
::rustc_span::Span,
|
||||||
|
::rustc_errors::ErrorReported,
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -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));
|
let span_with_body = span_with_body.unwrap_or_else(|| tcx.hir().span(id));
|
||||||
|
|
||||||
tcx.infer_ctxt().enter(|infcx| {
|
tcx.infer_ctxt().enter(|infcx| {
|
||||||
let body = if let Some(ErrorReported) = typeck_results.tainted_by_errors {
|
let body = if let Some(error_reported) = typeck_results.tainted_by_errors {
|
||||||
build::construct_error(&infcx, def, id, body_id, body_owner_kind)
|
build::construct_error(&infcx, def, id, body_id, body_owner_kind, error_reported)
|
||||||
} else if body_owner_kind.is_fn_or_closure() {
|
} else if body_owner_kind.is_fn_or_closure() {
|
||||||
// fetch the fully liberated fn signature (that is, all bound
|
// fetch the fully liberated fn signature (that is, all bound
|
||||||
// types/lifetimes replaced)
|
// types/lifetimes replaced)
|
||||||
|
@ -715,6 +715,7 @@ fn construct_error<'a, 'tcx>(
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
body_id: hir::BodyId,
|
body_id: hir::BodyId,
|
||||||
body_owner_kind: hir::BodyOwnerKind,
|
body_owner_kind: hir::BodyOwnerKind,
|
||||||
|
err: ErrorReported,
|
||||||
) -> Body<'tcx> {
|
) -> Body<'tcx> {
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
let span = tcx.hir().span(hir_id);
|
let span = tcx.hir().span(hir_id);
|
||||||
|
@ -769,6 +770,7 @@ fn construct_error<'a, 'tcx>(
|
||||||
vec![],
|
vec![],
|
||||||
span,
|
span,
|
||||||
generator_kind,
|
generator_kind,
|
||||||
|
Some(err),
|
||||||
);
|
);
|
||||||
body.generator.as_mut().map(|gen| gen.yield_ty = Some(ty));
|
body.generator.as_mut().map(|gen| gen.yield_ty = Some(ty));
|
||||||
body
|
body
|
||||||
|
@ -857,6 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
self.var_debug_info,
|
self.var_debug_info,
|
||||||
self.fn_span,
|
self.fn_span,
|
||||||
self.generator_kind,
|
self.generator_kind,
|
||||||
|
self.typeck_results.tainted_by_errors,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
||||||
Default::default(),
|
Default::default(),
|
||||||
body.span,
|
body.span,
|
||||||
body.generator_kind(),
|
body.generator_kind(),
|
||||||
|
body.tainted_by_errors,
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
|
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
|
||||||
|
|
|
@ -252,8 +252,11 @@ fn mir_promoted<'tcx>(
|
||||||
// Ensure that we compute the `mir_const_qualif` for constants at
|
// Ensure that we compute the `mir_const_qualif` for constants at
|
||||||
// this point, before we steal the mir-const result.
|
// this point, before we steal the mir-const result.
|
||||||
// Also this means promotion can rely on all const checks having been done.
|
// 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();
|
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 = Vec::new();
|
||||||
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
|
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);
|
return tcx.mir_drops_elaborated_and_const_checked(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (Mir-)Borrowck uses `mir_promoted`, so we have to force it to
|
let mir_borrowck = tcx.mir_borrowck_opt_const_arg(def);
|
||||||
// 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 is_fn_like = tcx.hir().get_by_def_id(def.did).fn_kind().is_some();
|
let is_fn_like = tcx.hir().get_by_def_id(def.did).fn_kind().is_some();
|
||||||
if is_fn_like {
|
if is_fn_like {
|
||||||
|
@ -379,6 +376,9 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
|
||||||
|
|
||||||
let (body, _) = tcx.mir_promoted(def);
|
let (body, _) = tcx.mir_promoted(def);
|
||||||
let mut body = body.steal();
|
let mut body = body.steal();
|
||||||
|
if let Some(error_reported) = mir_borrowck.tainted_by_errors {
|
||||||
|
body.tainted_by_errors = Some(error_reported);
|
||||||
|
}
|
||||||
|
|
||||||
// IMPORTANT
|
// IMPORTANT
|
||||||
pm::run_passes(tcx, &mut body, &[&remove_false_edges::RemoveFalseEdges]);
|
pm::run_passes(tcx, &mut body, &[&remove_false_edges::RemoveFalseEdges]);
|
||||||
|
@ -544,15 +544,13 @@ fn promoted_mir<'tcx>(
|
||||||
return tcx.arena.alloc(IndexVec::new());
|
return tcx.arena.alloc(IndexVec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(param_did) = def.const_param_did {
|
let tainted_by_errors = tcx.mir_borrowck_opt_const_arg(def).tainted_by_errors;
|
||||||
tcx.ensure().mir_borrowck_const_arg((def.did, param_did));
|
let mut promoted = tcx.mir_promoted(def).1.steal();
|
||||||
} else {
|
|
||||||
tcx.ensure().mir_borrowck(def.did);
|
|
||||||
}
|
|
||||||
let (_, promoted) = tcx.mir_promoted(def);
|
|
||||||
let mut promoted = promoted.steal();
|
|
||||||
|
|
||||||
for body in &mut promoted {
|
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);
|
run_post_borrowck_cleanup_passes(tcx, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,6 +235,8 @@ fn new_body<'tcx>(
|
||||||
vec![],
|
vec![],
|
||||||
span,
|
span,
|
||||||
None,
|
None,
|
||||||
|
// FIXME(compiler-errors): is this correct?
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue