add some cfgs back

This commit is contained in:
b-naber 2023-02-19 21:44:01 +00:00
parent aefc5ec110
commit 0725d0ceee
7 changed files with 134 additions and 124 deletions

View File

@ -782,7 +782,7 @@ dependencies = [
"declare_clippy_lint",
"if_chain",
"itertools",
"pulldown-cmark 0.9.2",
"pulldown-cmark",
"quine-mc_cluskey",
"regex-syntax",
"rustc-semver",
@ -2003,15 +2003,9 @@ dependencies = [
[[package]]
name = "http-auth"
<<<<<<< HEAD
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5430cacd7a1f9a02fbeb350dfc81a0e5ed42d81f3398cb0ba184017f85bdcfbc"
=======
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0b40b39d66c28829a0cf4d09f7e139ff8201f7500a5083732848ed3b4b4d850"
>>>>>>> 570ad623189 (remove cfgs)
dependencies = [
"memchr",
]
@ -2561,7 +2555,7 @@ dependencies = [
"memchr",
"once_cell",
"opener",
"pulldown-cmark 0.9.2",
"pulldown-cmark",
"regex",
"serde",
"serde_json",
@ -2578,7 +2572,7 @@ dependencies = [
"anyhow",
"handlebars 3.5.5",
"pretty_assertions",
"pulldown-cmark 0.7.2",
"pulldown-cmark",
"same-file",
"serde_json",
"url",
@ -3275,17 +3269,6 @@ dependencies = [
"cc",
]
[[package]]
name = "pulldown-cmark"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca36dea94d187597e104a5c8e4b07576a8a45aa5db48a65e12940d3eb7461f55"
dependencies = [
"bitflags",
"memchr",
"unicase",
]
[[package]]
name = "pulldown-cmark"
version = "0.9.2"
@ -4589,7 +4572,7 @@ name = "rustc_resolve"
version = "0.0.0"
dependencies = [
"bitflags",
"pulldown-cmark 0.9.2",
"pulldown-cmark",
"rustc_arena",
"rustc_ast",
"rustc_ast_pretty",
@ -6277,7 +6260,6 @@ checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]]
name = "windows_aarch64_msvc"
<<<<<<< HEAD
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
@ -6299,29 +6281,6 @@ name = "windows_x86_64_gnu"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
=======
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_i686_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
>>>>>>> 570ad623189 (remove cfgs)
[[package]]
name = "windows_x86_64_gnullvm"
@ -6331,15 +6290,9 @@ checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]]
name = "windows_x86_64_msvc"
<<<<<<< HEAD
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
=======
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
>>>>>>> 570ad623189 (remove cfgs)
[[package]]
name = "writeable"

View File

@ -495,49 +495,59 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
}
pub(crate) fn next_region_var(
pub(crate) fn next_region_var<F>(
&self,
origin: RegionVariableOrigin,
ctxt: RegionCtxt,
) -> ty::Region<'tcx> {
get_ctxt_fn: F,
) -> ty::Region<'tcx>
where
F: Fn() -> RegionCtxt,
{
let next_region = self.infcx.next_region_var(origin);
let vid = next_region
.try_get_var()
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
let prev = var_to_origin.insert(vid, ctxt);
debug!("var_to_origin after insertion: {:?}", var_to_origin);
if cfg!(debug_assertions) {
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
let ctxt = get_ctxt_fn();
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
let prev = var_to_origin.insert(vid, ctxt);
// This only makes sense if not called in a canonicalization context. If this
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
// or modify how we track nll region vars for that map.
assert!(matches!(prev, None));
// This only makes sense if not called in a canonicalization context. If this
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
// or modify how we track nll region vars for that map.
assert!(matches!(prev, None));
}
next_region
}
#[instrument(skip(self), level = "debug")]
pub(crate) fn next_nll_region_var(
#[instrument(skip(self, get_ctxt_fn), level = "debug")]
pub(crate) fn next_nll_region_var<F>(
&self,
origin: NllRegionVariableOrigin,
ctxt: RegionCtxt,
) -> ty::Region<'tcx> {
get_ctxt_fn: F,
) -> ty::Region<'tcx>
where
F: Fn() -> RegionCtxt,
{
let next_region = self.infcx.next_nll_region_var(origin.clone());
let vid = next_region
.try_get_var()
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
let prev = var_to_origin.insert(vid, ctxt);
debug!("var_to_origin after insertion: {:?}", var_to_origin);
if cfg!(debug_assertions) {
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
let ctxt = get_ctxt_fn();
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
let prev = var_to_origin.insert(vid, ctxt);
// This only makes sense if not called in a canonicalization context. If this
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
// or modify how we track nll region vars for that map.
assert!(matches!(prev, None));
// This only makes sense if not called in a canonicalization context. If this
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
// or modify how we track nll region vars for that map.
assert!(matches!(prev, None));
}
next_region
}

View File

@ -244,6 +244,7 @@ pub enum ExtraConstraintInfo {
PlaceholderFromPredicate(Span),
}
#[cfg(debug_assertions)]
#[instrument(skip(infcx, sccs), level = "debug")]
fn sccs_info<'cx, 'tcx>(
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
@ -252,31 +253,43 @@ fn sccs_info<'cx, 'tcx>(
use crate::renumber::RegionCtxt;
let var_to_origin = infcx.reg_var_to_origin.borrow();
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
var_to_origin_sorted.sort_by(|a, b| a.0.cmp(&b.0));
let mut debug_str = "region variables to origins:\n".to_string();
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
debug_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
}
debug!(debug_str);
let num_components = sccs.scc_data.ranges.len();
let mut components = vec![FxHashSet::default(); num_components];
for (reg_var_idx, scc_idx) in sccs.scc_indices.iter().enumerate() {
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
let origin = var_to_origin.get(&reg_var).unwrap_or_else(|| &RegionCtxt::Unknown);
components[scc_idx.as_usize()].insert(*origin);
components[scc_idx.as_usize()].insert((reg_var, *origin));
}
debug!(
"strongly connected components: {:#?}",
components
.iter()
.enumerate()
.map(|(idx, origin)| { (ConstraintSccIndex::from_usize(idx), origin) })
.collect::<Vec<_>>()
);
let mut components_str = "strongly connected components:";
for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
components_str.push(&format(
"{:?}: {:?})",
ConstraintSccIndex::from_usize(scc_idx),
regions_info,
))
}
debug!(components_str);
// Now let's calculate the best representative for each component
// calculate the best representative for each component
let components_representatives = components
.into_iter()
.enumerate()
.map(|(scc_idx, region_ctxts)| {
let repr = region_ctxts
.into_iter()
.map(|reg_var_origin| reg_var_origin.1)
.max_by(|x, y| x.preference_value().cmp(&y.preference_value()))
.unwrap();
@ -333,6 +346,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let fr_static = universal_regions.fr_static;
let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph, fr_static));
#[cfg(debug_assertions)]
sccs_info(_infcx, constraint_sccs.clone());
let mut scc_values =

View File

@ -31,18 +31,19 @@ pub fn renumber_mir<'tcx>(
/// Replaces all regions appearing in `value` with fresh inference
/// variables.
#[instrument(skip(infcx), level = "debug")]
pub(crate) fn renumber_regions<'tcx, T>(
#[instrument(skip(infcx, get_ctxt_fn), level = "debug")]
pub(crate) fn renumber_regions<'tcx, T, F>(
infcx: &BorrowckInferCtxt<'_, 'tcx>,
value: T,
ctxt: RegionCtxt,
get_ctxt_fn: F,
) -> T
where
T: TypeFoldable<'tcx>,
F: Fn() -> RegionCtxt,
{
infcx.tcx.fold_regions(value, |_region, _depth| {
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
infcx.next_nll_region_var(origin, ctxt)
infcx.next_nll_region_var(origin, || get_ctxt_fn())
})
}
@ -61,13 +62,14 @@ pub(crate) enum RegionCtxt {
LateBound(BoundRegionInfo),
Existential(Option<Symbol>),
Placeholder(BoundRegionInfo),
#[cfg(debug_assertions)]
Unknown,
}
impl RegionCtxt {
/// Used to determine the representative of a component in the strongly connected
/// constraint graph
/// FIXME: don't use underscore here. Got a 'not used' error for some reason
#[cfg(debug_assertions)]
pub(crate) fn preference_value(self) -> usize {
let _anon = Symbol::intern("anon");
@ -87,11 +89,12 @@ struct NllVisitor<'a, 'tcx> {
}
impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
fn renumber_regions<T>(&mut self, value: T, ctxt: RegionCtxt) -> T
fn renumber_regions<T, F>(&mut self, value: T, region_ctxt_fn: F) -> T
where
T: TypeFoldable<'tcx>,
F: Fn() -> RegionCtxt,
{
renumber_regions(self.infcx, value, ctxt)
renumber_regions(self.infcx, value, region_ctxt_fn)
}
}
@ -101,15 +104,15 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
}
#[instrument(skip(self), level = "debug")]
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _ty_context: TyContext) {
*ty = self.renumber_regions(*ty, RegionCtxt::TyContext(_ty_context));
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
*ty = self.renumber_regions(*ty, || RegionCtxt::TyContext(ty_context));
debug!(?ty);
}
#[instrument(skip(self), level = "debug")]
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
*substs = self.renumber_regions(*substs, RegionCtxt::Location(location));
*substs = self.renumber_regions(*substs, || RegionCtxt::Location(location));
debug!(?substs);
}
@ -117,7 +120,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
#[instrument(skip(self), level = "debug")]
fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
let old_region = *region;
*region = self.renumber_regions(old_region, RegionCtxt::Location(location));
*region = self.renumber_regions(old_region, || RegionCtxt::Location(location));
debug!(?region);
}
@ -125,7 +128,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
#[instrument(skip(self), level = "debug")]
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
let literal = constant.literal;
constant.literal = self.renumber_regions(literal, RegionCtxt::Location(_location));
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(_location));
debug!("constant: {:#?}", constant);
}
}

View File

@ -1338,14 +1338,21 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
use crate::renumber::{BoundRegionInfo, RegionCtxt};
use rustc_span::Symbol;
let reg_info = match br.kind {
// FIXME Probably better to use the `Span` here
ty::BoundRegionKind::BrAnon(_, Some(span)) => BoundRegionInfo::Span(span),
ty::BoundRegionKind::BrAnon(..) => {
BoundRegionInfo::Name(Symbol::intern("anon"))
}
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),
let region_ctxt_fn = || {
let reg_info = match br.kind {
ty::BoundRegionKind::BrAnon(_, Some(span)) => {
BoundRegionInfo::Span(span)
}
ty::BoundRegionKind::BrAnon(..) => {
BoundRegionInfo::Name(Symbol::intern("anon"))
}
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
ty::BoundRegionKind::BrEnv => {
BoundRegionInfo::Name(Symbol::intern("env"))
}
};
RegionCtxt::LateBound(reg_info)
};
self.infcx.next_region_var(
@ -1354,7 +1361,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
br.kind,
LateBoundRegionConversionTime::FnCall,
),
RegionCtxt::LateBound(reg_info),
region_ctxt_fn,
)
});
debug!(?sig);

View File

@ -110,7 +110,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
let origin = NllRegionVariableOrigin::Existential { from_forall };
let reg_var =
self.type_checker.infcx.next_nll_region_var(origin, RegionCtxt::Existential(_name));
self.type_checker.infcx.next_nll_region_var(origin, || RegionCtxt::Existential(_name));
reg_var
}
@ -150,9 +150,16 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
let reg_var = reg
.try_get_var()
.unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
let prev = var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
assert!(matches!(prev, None));
if cfg!(debug_assertions) {
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
let prev = var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
// It only makes sense to track region vars in non-canonicalization contexts. If this
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
// or modify how we track nll region vars for that map.
assert!(matches!(prev, None));
}
reg
}

View File

@ -408,7 +408,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
// Create the "global" region that is always free in all contexts: 'static.
let fr_static = self
.infcx
.next_nll_region_var(FR, RegionCtxt::Free(Symbol::intern("static")))
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("static")))
.to_region_vid();
// We've now added all the global regions. The next ones we
@ -447,10 +447,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
_ => Symbol::intern("anon"),
};
self.infcx.next_nll_region_var(
FR,
RegionCtxt::LateBound(BoundRegionInfo::Name(name)),
)
self.infcx.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
};
debug!(?region_vid);
@ -486,8 +485,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
_ => Symbol::intern("anon"),
};
self.infcx
.next_nll_region_var(FR, RegionCtxt::LateBound(BoundRegionInfo::Name(name)))
self.infcx.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
};
debug!(?region_vid);
@ -506,9 +506,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
LangItem::VaList,
Some(self.infcx.tcx.def_span(self.mir_def.did)),
);
let reg_vid = self.infcx.next_nll_region_var(FR, RegionCtxt::Free(Symbol::intern("c-variadic")).to_region_vid();
let region =
self.infcx.tcx.mk_re_var(reg_vid);
let reg_vid = self
.infcx
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
.to_region_vid();
let region = self.infcx.tcx.mk_re_var(reg_vid);
let va_list_ty =
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
@ -520,7 +524,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let fr_fn_body = self
.infcx
.next_nll_region_var(FR, RegionCtxt::Free(Symbol::intern("fn_body")))
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("fn_body")))
.to_region_vid();
let num_universals = self.infcx.num_region_vars();
@ -766,7 +770,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
};
debug!(?region, ?name);
let reg_var = self.next_nll_region_var(origin, RegionCtxt::Free(name));
let reg_var = self.next_nll_region_var(origin, || RegionCtxt::Free(name));
reg_var
})
@ -786,7 +790,15 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
debug!(?br);
let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind);
let region_vid = self.next_nll_region_var(origin, RegionCtxt::Bound(BoundRegionInfo::Name(name)));
let region_vid = {
let name = match br.kind.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
};
self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name)))
};
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
debug!(?liberated_region, ?region_vid);
region_vid
@ -818,7 +830,9 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
_ => Symbol::intern("anon"),
};
self.next_nll_region_var(FR, RegionCtxt::LateBound(BoundRegionInfo::Name(name)))
self.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
};
debug!(?region_vid);
@ -842,7 +856,9 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
_ => Symbol::intern("anon"),
};
self.next_nll_region_var(FR, RegionCtxt::LateBound(BoundRegionInfo::Name(name)))
self.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
};
indices.insert_late_bound_region(r, region_vid.to_region_vid());