Skip to content

Commit

Permalink
add some cfgs back
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Feb 19, 2023
1 parent aefc5ec commit 0725d0c
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 124 deletions.
55 changes: 4 additions & 51 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]
Expand Down Expand Up @@ -2561,7 +2555,7 @@ dependencies = [
"memchr",
"once_cell",
"opener",
"pulldown-cmark 0.9.2",
"pulldown-cmark",
"regex",
"serde",
"serde_json",
Expand All @@ -2578,7 +2572,7 @@ dependencies = [
"anyhow",
"handlebars 3.5.5",
"pretty_assertions",
"pulldown-cmark 0.7.2",
"pulldown-cmark",
"same-file",
"serde_json",
"url",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
56 changes: 33 additions & 23 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
34 changes: 24 additions & 10 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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();

Expand Down Expand Up @@ -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 =
Expand Down
27 changes: 15 additions & 12 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}

Expand All @@ -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");

Expand All @@ -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)
}
}

Expand All @@ -101,31 +104,31 @@ 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);
}

#[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);
}

#[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);
}
}
Loading

0 comments on commit 0725d0c

Please sign in to comment.