Skip to content

Commit 586b619

Browse files
committed
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.
1 parent 28ebec5 commit 586b619

File tree

19 files changed

+72
-71
lines changed

19 files changed

+72
-71
lines changed

src/librustc/front/std_inject.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ impl fold::Folder for PreludeInjector {
164164
segments: vec!(
165165
ast::PathSegment {
166166
identifier: token::str_to_ident("std"),
167-
lifetimes: opt_vec::Empty,
167+
lifetimes: Vec::new(),
168168
types: opt_vec::Empty,
169169
},
170170
ast::PathSegment {
171171
identifier: token::str_to_ident("prelude"),
172-
lifetimes: opt_vec::Empty,
172+
lifetimes: Vec::new(),
173173
types: opt_vec::Empty,
174174
}),
175175
};

src/librustc/front/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
369369
global: false,
370370
segments: ids.move_iter().map(|identifier| ast::PathSegment {
371371
identifier: identifier,
372-
lifetimes: opt_vec::Empty,
372+
lifetimes: Vec::new(),
373373
types: opt_vec::Empty,
374374
}).collect()
375375
}
@@ -381,7 +381,7 @@ fn path_node_global(ids: Vec<ast::Ident> ) -> ast::Path {
381381
global: true,
382382
segments: ids.move_iter().map(|identifier| ast::PathSegment {
383383
identifier: identifier,
384-
lifetimes: opt_vec::Empty,
384+
lifetimes: Vec::new(),
385385
types: opt_vec::Empty,
386386
}).collect()
387387
}

src/librustc/middle/privacy.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! which are available for use externally when compiled as a library.
1414
1515
use std::mem::replace;
16+
use std::vec_ng::Vec;
1617

1718
use metadata::csearch;
1819
use middle::lint;
@@ -855,7 +856,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
855856
debug!("privacy - list {}", pid.node.id);
856857
let seg = ast::PathSegment {
857858
identifier: pid.node.name,
858-
lifetimes: opt_vec::Empty,
859+
lifetimes: Vec::new(),
859860
types: opt_vec::Empty,
860861
};
861862
let segs = vec!(seg);

src/librustc/middle/resolve_lifetime.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
use driver::session;
2121
use std::cell::RefCell;
22+
use std::vec_ng::Vec;
2223
use util::nodemap::NodeMap;
2324
use syntax::ast;
2425
use syntax::codemap::Span;
25-
use syntax::opt_vec::OptVec;
2626
use syntax::parse::token::special_idents;
2727
use syntax::parse::token;
2828
use syntax::print::pprust::{lifetime_to_str};
@@ -39,8 +39,8 @@ struct LifetimeContext {
3939
}
4040

4141
enum ScopeChain<'a> {
42-
ItemScope(&'a OptVec<ast::Lifetime>),
43-
FnScope(ast::NodeId, &'a OptVec<ast::Lifetime>, Scope<'a>),
42+
ItemScope(&'a Vec<ast::Lifetime>),
43+
FnScope(ast::NodeId, &'a Vec<ast::Lifetime>, Scope<'a>),
4444
BlockScope(ast::NodeId, Scope<'a>),
4545
RootScope
4646
}
@@ -267,7 +267,7 @@ impl LifetimeContext {
267267
token::get_name(lifetime_ref.name)));
268268
}
269269

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

@@ -313,7 +313,7 @@ impl LifetimeContext {
313313
}
314314
}
315315

316-
fn search_lifetimes(lifetimes: &OptVec<ast::Lifetime>,
316+
fn search_lifetimes(lifetimes: &Vec<ast::Lifetime>,
317317
lifetime_ref: &ast::Lifetime)
318318
-> Option<(uint, ast::NodeId)> {
319319
for (i, lifetime_decl) in lifetimes.iter().enumerate() {

src/librustc/middle/trans/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
540540
return FunctionWithoutDebugInfo;
541541
}
542542

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

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

src/librustc/middle/typeck/astconv.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
186186
}
187187

188188
match anon_regions {
189-
Ok(v) => opt_vec::from(v.move_iter().collect()),
190-
Err(()) => opt_vec::from(Vec::from_fn(expected_num_region_params,
191-
|_| ty::ReStatic)) // hokey
189+
Ok(v) => v.move_iter().collect(),
190+
Err(()) => Vec::from_fn(expected_num_region_params,
191+
|_| ty::ReStatic) // hokey
192192
}
193193
};
194194

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

233233
let mut substs = substs {
234-
regions: ty::NonerasedRegions(regions),
234+
regions: ty::NonerasedRegions(opt_vec::from(regions)),
235235
self_ty: self_ty,
236236
tps: tps
237237
};

src/librustc/middle/typeck/check/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,7 @@ pub fn impl_self_ty(vcx: &VtableContext,
14531453
let tps = vcx.infcx.next_ty_vars(n_tps);
14541454

14551455
let substs = substs {
1456-
regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter()
1457-
.collect())),
1456+
regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter().collect())),
14581457
self_ty: None,
14591458
tps: tps,
14601459
};
@@ -3741,11 +3740,11 @@ pub fn instantiate_path(fcx: @FnCtxt,
37413740
nsupplied = num_supplied_regions));
37423741
}
37433742

3744-
opt_vec::from(fcx.infcx().next_region_vars(
3743+
fcx.infcx().next_region_vars(
37453744
infer::BoundRegionInTypeOrImpl(span),
3746-
num_expected_regions).move_iter().collect())
3745+
num_expected_regions).move_iter().collect()
37473746
};
3748-
let regions = ty::NonerasedRegions(regions);
3747+
let regions = ty::NonerasedRegions(opt_vec::from(regions));
37493748

37503749
// Special case: If there is a self parameter, omit it from the list of
37513750
// type parameters.

src/libsyntax/ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub struct PathSegment {
142142
/// The identifier portion of this path segment.
143143
identifier: Ident,
144144
/// The lifetime parameters for this path segment.
145-
lifetimes: OptVec<Lifetime>,
145+
lifetimes: Vec<Lifetime>,
146146
/// The type parameters for this path segment, if present.
147147
types: OptVec<P<Ty>>,
148148
}
@@ -187,7 +187,7 @@ pub struct TyParam {
187187

188188
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
189189
pub struct Generics {
190-
lifetimes: OptVec<Lifetime>,
190+
lifetimes: Vec<Lifetime>,
191191
ty_params: OptVec<TyParam>,
192192
}
193193

@@ -795,7 +795,7 @@ impl fmt::Show for Onceness {
795795
pub struct ClosureTy {
796796
sigil: Sigil,
797797
region: Option<Lifetime>,
798-
lifetimes: OptVec<Lifetime>,
798+
lifetimes: Vec<Lifetime>,
799799
purity: Purity,
800800
onceness: Onceness,
801801
decl: P<FnDecl>,
@@ -810,7 +810,7 @@ pub struct ClosureTy {
810810
pub struct BareFnTy {
811811
purity: Purity,
812812
abis: AbiSet,
813-
lifetimes: OptVec<Lifetime>,
813+
lifetimes: Vec<Lifetime>,
814814
decl: P<FnDecl>
815815
}
816816

src/libsyntax/ast_util.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
195195
segments: vec!(
196196
ast::PathSegment {
197197
identifier: identifier,
198-
lifetimes: opt_vec::Empty,
198+
lifetimes: Vec::new(),
199199
types: opt_vec::Empty,
200200
}
201201
),
@@ -311,7 +311,7 @@ pub fn operator_prec(op: ast::BinOp) -> uint {
311311
pub static as_prec: uint = 12u;
312312

313313
pub fn empty_generics() -> Generics {
314-
Generics {lifetimes: opt_vec::Empty,
314+
Generics {lifetimes: Vec::new(),
315315
ty_params: opt_vec::Empty}
316316
}
317317

@@ -690,10 +690,11 @@ mod test {
690690
use ast::*;
691691
use super::*;
692692
use opt_vec;
693+
use std::vec_ng::Vec;
693694

694695
fn ident_to_segment(id : &Ident) -> PathSegment {
695696
PathSegment {identifier:id.clone(),
696-
lifetimes: opt_vec::Empty,
697+
lifetimes: Vec::new(),
697698
types: opt_vec::Empty}
698699
}
699700

src/libsyntax/ext/build.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait AstBuilder {
4242
fn path_all(&self, sp: Span,
4343
global: bool,
4444
idents: Vec<ast::Ident> ,
45-
lifetimes: OptVec<ast::Lifetime>,
45+
lifetimes: Vec<ast::Lifetime>,
4646
types: Vec<P<ast::Ty>> )
4747
-> ast::Path;
4848

@@ -255,27 +255,27 @@ pub trait AstBuilder {
255255

256256
impl<'a> AstBuilder for ExtCtxt<'a> {
257257
fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
258-
self.path_all(span, false, strs, opt_vec::Empty, Vec::new())
258+
self.path_all(span, false, strs, Vec::new(), Vec::new())
259259
}
260260
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
261261
self.path(span, vec!(id))
262262
}
263263
fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
264-
self.path_all(span, true, strs, opt_vec::Empty, Vec::new())
264+
self.path_all(span, true, strs, Vec::new(), Vec::new())
265265
}
266266
fn path_all(&self,
267267
sp: Span,
268268
global: bool,
269269
mut idents: Vec<ast::Ident> ,
270-
lifetimes: OptVec<ast::Lifetime>,
270+
lifetimes: Vec<ast::Lifetime>,
271271
types: Vec<P<ast::Ty>> )
272272
-> ast::Path {
273273
let last_identifier = idents.pop().unwrap();
274274
let mut segments: Vec<ast::PathSegment> = idents.move_iter()
275275
.map(|ident| {
276276
ast::PathSegment {
277277
identifier: ident,
278-
lifetimes: opt_vec::Empty,
278+
lifetimes: Vec::new(),
279279
types: opt_vec::Empty,
280280
}
281281
}).collect();
@@ -342,7 +342,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
342342
self.ident_of("option"),
343343
self.ident_of("Option")
344344
),
345-
opt_vec::Empty,
345+
Vec::new(),
346346
vec!( ty )), None)
347347
}
348348

src/libsyntax/ext/concat_idents.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ext::base;
1515
use opt_vec;
1616
use parse::token;
1717
use parse::token::{str_to_ident};
18+
use std::vec_ng::Vec;
1819

1920
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
2021
-> base::MacResult {
@@ -51,7 +52,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
5152
segments: vec!(
5253
ast::PathSegment {
5354
identifier: res,
54-
lifetimes: opt_vec::Empty,
55+
lifetimes: Vec::new(),
5556
types: opt_vec::Empty,
5657
}
5758
)

src/libsyntax/ext/deriving/rand.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use codemap::Span;
1414
use ext::base::ExtCtxt;
1515
use ext::build::{AstBuilder};
1616
use ext::deriving::generic::*;
17-
use opt_vec;
1817

1918
use std::vec_ng::Vec;
2019

@@ -84,7 +83,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
8483
let rand_name = cx.path_all(trait_span,
8584
true,
8685
rand_ident.clone(),
87-
opt_vec::Empty,
86+
Vec::new(),
8887
Vec::new());
8988
let rand_name = cx.expr_path(rand_name);
9089

src/libsyntax/ext/deriving/ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use ext::base::ExtCtxt;
1919
use ext::build::AstBuilder;
2020
use codemap::{Span,respan};
2121
use opt_vec;
22-
use opt_vec::OptVec;
2322

2423
use std::vec_ng::Vec;
2524

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

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

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

200200
fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics {
201201
Generics {
202-
lifetimes: opt_vec::from(lifetimes),
202+
lifetimes: lifetimes,
203203
ty_params: opt_vec::from(ty_params)
204204
}
205205
}

src/libsyntax/ext/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use codemap::Span;
1919
use ext::base::*;
2020
use ext::base;
2121
use ext::build::AstBuilder;
22-
use opt_vec;
2322
use parse::token;
2423

2524
use std::os;
25+
use std::vec_ng::Vec;
2626

2727
pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
2828
-> base::MacResult {
@@ -38,7 +38,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
3838
vec!(cx.ident_of("std"),
3939
cx.ident_of("option"),
4040
cx.ident_of("None")),
41-
opt_vec::Empty,
41+
Vec::new(),
4242
vec!(cx.ty_rptr(sp,
4343
cx.ty_ident(sp,
4444
cx.ident_of("str")),

src/libsyntax/ext/format.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use codemap::{Span, respan};
1414
use ext::base::*;
1515
use ext::base;
1616
use ext::build::AstBuilder;
17-
use opt_vec;
1817
use parse::token::InternedString;
1918
use parse::token;
2019
use rsparse = parse;
@@ -509,7 +508,7 @@ impl<'a> Context<'a> {
509508
sp,
510509
true,
511510
self.rtpath("Method"),
512-
opt_vec::with(life),
511+
vec!(life),
513512
Vec::new()
514513
), None);
515514
let st = ast::ItemStatic(ty, ast::MutImmutable, method);
@@ -632,8 +631,8 @@ impl<'a> Context<'a> {
632631
self.ecx.ident_of("fmt"),
633632
self.ecx.ident_of("rt"),
634633
self.ecx.ident_of("Piece")),
635-
opt_vec::with(
636-
self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)),
634+
vec!(self.ecx.lifetime(self.fmtsp,
635+
self.ecx.ident_of("static").name)),
637636
Vec::new()
638637
), None);
639638
let ty = ast::TyFixedLengthVec(

src/libsyntax/fold.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ pub fn fold_lifetime<T: Folder>(l: &Lifetime, fld: &mut T) -> Lifetime {
439439
}
440440
}
441441

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

0 commit comments

Comments
 (0)