Skip to content

Commit

Permalink
Use Idents for associated item definitions in HIR
Browse files Browse the repository at this point in the history
Remove emulation of hygiene with gensyms
  • Loading branch information
petrochenkov committed Jun 28, 2018
1 parent c6ca1e4 commit f0622df
Show file tree
Hide file tree
Showing 45 changed files with 176 additions and 207 deletions.
22 changes: 11 additions & 11 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -57,7 +57,7 @@ pub enum FnKind<'a> {
ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),

/// fn foo(&self)
Method(Name, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),

/// |x, y| {}
Closure(&'a [Attribute]),
Expand Down Expand Up @@ -823,7 +823,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
}

pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) {
visitor.visit_name(trait_item.span, trait_item.name);
visitor.visit_ident(trait_item.ident);
walk_list!(visitor, visit_attribute, &trait_item.attrs);
visitor.visit_generics(&trait_item.generics);
match trait_item.node {
Expand All @@ -840,7 +840,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
}
}
TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => {
visitor.visit_fn(FnKind::Method(trait_item.name,
visitor.visit_fn(FnKind::Method(trait_item.ident,
sig,
None,
&trait_item.attrs),
Expand All @@ -859,9 +859,9 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai

pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) {
// NB: Deliberately force a compilation error if/when new fields are added.
let TraitItemRef { id, name, ref kind, span, ref defaultness } = *trait_item_ref;
let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref;
visitor.visit_nested_trait_item(id);
visitor.visit_name(span, name);
visitor.visit_ident(ident);
visitor.visit_associated_item_kind(kind);
visitor.visit_defaultness(defaultness);
}
Expand All @@ -871,16 +871,16 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
let ImplItem {
id: _,
hir_id: _,
name,
ident,
ref vis,
ref defaultness,
ref attrs,
ref generics,
ref node,
span
span: _,
} = *impl_item;

visitor.visit_name(span, name);
visitor.visit_ident(ident);
visitor.visit_vis(vis);
visitor.visit_defaultness(defaultness);
walk_list!(visitor, visit_attribute, attrs);
Expand All @@ -892,7 +892,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
visitor.visit_nested_body(body);
}
ImplItemKind::Method(ref sig, body_id) => {
visitor.visit_fn(FnKind::Method(impl_item.name,
visitor.visit_fn(FnKind::Method(impl_item.ident,
sig,
Some(&impl_item.vis),
&impl_item.attrs),
Expand All @@ -910,9 +910,9 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt

pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
// NB: Deliberately force a compilation error if/when new fields are added.
let ImplItemRef { id, name, ref kind, span, ref vis, ref defaultness } = *impl_item_ref;
let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref;
visitor.visit_nested_impl_item(id);
visitor.visit_name(span, name);
visitor.visit_ident(ident);
visitor.visit_associated_item_kind(kind);
visitor.visit_vis(vis);
visitor.visit_defaultness(defaultness);
Expand Down
22 changes: 5 additions & 17 deletions src/librustc/hir/lowering.rs
Expand Up @@ -52,7 +52,7 @@ use middle::cstore::CrateStore;
use rustc_data_structures::indexed_vec::IndexVec;
use session::Session;
use util::common::FN_OUTPUT_NAME;
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
use util::nodemap::{DefIdMap, NodeMap};

use std::collections::{BTreeMap, HashSet};
use std::fmt::Debug;
Expand Down Expand Up @@ -85,7 +85,6 @@ pub struct LoweringContext<'a> {
cstore: &'a CrateStore,

resolver: &'a mut Resolver,
name_map: FxHashMap<Ident, Name>,

/// The items being lowered are collected here.
items: BTreeMap<NodeId, hir::Item>,
Expand Down Expand Up @@ -210,7 +209,6 @@ pub fn lower_crate(
sess,
cstore,
resolver,
name_map: FxHashMap(),
items: BTreeMap::new(),
trait_items: BTreeMap::new(),
impl_items: BTreeMap::new(),
Expand Down Expand Up @@ -957,16 +955,6 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_ident(&mut self, ident: Ident) -> Name {
let ident = ident.modern();
if ident.span.ctxt() == SyntaxContext::empty() {
return ident.name;
}
*self.name_map
.entry(ident)
.or_insert_with(|| Symbol::from_ident(ident))
}

fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
label.map(|label| hir::Label {
ident: label.ident,
Expand Down Expand Up @@ -2962,7 +2950,7 @@ impl<'a> LoweringContext<'a> {
hir::TraitItem {
id: node_id,
hir_id,
name: self.lower_ident(i.ident),
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
generics,
node,
Expand All @@ -2988,7 +2976,7 @@ impl<'a> LoweringContext<'a> {
};
hir::TraitItemRef {
id: hir::TraitItemId { node_id: i.id },
name: self.lower_ident(i.ident),
ident: i.ident,
span: i.span,
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
kind,
Expand Down Expand Up @@ -3054,7 +3042,7 @@ impl<'a> LoweringContext<'a> {
hir::ImplItem {
id: node_id,
hir_id,
name: self.lower_ident(i.ident),
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
generics,
vis: self.lower_visibility(&i.vis, None),
Expand All @@ -3069,7 +3057,7 @@ impl<'a> LoweringContext<'a> {
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
hir::ImplItemRef {
id: hir::ImplItemId { node_id: i.id },
name: self.lower_ident(i.ident),
ident: i.ident,
span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/map/blocks.rs
Expand Up @@ -25,7 +25,7 @@ use hir as ast;
use hir::map::{self, Node};
use hir::{Expr, FnDecl};
use hir::intravisit::FnKind;
use syntax::ast::{Attribute, Name, NodeId};
use syntax::ast::{Attribute, Ident, Name, NodeId};
use syntax_pos::Span;

/// An FnLikeNode is a Node that is like a fn, in that it has a decl
Expand Down Expand Up @@ -209,16 +209,16 @@ impl<'a> FnLikeNode<'a> {
let closure = |c: ClosureParts<'a>| {
FnKind::Closure(c.attrs)
};
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _, attrs| {
FnKind::Method(name, sig, vis, attrs)
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
FnKind::Method(ident, sig, vis, attrs)
};
self.handle(item, method, closure)
}

fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(NodeId,
Name,
Ident,
&'a ast::MethodSig,
Option<&'a ast::Visibility>,
ast::BodyId,
Expand All @@ -245,14 +245,14 @@ impl<'a> FnLikeNode<'a> {
},
map::NodeTraitItem(ti) => match ti.node {
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
method(ti.id, ti.name, sig, None, body, ti.span, &ti.attrs)
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
map::NodeImplItem(ii) => {
match ii.node {
ast::ImplItemKind::Method(ref sig, body) => {
method(ii.id, ii.name, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
}
_ => {
bug!("impl method FnLikeNode that is not fn-like")
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/collector.rs
Expand Up @@ -495,7 +495,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
// map the actual nodes, not the duplicate ones in the *Ref.
let TraitItemRef {
id,
name: _,
ident: _,
kind: _,
span: _,
defaultness: _,
Expand All @@ -509,7 +509,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
// map the actual nodes, not the duplicate ones in the *Ref.
let ImplItemRef {
id,
name: _,
ident: _,
kind: _,
span: _,
vis: _,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -949,8 +949,8 @@ impl<'hir> Map<'hir> {
match self.get(id) {
NodeItem(i) => i.name,
NodeForeignItem(i) => i.name,
NodeImplItem(ii) => ii.name,
NodeTraitItem(ti) => ti.name,
NodeImplItem(ii) => ii.ident.name,
NodeTraitItem(ti) => ti.ident.name,
NodeVariant(v) => v.node.name,
NodeField(f) => f.ident.name,
NodeLifetime(lt) => lt.name.ident().name,
Expand Down Expand Up @@ -1149,8 +1149,8 @@ impl Named for Item { fn name(&self) -> Name { self.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }


pub fn map_crate<'hir>(sess: &::session::Session,
Expand Down Expand Up @@ -1309,13 +1309,13 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
Some(NodeImplItem(ii)) => {
match ii.node {
ImplItemKind::Const(..) => {
format!("assoc const {} in {}{}", ii.name, path_str(), id_str)
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
}
ImplItemKind::Method(..) => {
format!("method {} in {}{}", ii.name, path_str(), id_str)
format!("method {} in {}{}", ii.ident, path_str(), id_str)
}
ImplItemKind::Type(_) => {
format!("assoc type {} in {}{}", ii.name, path_str(), id_str)
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
}
}
}
Expand All @@ -1326,7 +1326,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
TraitItemKind::Type(..) => "assoc type",
};

format!("{} {} in {}{}", kind, ti.name, path_str(), id_str)
format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str)
}
Some(NodeVariant(ref variant)) => {
format!("variant {} in {}{}",
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/mod.rs
Expand Up @@ -1536,7 +1536,7 @@ pub struct TraitItemId {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TraitItem {
pub id: NodeId,
pub name: Name,
pub ident: Ident,
pub hir_id: HirId,
pub attrs: HirVec<Attribute>,
pub generics: Generics,
Expand Down Expand Up @@ -1579,7 +1579,7 @@ pub struct ImplItemId {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ImplItem {
pub id: NodeId,
pub name: Name,
pub ident: Ident,
pub hir_id: HirId,
pub vis: Visibility,
pub defaultness: Defaultness,
Expand Down Expand Up @@ -2140,7 +2140,7 @@ impl Item_ {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TraitItemRef {
pub id: TraitItemId,
pub name: Name,
pub ident: Ident,
pub kind: AssociatedItemKind,
pub span: Span,
pub defaultness: Defaultness,
Expand All @@ -2155,7 +2155,7 @@ pub struct TraitItemRef {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ImplItemRef {
pub id: ImplItemId,
pub name: Name,
pub ident: Ident,
pub kind: AssociatedItemKind,
pub span: Span,
pub vis: Visibility,
Expand Down

0 comments on commit f0622df

Please sign in to comment.