Skip to content

Use InternedString rather than Name for RegionParameterDef #49913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ use std::fmt;
use syntax::ast;
use errors::DiagnosticBuilder;
use syntax_pos::{self, Span};
use syntax_pos::symbol::InternedString;
use util::nodemap::FxHashMap;
use arena::DroplessArena;

@@ -343,7 +344,7 @@ pub enum RegionVariableOrigin {
Coercion(Span),

// Region variables created as the values for early-bound regions
EarlyBoundRegion(Span, ast::Name),
EarlyBoundRegion(Span, InternedString),

// Region variables created for bound regions
// in a function or method that is called
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -728,7 +728,7 @@ pub struct TypeParameterDef {

#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub struct RegionParameterDef {
pub name: Name,
pub name: InternedString,
pub def_id: DefId,
pub index: u32,

4 changes: 2 additions & 2 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ pub enum BoundRegion {
///
/// The def-id is needed to distinguish free regions in
/// the event of shadowing.
BrNamed(DefId, Name),
BrNamed(DefId, InternedString),

/// Fresh bound identifiers created during GLB computations.
BrFresh(u32),
@@ -1058,7 +1058,7 @@ impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
pub struct EarlyBoundRegion {
pub def_id: DefId,
pub index: u32,
pub name: Name,
pub name: InternedString,
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
17 changes: 8 additions & 9 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ use std::usize;
use rustc_data_structures::indexed_vec::Idx;
use syntax::abi::Abi;
use syntax::ast::CRATE_NODE_ID;
use syntax::symbol::Symbol;
use syntax::symbol::{Symbol, InternedString};
use hir;

macro_rules! gen_display_debug_body {
@@ -130,7 +130,7 @@ macro_rules! print {
}


struct LateBoundRegionNameCollector(FxHashSet<Symbol>);
struct LateBoundRegionNameCollector(FxHashSet<InternedString>);
impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
match *r {
@@ -148,7 +148,7 @@ pub struct PrintContext {
is_debug: bool,
is_verbose: bool,
identify_regions: bool,
used_region_names: Option<FxHashSet<Symbol>>,
used_region_names: Option<FxHashSet<InternedString>>,
region_index: usize,
binder_depth: usize,
}
@@ -440,12 +440,12 @@ impl PrintContext {
lifted: Option<ty::Binder<U>>) -> fmt::Result
where T: Print, U: Print + TypeFoldable<'tcx>, F: fmt::Write
{
fn name_by_region_index(index: usize) -> Symbol {
fn name_by_region_index(index: usize) -> InternedString {
match index {
0 => Symbol::intern("'r"),
1 => Symbol::intern("'s"),
i => Symbol::intern(&format!("'t{}", i-2)),
}
}.as_str()
}

// Replace any anonymous late-bound regions with named
@@ -493,8 +493,7 @@ impl PrintContext {
}
};
let _ = write!(f, "{}", name);
ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID),
name)
ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), name)
}
};
tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), br))
@@ -510,7 +509,7 @@ impl PrintContext {
result
}

fn is_name_used(&self, name: &Symbol) -> bool {
fn is_name_used(&self, name: &InternedString) -> bool {
match self.used_region_names {
Some(ref names) => names.contains(name),
None => false,
@@ -697,7 +696,7 @@ define_print! {
BrAnon(n) => write!(f, "BrAnon({:?})", n),
BrFresh(n) => write!(f, "BrFresh({:?})", n),
BrNamed(did, name) => {
write!(f, "BrNamed({:?}:{:?}, {:?})",
write!(f, "BrNamed({:?}:{:?}, {})",
did.krate, did.index, name)
}
BrEnv => write!(f, "BrEnv"),
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
@@ -307,7 +307,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
}

pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> {
let name = Symbol::intern(name);
let name = Symbol::intern(name).as_str();
self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
def_id: self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID),
index,
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
{
let tcx = self.tcx();
let lifetime_name = |def_id| {
tcx.hir.name(tcx.hir.as_local_node_id(def_id).unwrap())
tcx.hir.name(tcx.hir.as_local_node_id(def_id).unwrap()).as_str()
};

let hir_id = tcx.hir.node_to_hir_id(lifetime.id);
4 changes: 2 additions & 2 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
@@ -885,7 +885,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics);
let regions = early_lifetimes.enumerate().map(|(i, l)| {
ty::RegionParameterDef {
name: l.lifetime.name.name(),
name: l.lifetime.name.name().as_str(),
index: own_start + i as u32,
def_id: tcx.hir.local_def_id(l.lifetime.id),
pure_wrt_drop: l.pure_wrt_drop,
@@ -1422,7 +1422,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
def_id: tcx.hir.local_def_id(param.lifetime.id),
index,
name: param.lifetime.name.name(),
name: param.lifetime.name.name().as_str(),
}));
index += 1;

8 changes: 4 additions & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -224,7 +224,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
let name = if p.name == "" {
hir::LifetimeName::Static
} else {
hir::LifetimeName::Name(p.name)
hir::LifetimeName::Name(Symbol::intern(&p.name))
};

hir::Lifetime {
@@ -407,7 +407,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
let names_map: FxHashMap<String, Lifetime> = generics
.regions
.iter()
.map(|l| (l.name.as_str().to_string(), l.clean(self.cx)))
.map(|l| (l.name.to_string(), l.clean(self.cx)))
.collect();

let body_ids: FxHashSet<_> = infcx
@@ -728,7 +728,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {

fn region_name(&self, region: Region) -> Option<String> {
match region {
&ty::ReEarlyBound(r) => Some(r.name.as_str().to_string()),
&ty::ReEarlyBound(r) => Some(r.name.to_string()),
_ => None,
}
}
@@ -1005,7 +1005,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// We only care about late bound regions, as we need to add them
// to the 'for<>' section
&ty::ReLateBound(_, ty::BoundRegion::BrNamed(_, name)) => {
Some(GenericParam::Lifetime(Lifetime(name.as_str().to_string())))
Some(GenericParam::Lifetime(Lifetime(name.to_string())))
}
&ty::ReVar(_) | &ty::ReEarlyBound(_) => None,
_ => panic!("Unexpected region type {:?}", r),