Skip to content
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

Represent lifetimes as Names instead of Idents #12451

Merged
merged 1 commit into from
Feb 23, 2014
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
tag_region_param_def_def_id);
let def_id = reader::with_doc_data(def_id_doc, parse_def_id);
let def_id = translate_def_id(cdata, def_id);
v.push(ty::RegionParameterDef { ident: ident,
v.push(ty::RegionParameterDef { ident: ident.name,
def_id: def_id });
true
});
Expand Down
36 changes: 18 additions & 18 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ pub fn reachable(ecx: &EncodeContext, id: NodeId) -> bool {
reachable.get().contains(&id)
}

fn encode_name(ebml_w: &mut writer::Encoder, name: Ident) {
ebml_w.wr_tagged_str(tag_paths_data_name, token::get_ident(name).get());
fn encode_name(ebml_w: &mut writer::Encoder, name: Name) {
ebml_w.wr_tagged_str(tag_paths_data_name, token::get_name(name).get());
}

fn encode_impl_type_basename(ebml_w: &mut writer::Encoder, name: Ident) {
Expand Down Expand Up @@ -312,7 +312,7 @@ fn encode_struct_fields(ebml_w: &mut writer::Encoder,
NamedField(ident, vis) => {
ebml_w.start_tag(tag_item_field);
encode_struct_field_family(ebml_w, vis);
encode_name(ebml_w, ident);
encode_name(ebml_w, ident.name);
encode_def_id(ebml_w, local_def(f.node.id));
ebml_w.end_tag();
}
Expand Down Expand Up @@ -352,7 +352,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
ast::TupleVariantKind(_) => encode_family(ebml_w, 'v'),
ast::StructVariantKind(_) => encode_family(ebml_w, 'V')
}
encode_name(ebml_w, variant.node.name);
encode_name(ebml_w, variant.node.name.name);
encode_parent_item(ebml_w, local_def(id));
encode_visibility(ebml_w, variant.node.vis);
encode_attributes(ebml_w, variant.node.attrs);
Expand Down Expand Up @@ -579,7 +579,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(id));
encode_family(ebml_w, 'm');
encode_name(ebml_w, name);
encode_name(ebml_w, name.name);
debug!("(encoding info for module) encoding info for module ID {}", id);

// Encode info about all the module children.
Expand Down Expand Up @@ -716,7 +716,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
debug!("encode_info_for_struct: doing {} {}",
token::get_ident(nm), id);
encode_struct_field_family(ebml_w, vis);
encode_name(ebml_w, nm);
encode_name(ebml_w, nm.name);
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
encode_def_id(ebml_w, local_def(id));
ebml_w.end_tag();
Expand All @@ -743,7 +743,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
encode_family(ebml_w, 'f');
encode_bounds_and_type(ebml_w, ecx,
&lookup_item_type(ecx.tcx, local_def(ctor_id)));
encode_name(ebml_w, name);
encode_name(ebml_w, name.name);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, ctor_id));
ecx.tcx.map.with_path(ctor_id, |path| encode_path(ebml_w, path));
encode_parent_item(ebml_w, local_def(struct_id));
Expand All @@ -766,7 +766,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
method_ty: &ty::Method) {
encode_def_id(ebml_w, method_ty.def_id);
encode_name(ebml_w, method_ty.ident);
encode_name(ebml_w, method_ty.ident.name);
encode_ty_type_param_defs(ebml_w, ecx,
method_ty.generics.type_param_defs(),
tag_item_method_tps);
Expand Down Expand Up @@ -916,7 +916,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_symbol(ecx, ebml_w, item.id);
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_path(ebml_w, path);

let inlineable = !ecx.non_inlineable_statics.borrow().get().contains(&item.id);
Expand All @@ -934,7 +934,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_family(ebml_w, purity_fn_family(purity));
let tps_len = generics.ty_params.len();
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_path(ebml_w, path);
encode_attributes(ebml_w, item.attrs);
if tps_len > 0u || should_inline(item.attrs) {
Expand All @@ -960,7 +960,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 'n');
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_path(ebml_w, path);

// Encode all the items in this module.
Expand All @@ -978,7 +978,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 'y');
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_path(ebml_w, path);
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
Expand All @@ -991,7 +991,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_family(ebml_w, 't');
encode_item_variances(ebml_w, ecx, item.id);
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_attributes(ebml_w, item.attrs);
for v in (*enum_definition).variants.iter() {
encode_variant_id(ebml_w, local_def(v.node.id));
Expand Down Expand Up @@ -1030,7 +1030,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));

encode_item_variances(ebml_w, ecx, item.id);
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_attributes(ebml_w, item.attrs);
encode_path(ebml_w, path.clone());
encode_visibility(ebml_w, vis);
Expand Down Expand Up @@ -1070,7 +1070,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 'i');
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_attributes(ebml_w, item.attrs);
match ty.node {
ast::TyPath(ref path, ref bounds, _) if path.segments
Expand Down Expand Up @@ -1134,7 +1134,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
tag_items_data_item_ty_param_bounds);
encode_region_param_defs(ebml_w, trait_def.generics.region_param_defs());
encode_trait_ref(ebml_w, ecx, trait_def.trait_ref, tag_item_trait_ref);
encode_name(ebml_w, item.ident);
encode_name(ebml_w, item.ident.name);
encode_attributes(ebml_w, item.attrs);
encode_visibility(ebml_w, vis);
for &method_def_id in ty::trait_method_def_ids(tcx, def_id).iter() {
Expand Down Expand Up @@ -1255,7 +1255,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
encode_family(ebml_w, purity_fn_family(ImpureFn));
encode_bounds_and_type(ebml_w, ecx,
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
encode_name(ebml_w, nitem.ident);
encode_name(ebml_w, nitem.ident.name);
if abi.is_intrinsic() {
(ecx.encode_inlined_item)(ecx, ebml_w, IIForeignRef(nitem));
} else {
Expand All @@ -1270,7 +1270,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
}
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
encode_symbol(ecx, ebml_w, nitem.id);
encode_name(ebml_w, nitem.ident);
encode_name(ebml_w, nitem.ident.name);
}
}
encode_path(ebml_w, path);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
'[' => {
let def = parse_def(st, RegionParameter, |x,y| conv(x,y));
let ident = token::str_to_ident(parse_str(st, ']'));
ty::BrNamed(def, ident)
ty::BrNamed(def, ident.name)
}
'f' => {
let id = parse_uint(st);
Expand Down Expand Up @@ -242,7 +242,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
let index = parse_uint(st);
assert_eq!(next(st), '|');
let nm = token::str_to_ident(parse_str(st, ']'));
ty::ReEarlyBound(node_id, index, nm)
ty::ReEarlyBound(node_id, index, nm.name)
}
'f' => {
assert_eq!(next(st), '[');
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn enc_region(w: &mut MemWriter, cx: @ctxt, r: ty::Region) {
mywrite!(w, "B[{}|{}|{}]",
node_id,
index,
token::get_ident(ident));
token::get_name(ident));
}
ty::ReFree(ref fr) => {
mywrite!(w, "f[{}|", fr.scope_id);
Expand Down Expand Up @@ -210,7 +210,7 @@ fn enc_bound_region(w: &mut MemWriter, cx: @ctxt, br: ty::BoundRegion) {
ty::BrNamed(d, s) => {
mywrite!(w, "[{}|{}]",
(cx.ds)(d),
token::get_ident(s));
token::get_name(s));
}
ty::BrFresh(id) => {
mywrite!(w, "f{}|", id);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> Visitor<&'a ScopeChain<'a>> for LifetimeContext {
fn visit_lifetime_ref(&mut self,
lifetime_ref: &ast::Lifetime,
scope: &'a ScopeChain<'a>) {
if lifetime_ref.ident == special_idents::statik {
if lifetime_ref.ident == special_idents::statik.name {
self.insert_lifetime(lifetime_ref, ast::DefStaticRegion);
return;
}
Expand Down Expand Up @@ -262,7 +262,7 @@ impl LifetimeContext {
self.sess.span_err(
lifetime_ref.span,
format!("use of undeclared lifetime name `'{}`",
token::get_ident(lifetime_ref.ident)));
token::get_name(lifetime_ref.ident)));
}

fn check_lifetime_names(&self, lifetimes: &OptVec<ast::Lifetime>) {
Expand All @@ -271,11 +271,11 @@ impl LifetimeContext {

let special_idents = [special_idents::statik];
for lifetime in lifetimes.iter() {
if special_idents.iter().any(|&i| i == lifetime.ident) {
if special_idents.iter().any(|&i| i.name == lifetime.ident) {
self.sess.span_err(
lifetime.span,
format!("illegal lifetime parameter name: `{}`",
token::get_ident(lifetime.ident)));
token::get_name(lifetime.ident)));
}
}

Expand All @@ -287,7 +287,7 @@ impl LifetimeContext {
lifetime_j.span,
format!("lifetime name `'{}` declared twice in \
the same scope",
token::get_ident(lifetime_j.ident)));
token::get_name(lifetime_j.ident)));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ pub enum Region {
// Region bound in a type or fn declaration which will be
// substituted 'early' -- that is, at the same time when type
// parameters are substituted.
ReEarlyBound(/* param id */ ast::NodeId, /*index*/ uint, ast::Ident),
ReEarlyBound(/* param id */ ast::NodeId, /*index*/ uint, ast::Name),

// Region bound in a function scope, which will be substituted when the
// function is called. The first argument must be the `binder_id` of
Expand Down Expand Up @@ -635,7 +635,7 @@ pub enum BoundRegion {
///
/// The def-id is needed to distinguish free regions in
/// the event of shadowing.
BrNamed(ast::DefId, ast::Ident),
BrNamed(ast::DefId, ast::Name),

/// Fresh bound identifiers created during GLB computations.
BrFresh(uint),
Expand Down Expand Up @@ -976,7 +976,7 @@ pub struct TypeParameterDef {

#[deriving(Encodable, Decodable, Clone)]
pub struct RegionParameterDef {
ident: ast::Ident,
ident: ast::Name,
def_id: ast::DefId,
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn bound_region_to_str(cx: ctxt,

match br {
BrNamed(_, ident) => format!("{}'{}{}", prefix,
token::get_ident(ident), space_str),
token::get_name(ident), space_str),
BrAnon(_) => prefix.to_str(),
BrFresh(_) => prefix.to_str(),
}
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn region_to_str(cx: ctxt, prefix: &str, space: bool, region: Region) -> ~st
// `explain_region()` or `note_and_explain_region()`.
match region {
ty::ReScope(_) => prefix.to_str(),
ty::ReEarlyBound(_, _, ident) => token::get_ident(ident).get().to_str(),
ty::ReEarlyBound(_, _, ident) => token::get_name(ident).get().to_str(),
ty::ReLateBound(_, br) => bound_region_to_str(cx, prefix, space, br),
ty::ReFree(ref fr) => bound_region_to_str(cx, prefix, space, fr.bound_region),
ty::ReInfer(ReSkolemized(_, br)) => {
Expand Down Expand Up @@ -630,7 +630,7 @@ impl Repr for ty::TypeParameterDef {
impl Repr for ty::RegionParameterDef {
fn repr(&self, _tcx: ctxt) -> ~str {
format!("RegionParameterDef({}, {:?})",
token::get_ident(self.ident),
token::get_name(self.ident),
self.def_id)
}
}
Expand Down Expand Up @@ -718,7 +718,7 @@ impl Repr for ty::BoundRegion {
ty::BrAnon(id) => format!("BrAnon({})", id),
ty::BrNamed(id, ident) => format!("BrNamed({}, {})",
id.repr(tcx),
ident.repr(tcx)),
token::get_name(ident)),
ty::BrFresh(id) => format!("BrFresh({})", id),
}
}
Expand All @@ -729,7 +729,7 @@ impl Repr for ty::Region {
match *self {
ty::ReEarlyBound(id, index, ident) => {
format!("ReEarlyBound({}, {}, {})",
id, index, ident.repr(tcx))
id, index, token::get_name(ident))
}

ty::ReLateBound(binder_id, ref bound_region) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl Lifetime {

impl Clean<Lifetime> for ast::Lifetime {
fn clean(&self) -> Lifetime {
Lifetime(self.ident.clean())
Lifetime(token::get_name(self.ident).get().to_owned())
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ pub type FnIdent = Option<Ident>;
pub struct Lifetime {
id: NodeId,
span: Span,
// FIXME #7743 : change this to Name!
ident: Ident
ident: Name
}

// a "Path" is essentially Rust's notion of a name;
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait AstBuilder {

fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime;
fn lifetime(&self, span: Span, ident: ast::Name) -> ast::Lifetime;

// statements
fn stmt_expr(&self, expr: @ast::Expr) -> @ast::Stmt;
Expand Down Expand Up @@ -408,7 +408,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
ast::TraitTyParamBound(self.trait_ref(path))
}

fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime {
fn lifetime(&self, span: Span, ident: ast::Name) -> ast::Lifetime {
ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, ident: ident }
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/deriving/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ pub fn nil_ty() -> Ty<'static> {

fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
match *lt {
Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s))),
Some(ref s) => Some(cx.lifetime(span, cx.ident_of(*s).name)),
None => None
}
}

fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
match *lt {
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s))),
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s).name)),
None => opt_vec::Empty
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<'a> LifetimeBounds<'a> {
self_generics: &Generics)
-> Generics {
let lifetimes = self.lifetimes.map(|lt| {
cx.lifetime(span, cx.ident_of(*lt))
cx.lifetime(span, cx.ident_of(*lt).name)
});
let ty_params = self.bounds.map(|t| {
match t {
Expand All @@ -248,7 +248,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
match *ptr {
Send => ast::SelfUniq,
Borrowed(ref lt, mutbl) => {
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s)));
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name));
ast::SelfRegion(lt, mutbl)
}
});
Expand Down
Loading