1
Fork 0

Changed lists of lifetimes in ast and ty to use Vec instead of OptVec.

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.
This commit is contained in:
Felix S. Klock II 2014-03-07 16:50:40 +01:00
parent 28ebec5160
commit 586b619c76
19 changed files with 72 additions and 71 deletions

View file

@ -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,
}),
};

View file

@ -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()
}
@ -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()
}

View file

@ -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;
@ -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);

View file

@ -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};
@ -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
}
@ -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);
@ -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() {

View file

@ -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);

View file

@ -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
}
};
@ -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
};

View file

@ -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,
};
@ -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.

View file

@ -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>>,
}
@ -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>,
}
@ -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>,
@ -810,7 +810,7 @@ pub struct ClosureTy {
pub struct BareFnTy {
purity: Purity,
abis: AbiSet,
lifetimes: OptVec<Lifetime>,
lifetimes: Vec<Lifetime>,
decl: P<FnDecl>
}

View file

@ -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,
}
),
@ -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}
}
@ -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}
}

View file

@ -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;
@ -255,19 +255,19 @@ 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();
@ -275,7 +275,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
.map(|ident| {
ast::PathSegment {
identifier: ident,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
}).collect();
@ -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)
}

View file

@ -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 {
@ -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,
}
)

View file

@ -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;
@ -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);

View file

@ -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;
@ -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> {
@ -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)
}
}

View file

@ -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 {
@ -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")),

View file

@ -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;
@ -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);
@ -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(

View file

@ -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))
}

View file

@ -556,7 +556,7 @@ mod test {
segments: vec!(
ast::PathSegment {
identifier: str_to_ident("d"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
),
@ -578,7 +578,7 @@ mod test {
segments: vec!(
ast::PathSegment {
identifier: str_to_ident("b"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
),
@ -605,7 +605,7 @@ mod test {
segments: vec!(
ast::PathSegment {
identifier: str_to_ident("b"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
),
@ -633,7 +633,7 @@ mod test {
ast::PathSegment {
identifier:
str_to_ident("int"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
),
@ -651,7 +651,7 @@ mod test {
ast::PathSegment {
identifier:
str_to_ident("b"),
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
),
@ -671,7 +671,7 @@ mod test {
ast::ImpureFn,
abi::AbiSet::Rust(),
ast::Generics{ // no idea on either of these:
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
ty_params: opt_vec::Empty,
},
ast::P(ast::Block {
@ -689,7 +689,7 @@ mod test {
str_to_ident(
"b"),
lifetimes:
opt_vec::Empty,
Vec::new(),
types:
opt_vec::Empty
}

View file

@ -958,7 +958,7 @@ impl Parser {
lifetimes
} else {
opt_vec::Empty
Vec::new()
};
let inputs = if self.eat(&token::OROR) {
@ -1015,7 +1015,7 @@ impl Parser {
// parse a function type (following the 'fn')
pub fn parse_ty_fn_decl(&mut self, allow_variadic: bool)
-> (P<FnDecl>, OptVec<ast::Lifetime>) {
-> (P<FnDecl>, Vec<ast::Lifetime>) {
/*
(fn) <'lt> (S) -> T
@ -1031,7 +1031,7 @@ impl Parser {
self.expect_gt();
lifetimes
} else {
opt_vec::Empty
Vec::new()
};
let (inputs, variadic) = self.parse_fn_args(false, allow_variadic);
@ -1510,7 +1510,7 @@ impl Parser {
segments.push(PathSegmentAndBoundSet {
segment: ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
},
bound_set: bound_set
@ -1525,7 +1525,7 @@ impl Parser {
self.parse_generic_values_after_lt();
(true, lifetimes, opt_vec::from(types))
} else {
(false, opt_vec::Empty, opt_vec::Empty)
(false, Vec::new(), opt_vec::Empty)
}
};
@ -1621,7 +1621,7 @@ impl Parser {
// matches lifetimes = ( lifetime ) | ( lifetime , lifetimes )
// actually, it matches the empty one too, but putting that in there
// messes up the grammar....
pub fn parse_lifetimes(&mut self) -> OptVec<ast::Lifetime> {
pub fn parse_lifetimes(&mut self) -> Vec<ast::Lifetime> {
/*!
*
* Parses zero or more comma separated lifetimes.
@ -1630,7 +1630,7 @@ impl Parser {
* lists, where we expect something like `<'a, 'b, T>`.
*/
let mut res = opt_vec::Empty;
let mut res = Vec::new();
loop {
match self.token {
token::LIFETIME(_) => {
@ -1995,7 +1995,7 @@ impl Parser {
self.expect(&token::LT);
self.parse_generic_values_after_lt()
} else {
(opt_vec::Empty, Vec::new())
(Vec::new(), Vec::new())
};
// expr.f() method call
@ -3515,7 +3515,7 @@ impl Parser {
}
}
fn parse_generic_values_after_lt(&mut self) -> (OptVec<ast::Lifetime>, Vec<P<Ty>> ) {
fn parse_generic_values_after_lt(&mut self) -> (Vec<ast::Lifetime>, Vec<P<Ty>> ) {
let lifetimes = self.parse_lifetimes();
let result = self.parse_seq_to_gt(
Some(token::COMMA),
@ -4886,7 +4886,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| {
ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
}).collect()
@ -4921,7 +4921,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| {
ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
}).collect()
@ -4939,7 +4939,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| {
ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
}).collect()
@ -4961,7 +4961,7 @@ impl Parser {
segments: path.move_iter().map(|identifier| {
ast::PathSegment {
identifier: identifier,
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
types: opt_vec::Empty,
}
}).collect()

View file

@ -15,6 +15,7 @@ use codemap::Span;
use parse;
use opt_vec;
use opt_vec::OptVec;
use std::vec_ng::Vec;
// Context-passing AST walker. Each overridden visit method has full control
// over what happens with its node, it can do its own traversal of the node's
@ -55,7 +56,7 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics {
}
FkFnBlock(..) => {
Generics {
lifetimes: opt_vec::Empty,
lifetimes: Vec::new(),
ty_params: opt_vec::Empty,
}
}
@ -370,7 +371,7 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
}
fn walk_lifetime_decls<E: Clone, V: Visitor<E>>(visitor: &mut V,
lifetimes: &OptVec<Lifetime>,
lifetimes: &Vec<Lifetime>,
env: E) {
for l in lifetimes.iter() {
visitor.visit_lifetime_decl(l, env.clone());