Skip to content

Commit

Permalink
Changed lists of lifetimes in ast and ty to use Vec instead of OptVec.
Browse files Browse the repository at this point in the history
There is a broader revision (that does this across the board) pending
in #12675, but that is awaiting the arrival of more data (to decide
whether to keep OptVec alive by using a non-Vec internally).

For this code, the representation of lifetime lists needs to be the
same in both ScopeChain and in the ast and ty structures.  So it
seemed cleanest to just use `vec_ng::Vec`, now that it has a cheaper
empty representation than the current `vec` code.
  • Loading branch information
pnkfelix committed Mar 12, 2014
1 parent 28ebec5 commit 586b619
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/librustc/front/std_inject.rs
Expand Up @@ -164,12 +164,12 @@ impl fold::Folder for PreludeInjector {
segments: vec!(
ast::PathSegment {
identifier: token::str_to_ident("std"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
},
ast::PathSegment {
identifier: token::str_to_ident("prelude"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}),
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/front/test.rs
Expand Up @@ -369,7 +369,7 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
global: false,
segments: ids.move_iter().map(|identifier| ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}).collect()
}
Expand All @@ -381,7 +381,7 @@ fn path_node_global(ids: Vec<ast::Ident> ) -> ast::Path {
global: true,
segments: ids.move_iter().map(|identifier| ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}).collect()
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/privacy.rs
Expand Up @@ -13,6 +13,7 @@
//! which are available for use externally when compiled as a library.

use std::mem::replace;
use std::vec_ng::Vec;

use metadata::csearch;
use middle::lint;
Expand Down Expand Up @@ -855,7 +856,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
debug!("privacy - list {}", pid.node.id);
let seg = ast::PathSegment {
identifier: pid.node.name,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
};
let segs = vec!(seg);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -19,10 +19,10 @@

use driver::session;
use std::cell::RefCell;
use std::vec_ng::Vec;
use util::nodemap::NodeMap;
use syntax::ast;
use syntax::codemap::Span;
use syntax::opt_vec::OptVec;
use syntax::parse::token::special_idents;
use syntax::parse::token;
use syntax::print::pprust::{lifetime_to_str};
Expand All @@ -39,8 +39,8 @@ struct LifetimeContext {
}

enum ScopeChain<'a> {
ItemScope(&'a OptVec<ast::Lifetime>),
FnScope(ast::NodeId, &'a OptVec<ast::Lifetime>, Scope<'a>),
ItemScope(&'a Vec<ast::Lifetime>),
FnScope(ast::NodeId, &'a Vec<ast::Lifetime>, Scope<'a>),
BlockScope(ast::NodeId, Scope<'a>),
RootScope
}
Expand Down Expand Up @@ -267,7 +267,7 @@ impl LifetimeContext {
token::get_name(lifetime_ref.name)));
}

fn check_lifetime_names(&self, lifetimes: &OptVec<ast::Lifetime>) {
fn check_lifetime_names(&self, lifetimes: &Vec<ast::Lifetime>) {
for i in range(0, lifetimes.len()) {
let lifetime_i = lifetimes.get(i);

Expand Down Expand Up @@ -313,7 +313,7 @@ impl LifetimeContext {
}
}

fn search_lifetimes(lifetimes: &OptVec<ast::Lifetime>,
fn search_lifetimes(lifetimes: &Vec<ast::Lifetime>,
lifetime_ref: &ast::Lifetime)
-> Option<(uint, ast::NodeId)> {
for (i, lifetime_decl) in lifetimes.iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/debuginfo.rs
Expand Up @@ -540,7 +540,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
return FunctionWithoutDebugInfo;
}

let empty_generics = ast::Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty };
let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: opt_vec::Empty };

let fnitem = cx.tcx.map.get(fn_ast_id);

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/astconv.rs
Expand Up @@ -186,9 +186,9 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
}

match anon_regions {
Ok(v) => opt_vec::from(v.move_iter().collect()),
Err(()) => opt_vec::from(Vec::from_fn(expected_num_region_params,
|_| ty::ReStatic)) // hokey
Ok(v) => v.move_iter().collect(),
Err(()) => Vec::from_fn(expected_num_region_params,
|_| ty::ReStatic) // hokey
}
};

Expand Down Expand Up @@ -231,7 +231,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
.collect();

let mut substs = substs {
regions: ty::NonerasedRegions(regions),
regions: ty::NonerasedRegions(opt_vec::from(regions)),
self_ty: self_ty,
tps: tps
};
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -1453,8 +1453,7 @@ pub fn impl_self_ty(vcx: &VtableContext,
let tps = vcx.infcx.next_ty_vars(n_tps);

let substs = substs {
regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter()
.collect())),
regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter().collect())),
self_ty: None,
tps: tps,
};
Expand Down Expand Up @@ -3741,11 +3740,11 @@ pub fn instantiate_path(fcx: @FnCtxt,
nsupplied = num_supplied_regions));
}

opt_vec::from(fcx.infcx().next_region_vars(
fcx.infcx().next_region_vars(
infer::BoundRegionInTypeOrImpl(span),
num_expected_regions).move_iter().collect())
num_expected_regions).move_iter().collect()
};
let regions = ty::NonerasedRegions(regions);
let regions = ty::NonerasedRegions(opt_vec::from(regions));

// Special case: If there is a self parameter, omit it from the list of
// type parameters.
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ast.rs
Expand Up @@ -142,7 +142,7 @@ pub struct PathSegment {
/// The identifier portion of this path segment.
identifier: Ident,
/// The lifetime parameters for this path segment.
lifetimes: OptVec<Lifetime>,
lifetimes: Vec<Lifetime>,
/// The type parameters for this path segment, if present.
types: OptVec<P<Ty>>,
}
Expand Down Expand Up @@ -187,7 +187,7 @@ pub struct TyParam {

#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
pub struct Generics {
lifetimes: OptVec<Lifetime>,
lifetimes: Vec<Lifetime>,
ty_params: OptVec<TyParam>,
}

Expand Down Expand Up @@ -795,7 +795,7 @@ impl fmt::Show for Onceness {
pub struct ClosureTy {
sigil: Sigil,
region: Option<Lifetime>,
lifetimes: OptVec<Lifetime>,
lifetimes: Vec<Lifetime>,
purity: Purity,
onceness: Onceness,
decl: P<FnDecl>,
Expand All @@ -810,7 +810,7 @@ pub struct ClosureTy {
pub struct BareFnTy {
purity: Purity,
abis: AbiSet,
lifetimes: OptVec<Lifetime>,
lifetimes: Vec<Lifetime>,
decl: P<FnDecl>
}

Expand Down
7 changes: 4 additions & 3 deletions src/libsyntax/ast_util.rs
Expand Up @@ -195,7 +195,7 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
segments: vec!(
ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
),
Expand Down Expand Up @@ -311,7 +311,7 @@ pub fn operator_prec(op: ast::BinOp) -> uint {
pub static as_prec: uint = 12u;

pub fn empty_generics() -> Generics {
Generics {lifetimes: opt_vec::Empty,
Generics {lifetimes: Vec::new(),
ty_params: opt_vec::Empty}
}

Expand Down Expand Up @@ -690,10 +690,11 @@ mod test {
use ast::*;
use super::*;
use opt_vec;
use std::vec_ng::Vec;

fn ident_to_segment(id : &Ident) -> PathSegment {
PathSegment {identifier:id.clone(),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty}
}

Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ext/build.rs
Expand Up @@ -42,7 +42,7 @@ pub trait AstBuilder {
fn path_all(&self, sp: Span,
global: bool,
idents: Vec<ast::Ident> ,
lifetimes: OptVec<ast::Lifetime>,
lifetimes: Vec<ast::Lifetime>,
types: Vec<P<ast::Ty>> )
-> ast::Path;

Expand Down Expand Up @@ -255,27 +255,27 @@ pub trait AstBuilder {

impl<'a> AstBuilder for ExtCtxt<'a> {
fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
self.path_all(span, false, strs, opt_vec::Empty, Vec::new())
self.path_all(span, false, strs, Vec::new(), Vec::new())
}
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
self.path(span, vec!(id))
}
fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
self.path_all(span, true, strs, opt_vec::Empty, Vec::new())
self.path_all(span, true, strs, Vec::new(), Vec::new())
}
fn path_all(&self,
sp: Span,
global: bool,
mut idents: Vec<ast::Ident> ,
lifetimes: OptVec<ast::Lifetime>,
lifetimes: Vec<ast::Lifetime>,
types: Vec<P<ast::Ty>> )
-> ast::Path {
let last_identifier = idents.pop().unwrap();
let mut segments: Vec<ast::PathSegment> = idents.move_iter()
.map(|ident| {
ast::PathSegment {
identifier: ident,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
}).collect();
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.ident_of("option"),
self.ident_of("Option")
),
opt_vec::Empty,
Vec::new(),
vec!( ty )), None)
}

Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/ext/concat_idents.rs
Expand Up @@ -15,6 +15,7 @@ use ext::base;
use opt_vec;
use parse::token;
use parse::token::{str_to_ident};
use std::vec_ng::Vec;

pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult {
Expand Down Expand Up @@ -51,7 +52,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
segments: vec!(
ast::PathSegment {
identifier: res,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
)
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/ext/deriving/rand.rs
Expand Up @@ -14,7 +14,6 @@ use codemap::Span;
use ext::base::ExtCtxt;
use ext::build::{AstBuilder};
use ext::deriving::generic::*;
use opt_vec;

use std::vec_ng::Vec;

Expand Down Expand Up @@ -84,7 +83,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
let rand_name = cx.path_all(trait_span,
true,
rand_ident.clone(),
opt_vec::Empty,
Vec::new(),
Vec::new());
let rand_name = cx.expr_path(rand_name);

Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ext/deriving/ty.rs
Expand Up @@ -19,7 +19,6 @@ use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use codemap::{Span,respan};
use opt_vec;
use opt_vec::OptVec;

use std::vec_ng::Vec;

Expand Down Expand Up @@ -118,11 +117,12 @@ fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifet
}
}

fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
match *lt {
fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
let lifetimes = match *lt {
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s).name)),
None => opt_vec::Empty
}
};
opt_vec::take_vec(lifetimes)
}

impl<'a> Ty<'a> {
Expand Down Expand Up @@ -199,7 +199,7 @@ fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path],

fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics {
Generics {
lifetimes: opt_vec::from(lifetimes),
lifetimes: lifetimes,
ty_params: opt_vec::from(ty_params)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/env.rs
Expand Up @@ -19,10 +19,10 @@ use codemap::Span;
use ext::base::*;
use ext::base;
use ext::build::AstBuilder;
use opt_vec;
use parse::token;

use std::os;
use std::vec_ng::Vec;

pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult {
Expand All @@ -38,7 +38,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
vec!(cx.ident_of("std"),
cx.ident_of("option"),
cx.ident_of("None")),
opt_vec::Empty,
Vec::new(),
vec!(cx.ty_rptr(sp,
cx.ty_ident(sp,
cx.ident_of("str")),
Expand Down
7 changes: 3 additions & 4 deletions src/libsyntax/ext/format.rs
Expand Up @@ -14,7 +14,6 @@ use codemap::{Span, respan};
use ext::base::*;
use ext::base;
use ext::build::AstBuilder;
use opt_vec;
use parse::token::InternedString;
use parse::token;
use rsparse = parse;
Expand Down Expand Up @@ -509,7 +508,7 @@ impl<'a> Context<'a> {
sp,
true,
self.rtpath("Method"),
opt_vec::with(life),
vec!(life),
Vec::new()
), None);
let st = ast::ItemStatic(ty, ast::MutImmutable, method);
Expand Down Expand Up @@ -632,8 +631,8 @@ impl<'a> Context<'a> {
self.ecx.ident_of("fmt"),
self.ecx.ident_of("rt"),
self.ecx.ident_of("Piece")),
opt_vec::with(
self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)),
vec!(self.ecx.lifetime(self.fmtsp,
self.ecx.ident_of("static").name)),
Vec::new()
), None);
let ty = ast::TyFixedLengthVec(
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/fold.rs
Expand Up @@ -439,8 +439,8 @@ pub fn fold_lifetime<T: Folder>(l: &Lifetime, fld: &mut T) -> Lifetime {
}
}

pub fn fold_lifetimes<T: Folder>(lts: &OptVec<Lifetime>, fld: &mut T)
-> OptVec<Lifetime> {
pub fn fold_lifetimes<T: Folder>(lts: &Vec<Lifetime>, fld: &mut T)
-> Vec<Lifetime> {
lts.map(|l| fold_lifetime(l, fld))
}

Expand Down

0 comments on commit 586b619

Please sign in to comment.