1
Fork 0

update TypeFlags to deal with missing ct substs

This commit is contained in:
lcnr 2021-07-17 18:48:07 +02:00
parent cc47998e28
commit ab9108b70f
44 changed files with 305 additions and 166 deletions

View file

@ -171,7 +171,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
for (local, location) in drop_used {
if !live_locals.contains(&local) {
let local_ty = self.cx.body.local_decls[local].ty;
if local_ty.has_free_regions() {
if local_ty.has_free_regions(self.cx.typeck.tcx()) {
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations);
}
}

View file

@ -9,7 +9,7 @@ where
T: TypeFoldable<'tcx>,
{
debug!("ensure_monomorphic_enough: ty={:?}", ty);
if !ty.needs_subst() {
if !ty.potentially_needs_subst() {
return Ok(());
}
@ -25,19 +25,8 @@ where
Some(self.tcx)
}
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if !c.needs_subst() {
return ControlFlow::CONTINUE;
}
match c.val {
ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
_ => c.super_visit_with(self),
}
}
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if !ty.needs_subst() {
if !ty.potentially_needs_subst() {
return ControlFlow::CONTINUE;
}
@ -54,7 +43,7 @@ where
let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
// Only recurse when generic parameters in fns, closures and generators
// are used and require substitution.
match (is_used, subst.needs_subst()) {
match (is_used, subst.needs_subst(self.tcx)) {
// Just in case there are closures or generators within this subst,
// recurse.
(true, true) => return subst.super_visit_with(self),
@ -77,6 +66,13 @@ where
_ => ty.super_visit_with(self),
}
}
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match c.val {
ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
_ => c.super_visit_with(self),
}
}
}
let mut vis = UsedParamsNeedSubstVisitor { tcx };

View file

@ -288,7 +288,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
}
#[instrument(skip(self))]
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if !c.has_param_types_or_consts() {
if !c.has_potential_param_types_or_consts() {
return ControlFlow::CONTINUE;
}
@ -321,7 +321,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
#[instrument(skip(self))]
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if !ty.has_param_types_or_consts() {
if !ty.has_potential_param_types_or_consts() {
return ControlFlow::CONTINUE;
}
@ -363,7 +363,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> {
#[instrument(skip(self))]
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if !c.has_param_types_or_consts() {
if !c.has_potential_param_types_or_consts() {
return ControlFlow::CONTINUE;
}
@ -381,7 +381,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> {
#[instrument(skip(self))]
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if !ty.has_param_types_or_consts() {
if !ty.has_potential_param_types_or_consts() {
return ControlFlow::CONTINUE;
}

View file

@ -163,7 +163,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
let source = MirSource::from_instance(ty::InstanceDef::DropGlue(def_id, ty));
let mut body =
new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span);
new_body(tcx, source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span);
if ty.is_some() {
// The first argument (index 0), but add 1 for the return value.
@ -202,6 +202,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
}
fn new_body<'tcx>(
tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
@ -209,6 +210,7 @@ fn new_body<'tcx>(
span: Span,
) -> Body<'tcx> {
Body::new(
tcx,
source,
basic_blocks,
IndexVec::from_elem_n(
@ -353,7 +355,14 @@ impl CloneShimBuilder<'tcx> {
self.def_id,
self.sig.inputs_and_output[0],
));
new_body(source, self.blocks, self.local_decls, self.sig.inputs().len(), self.span)
new_body(
self.tcx,
source,
self.blocks,
self.local_decls,
self.sig.inputs().len(),
self.span,
)
}
fn source_info(&self) -> SourceInfo {
@ -851,8 +860,14 @@ fn build_call_shim<'tcx>(
block(&mut blocks, vec![], TerminatorKind::Resume, true);
}
let mut body =
new_body(MirSource::from_instance(instance), blocks, local_decls, sig.inputs().len(), span);
let mut body = new_body(
tcx,
MirSource::from_instance(instance),
blocks,
local_decls,
sig.inputs().len(),
span,
);
if let Abi::RustCall = sig.abi {
body.spread_arg = Some(Local::new(sig.inputs().len()));
@ -917,6 +932,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
let source = MirSource::item(ctor_id);
let body = new_body(
tcx,
source,
IndexVec::from_elem_n(start_block, 1),
local_decls,

View file

@ -120,7 +120,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
.predicates_of(def_id.to_def_id())
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
.filter_map(|(p, _)| if p.is_global(tcx) { Some(*p) } else { None });
if traits::impossible_predicates(
tcx,
traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(),
@ -132,6 +132,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
trace!("ConstProp starting for {:?}", def_id);
let dummy_body = &Body::new(
tcx,
body.source,
body.basic_blocks().clone(),
body.source_scopes.clone(),
@ -468,7 +469,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
/// Returns the value, if any, of evaluating `c`.
fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
// FIXME we need to revisit this for #67176
if c.needs_subst() {
if c.needs_subst(self.tcx) {
return None;
}
@ -488,9 +489,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}) => true,
// Out of backwards compatibility we cannot report hard errors in unused
// generic functions using associated constants of the generic parameters.
_ => c.literal.needs_subst(),
_ => c.literal.needs_subst(*tcx),
},
ConstantKind::Val(_, ty) => ty.needs_subst(),
ConstantKind::Val(_, ty) => ty.needs_subst(*tcx),
};
if lint_only {
// Out of backwards compatibility we cannot report hard errors in unused
@ -720,7 +721,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}
// FIXME we need to revisit this for #67176
if rvalue.needs_subst() {
if rvalue.needs_subst(self.tcx) {
return None;
}

View file

@ -89,7 +89,7 @@ crate fn mir_callgraph_reachable(
// FIXME: A not fully substituted drop shim can cause ICEs if one attempts to
// have its MIR built. Likely oli-obk just screwed up the `ParamEnv`s, so this
// needs some more analysis.
if callee.needs_subst() {
if callee.needs_subst(tcx) {
continue;
}
}

View file

@ -400,7 +400,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -
}
}
debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE");
debug_assert!(!body.has_free_regions(tcx), "Free regions in MIR for CTFE");
body
}
@ -594,7 +594,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal();
run_optimization_passes(tcx, &mut body);
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");
debug_assert!(!body.has_free_regions(tcx), "Free regions in optimized MIR");
body
}
@ -621,7 +621,7 @@ fn promoted_mir<'tcx>(
run_post_borrowck_cleanup_passes(tcx, body);
}
debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR");
debug_assert!(!promoted.has_free_regions(tcx), "Free regions in promoted MIR");
tcx.arena.alloc(promoted)
}

View file

@ -992,6 +992,7 @@ pub fn promote_candidates<'tcx>(
scope.parent_scope = None;
let promoted = Body::new(
tcx,
body.source, // `promoted` gets filled in below
IndexVec::new(),
IndexVec::from_elem_n(scope, 1),