Skip to content

Commit

Permalink
Rollup merge of #110175 - nnethercote:symbol-cleanups, r=jackh726
Browse files Browse the repository at this point in the history
Symbol cleanups

r? ``@jackh726``

cc ``@b-naber``
  • Loading branch information
compiler-errors committed Apr 12, 2023
2 parents b5a6f8d + 7975779 commit 318e82d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 49 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ impl RegionCtxt {
/// Used to determine the representative of a component in the strongly connected
/// constraint graph
pub(crate) fn preference_value(self) -> usize {
let _anon = Symbol::intern("anon");

match self {
RegionCtxt::Unknown => 1,
RegionCtxt::Existential(None) => 2,
RegionCtxt::Existential(Some(_anon)) | RegionCtxt::Free(_anon) => 2,
RegionCtxt::Existential(Some(_)) | RegionCtxt::Free(_) => 2,
RegionCtxt::Location(_) => 3,
RegionCtxt::TyContext(_) => 4,
_ => 5,
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use rustc_middle::ty::{
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
};
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::symbol::sym;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
Expand Down Expand Up @@ -1338,18 +1339,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
};
let (sig, map) = tcx.replace_late_bound_regions(sig, |br| {
use crate::renumber::{BoundRegionInfo, RegionCtxt};
use rustc_span::Symbol;

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::BrAnon(..) => BoundRegionInfo::Name(sym::anon),
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
ty::BoundRegionKind::BrEnv => {
BoundRegionInfo::Name(Symbol::intern("env"))
}
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
};

RegionCtxt::LateBound(reg_info)
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_infer::traits::PredicateObligations;
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
use rustc_trait_selection::traits::query::Fallible;

Expand Down Expand Up @@ -125,9 +126,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>

let reg_info = match placeholder.bound.kind {
ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span),
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(Symbol::intern("anon")),
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon),
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
};

let reg_var =
Expand Down
42 changes: 10 additions & 32 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
use rustc_middle::ty::{InternalSubsts, SubstsRef};
use rustc_span::symbol::{kw, sym};
use rustc_span::Symbol;
use std::iter;

Expand Down Expand Up @@ -404,10 +405,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars());

// 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")))
.to_region_vid();
let fr_static =
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(kw::Static)).to_region_vid();

// We've now added all the global regions. The next ones we
// add will be external.
Expand Down Expand Up @@ -440,11 +439,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
debug!(?r);
if !indices.indices.contains_key(&r) {
let region_vid = {
let name = match r.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
};

let name = r.get_name_or_anon();
self.infcx.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
Expand Down Expand Up @@ -478,11 +473,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
debug!(?r);
if !indices.indices.contains_key(&r) {
let region_vid = {
let name = match r.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
};

let name = r.get_name_or_anon();
self.infcx.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
Expand Down Expand Up @@ -768,15 +759,10 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
T: TypeFoldable<TyCtxt<'tcx>>,
{
self.infcx.tcx.fold_regions(value, |region, _depth| {
let name = match region.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
};
let name = region.get_name_or_anon();
debug!(?region, ?name);

let reg_var = self.next_nll_region_var(origin, || RegionCtxt::Free(name));

reg_var
self.next_nll_region_var(origin, || RegionCtxt::Free(name))
})
}

Expand All @@ -797,7 +783,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
let region_vid = {
let name = match br.kind.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
_ => sym::anon,
};

self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name)))
Expand Down Expand Up @@ -829,11 +815,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
debug!(?r);
if !indices.indices.contains_key(&r) {
let region_vid = {
let name = match r.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
};

let name = r.get_name_or_anon();
self.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
Expand All @@ -855,11 +837,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
debug!(?r);
if !indices.indices.contains_key(&r) {
let region_vid = {
let name = match r.get_name() {
Some(name) => name,
_ => Symbol::intern("anon"),
};

let name = r.get_name_or_anon();
self.next_nll_region_var(FR, || {
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
})
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,19 +1621,24 @@ impl<'tcx> Region<'tcx> {

pub fn get_name(self) -> Option<Symbol> {
if self.has_name() {
let name = match *self {
match *self {
ty::ReEarlyBound(ebr) => Some(ebr.name),
ty::ReLateBound(_, br) => br.kind.get_name(),
ty::ReFree(fr) => fr.bound_region.get_name(),
ty::ReStatic => Some(kw::StaticLifetime),
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
_ => None,
};

return name;
}
} else {
None
}
}

None
pub fn get_name_or_anon(self) -> Symbol {
match self.get_name() {
Some(name) => name,
None => sym::anon,
}
}

/// Is this region named by the user?
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ symbols! {
always,
and,
and_then,
anon,
anonymous_lifetime_in_impl_trait,
any,
append_const_msg,
Expand Down

0 comments on commit 318e82d

Please sign in to comment.