Skip to content

Commit f5357cf

Browse files
committed
auto merge of #13016 : huonw/rust/new-opt-vec, r=cmr
Replace syntax::opt_vec with syntax::owned_slice The `owned_slice::OwnedSlice` is `(*T, uint)` (i.e. a direct equivalent to DSTs `~[T]`). This shaves two words off the old OptVec type; and also makes substituting in other implementations easy, by removing all the mutation methods. (And also everything that's very rarely/never used.)
2 parents bbf8cdc + e33676b commit f5357cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+369
-451
lines changed

src/librustc/front/std_inject.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::codemap::DUMMY_SP;
1818
use syntax::codemap;
1919
use syntax::fold::Folder;
2020
use syntax::fold;
21-
use syntax::opt_vec;
21+
use syntax::owned_slice::OwnedSlice;
2222
use syntax::parse::token::InternedString;
2323
use syntax::parse::token;
2424
use syntax::util::small_vector::SmallVector;
@@ -156,12 +156,12 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
156156
ast::PathSegment {
157157
identifier: token::str_to_ident("std"),
158158
lifetimes: Vec::new(),
159-
types: opt_vec::Empty,
159+
types: OwnedSlice::empty(),
160160
},
161161
ast::PathSegment {
162162
identifier: token::str_to_ident("prelude"),
163163
lifetimes: Vec::new(),
164-
types: opt_vec::Empty,
164+
types: OwnedSlice::empty(),
165165
}),
166166
};
167167

src/librustc/front/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::ext::base::ExtCtxt;
3131
use syntax::ext::expand::ExpansionConfig;
3232
use syntax::fold::Folder;
3333
use syntax::fold;
34-
use syntax::opt_vec;
34+
use syntax::owned_slice::OwnedSlice;
3535
use syntax::parse::token::InternedString;
3636
use syntax::parse::token;
3737
use syntax::print::pprust;
@@ -377,7 +377,7 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
377377
segments: ids.move_iter().map(|identifier| ast::PathSegment {
378378
identifier: identifier,
379379
lifetimes: Vec::new(),
380-
types: opt_vec::Empty,
380+
types: OwnedSlice::empty(),
381381
}).collect()
382382
}
383383
}
@@ -389,7 +389,7 @@ fn path_node_global(ids: Vec<ast::Ident> ) -> ast::Path {
389389
segments: ids.move_iter().map(|identifier| ast::PathSegment {
390390
identifier: identifier,
391391
lifetimes: Vec::new(),
392-
types: opt_vec::Empty,
392+
types: OwnedSlice::empty(),
393393
}).collect()
394394
}
395395
}

src/librustc/metadata/tydecode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use syntax::abi::AbiSet;
2424
use syntax::abi;
2525
use syntax::ast;
2626
use syntax::ast::*;
27-
use syntax::opt_vec;
27+
use syntax::owned_slice::OwnedSlice;
2828
use syntax::parse::token;
2929

3030
// Compact string representation for ty::t values. API ty_str &
@@ -192,13 +192,13 @@ fn parse_region_substs(st: &mut PState, conv: conv_did) -> ty::RegionSubsts {
192192
match next(st) {
193193
'e' => ty::ErasedRegions,
194194
'n' => {
195-
let mut regions = opt_vec::Empty;
195+
let mut regions = vec!();
196196
while peek(st) != '.' {
197197
let r = parse_region(st, |x,y| conv(x,y));
198198
regions.push(r);
199199
}
200200
assert_eq!(next(st), '.');
201-
ty::NonerasedRegions(regions)
201+
ty::NonerasedRegions(OwnedSlice::from_vec(regions))
202202
}
203203
_ => fail!("parse_bound_region: bad input")
204204
}

src/librustc/middle/borrowck/move_data.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ use middle::typeck;
2626
use syntax::ast;
2727
use syntax::ast_util;
2828
use syntax::codemap::Span;
29-
use syntax::opt_vec::OptVec;
30-
use syntax::opt_vec;
3129
use util::ppaux::Repr;
3230

3331
pub struct MoveData {
@@ -316,15 +314,15 @@ impl MoveData {
316314

317315
fn existing_base_paths(&self,
318316
lp: @LoanPath)
319-
-> OptVec<MovePathIndex> {
320-
let mut result = opt_vec::Empty;
317+
-> Vec<MovePathIndex> {
318+
let mut result = vec!();
321319
self.add_existing_base_paths(lp, &mut result);
322320
result
323321
}
324322

325323
fn add_existing_base_paths(&self,
326324
lp: @LoanPath,
327-
result: &mut OptVec<MovePathIndex>) {
325+
result: &mut Vec<MovePathIndex>) {
328326
/*!
329327
* Adds any existing move path indices for `lp` and any base
330328
* paths of `lp` to `result`, but does not add new move paths

src/librustc/middle/cfg/construct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use middle::typeck;
1414
use middle::ty;
1515
use syntax::ast;
1616
use syntax::ast_util;
17-
use syntax::opt_vec;
1817
use util::nodemap::NodeMap;
1918

2019
struct CFGBuilder<'a> {
@@ -470,7 +469,7 @@ impl<'a> CFGBuilder<'a> {
470469
fn add_contained_edge(&mut self,
471470
source: CFGIndex,
472471
target: CFGIndex) {
473-
let data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
472+
let data = CFGEdgeData {exiting_scopes: vec!() };
474473
self.graph.add_edge(source, target, data);
475474
}
476475

@@ -479,9 +478,10 @@ impl<'a> CFGBuilder<'a> {
479478
from_index: CFGIndex,
480479
to_loop: LoopScope,
481480
to_index: CFGIndex) {
482-
let mut data = CFGEdgeData {exiting_scopes: opt_vec::Empty};
481+
let mut data = CFGEdgeData {exiting_scopes: vec!() };
483482
let mut scope_id = from_expr.id;
484483
while scope_id != to_loop.loop_id {
484+
485485
data.exiting_scopes.push(scope_id);
486486
scope_id = self.tcx.region_maps.encl_scope(scope_id);
487487
}

src/librustc/middle/cfg/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use middle::graph;
1919
use middle::ty;
2020
use middle::typeck;
2121
use syntax::ast;
22-
use syntax::opt_vec::OptVec;
2322
use util::nodemap::NodeMap;
2423

2524
mod construct;
@@ -36,7 +35,7 @@ pub struct CFGNodeData {
3635
}
3736

3837
pub struct CFGEdgeData {
39-
exiting_scopes: OptVec<ast::NodeId>
38+
exiting_scopes: Vec<ast::NodeId>
4039
}
4140

4241
pub type CFGIndex = graph::NodeIndex;

src/librustc/middle/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use util::ppaux::UserString;
1919
use syntax::ast::*;
2020
use syntax::attr;
2121
use syntax::codemap::Span;
22-
use syntax::opt_vec;
22+
use syntax::owned_slice::OwnedSlice;
2323
use syntax::print::pprust::expr_to_str;
2424
use syntax::{visit,ast_util};
2525
use syntax::visit::Visitor;
@@ -92,7 +92,7 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
9292
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
9393
if !struct_tpt.generics.has_type_params() {
9494
let struct_ty = ty::mk_struct(cx.tcx, struct_did, ty::substs {
95-
regions: ty::NonerasedRegions(opt_vec::Empty),
95+
regions: ty::NonerasedRegions(OwnedSlice::empty()),
9696
self_ty: None,
9797
tps: Vec::new()
9898
});

src/librustc/middle/privacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use syntax::ast_util::{is_local, def_id_of_def, local_def};
2828
use syntax::attr;
2929
use syntax::codemap::Span;
3030
use syntax::parse::token;
31-
use syntax::opt_vec;
31+
use syntax::owned_slice::OwnedSlice;
3232
use syntax::visit;
3333
use syntax::visit::Visitor;
3434

@@ -842,7 +842,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
842842
let seg = ast::PathSegment {
843843
identifier: pid.node.name,
844844
lifetimes: Vec::new(),
845-
types: opt_vec::Empty,
845+
types: OwnedSlice::empty(),
846846
};
847847
let segs = vec!(seg);
848848
let path = ast::Path {

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax::parse::token::special_idents;
2727
use syntax::parse::token;
2828
use syntax::print::pprust::path_to_str;
2929
use syntax::codemap::{Span, DUMMY_SP, Pos};
30-
use syntax::opt_vec::OptVec;
30+
use syntax::owned_slice::OwnedSlice;
3131
use syntax::visit;
3232
use syntax::visit::Visitor;
3333

@@ -3969,7 +3969,7 @@ impl<'a> Resolver<'a> {
39693969
}
39703970

39713971
fn resolve_type_parameters(&mut self,
3972-
type_parameters: &OptVec<TyParam>) {
3972+
type_parameters: &OwnedSlice<TyParam>) {
39733973
for type_parameter in type_parameters.iter() {
39743974
for bound in type_parameter.bounds.iter() {
39753975
self.resolve_type_parameter_bound(type_parameter.id, bound);

src/librustc/middle/resolve_lifetime.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use driver::session::Session;
2121
use util::nodemap::NodeMap;
2222
use syntax::ast;
2323
use syntax::codemap::Span;
24-
use syntax::opt_vec;
25-
use syntax::opt_vec::OptVec;
24+
use syntax::owned_slice::OwnedSlice;
2625
use syntax::parse::token::special_idents;
2726
use syntax::parse::token;
2827
use syntax::print::pprust::{lifetime_to_str};
@@ -413,22 +412,22 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti
413412
.collect()
414413
}
415414

416-
pub fn free_lifetimes(ty_params: &OptVec<ast::TyParam>) -> OptVec<ast::Name> {
415+
pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>) -> Vec<ast::Name> {
417416
/*!
418417
* Gathers up and returns the names of any lifetimes that appear
419418
* free in `ty_params`. Of course, right now, all lifetimes appear
420419
* free, since we don't currently have any binders in type parameter
421420
* declarations; just being forwards compatible with future extensions.
422421
*/
423422

424-
let mut collector = FreeLifetimeCollector { names: opt_vec::Empty };
423+
let mut collector = FreeLifetimeCollector { names: vec!() };
425424
for ty_param in ty_params.iter() {
426425
visit::walk_ty_param_bounds(&mut collector, &ty_param.bounds, ());
427426
}
428427
return collector.names;
429428

430429
struct FreeLifetimeCollector {
431-
names: OptVec<ast::Name>,
430+
names: Vec<ast::Name>,
432431
}
433432

434433
impl Visitor<()> for FreeLifetimeCollector {

src/librustc/middle/subst.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use util::ppaux::Repr;
1717

1818
use std::rc::Rc;
1919
use syntax::codemap::Span;
20-
use syntax::opt_vec::OptVec;
20+
use syntax::owned_slice::OwnedSlice;
2121

2222
///////////////////////////////////////////////////////////////////////////
2323
// Public trait `Subst`
@@ -145,10 +145,10 @@ impl<T:Subst> Subst for Rc<T> {
145145
}
146146
}
147147

148-
impl<T:Subst> Subst for OptVec<T> {
148+
impl<T:Subst> Subst for OwnedSlice<T> {
149149
fn subst_spanned(&self, tcx: &ty::ctxt,
150150
substs: &ty::substs,
151-
span: Option<Span>) -> OptVec<T> {
151+
span: Option<Span>) -> OwnedSlice<T> {
152152
self.map(|t| t.subst_spanned(tcx, substs, span))
153153
}
154154
}

src/librustc/middle/trans/cleanup.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use middle::trans::glue;
2424
use middle::trans::type_::Type;
2525
use middle::ty;
2626
use syntax::ast;
27-
use syntax::opt_vec;
28-
use syntax::opt_vec::OptVec;
2927
use util::ppaux::Repr;
3028

3129
pub struct CleanupScope<'a> {
@@ -37,9 +35,9 @@ pub struct CleanupScope<'a> {
3735
kind: CleanupScopeKind<'a>,
3836

3937
// Cleanups to run upon scope exit.
40-
cleanups: OptVec<~Cleanup>,
38+
cleanups: Vec<~Cleanup>,
4139

42-
cached_early_exits: OptVec<CachedEarlyExit>,
40+
cached_early_exits: Vec<CachedEarlyExit>,
4341
cached_landing_pad: Option<BasicBlockRef>,
4442
}
4543

@@ -379,7 +377,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
379377
assert!(orig_scopes_len > 0);
380378

381379
// Remove any scopes that do not have cleanups on failure:
382-
let mut popped_scopes = opt_vec::Empty;
380+
let mut popped_scopes = vec!();
383381
while !self.top_scope(|s| s.needs_invoke()) {
384382
debug!("top scope does not need invoke");
385383
popped_scopes.push(self.pop_scope());
@@ -510,7 +508,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
510508

511509
let orig_scopes_len = self.scopes_len();
512510
let mut prev_llbb;
513-
let mut popped_scopes = opt_vec::Empty;
511+
let mut popped_scopes = vec!();
514512

515513
// First we pop off all the cleanup stacks that are
516514
// traversed until the exit is reached, pushing them
@@ -708,14 +706,14 @@ impl<'a> CleanupScope<'a> {
708706
fn new(kind: CleanupScopeKind<'a>) -> CleanupScope<'a> {
709707
CleanupScope {
710708
kind: kind,
711-
cleanups: opt_vec::Empty,
712-
cached_early_exits: opt_vec::Empty,
709+
cleanups: vec!(),
710+
cached_early_exits: vec!(),
713711
cached_landing_pad: None,
714712
}
715713
}
716714

717715
fn clear_cached_exits(&mut self) {
718-
self.cached_early_exits = opt_vec::Empty;
716+
self.cached_early_exits = vec!();
719717
self.cached_landing_pad = None;
720718
}
721719

src/librustc/middle/trans/debuginfo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ use std::ptr;
150150
use std::sync::atomics;
151151
use std::slice;
152152
use syntax::codemap::{Span, Pos};
153-
use syntax::{abi, ast, codemap, ast_util, ast_map, opt_vec};
153+
use syntax::{abi, ast, codemap, ast_util, ast_map};
154+
use syntax::owned_slice::OwnedSlice;
154155
use syntax::parse::token;
155156
use syntax::parse::token::special_idents;
156157

@@ -539,7 +540,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
539540
return FunctionWithoutDebugInfo;
540541
}
541542

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

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

src/librustc/middle/trans/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use util::ppaux::Repr;
2020
use middle::trans::type_::Type;
2121

2222
use syntax::ast;
23-
use syntax::opt_vec;
23+
use syntax::owned_slice::OwnedSlice;
2424

2525
pub fn arg_is_indirect(ccx: &CrateContext, arg_ty: ty::t) -> bool {
2626
!type_is_immediate(ccx, arg_ty)
@@ -324,7 +324,7 @@ pub fn llvm_type_name(cx: &CrateContext,
324324
an_enum => { "enum" }
325325
};
326326
let tstr = ppaux::parameterized(cx.tcx(), ty::item_path_str(cx.tcx(), did),
327-
&ty::NonerasedRegions(opt_vec::Empty),
327+
&ty::NonerasedRegions(OwnedSlice::empty()),
328328
tps, did, false);
329329
if did.krate == 0 {
330330
format!("{}.{}", name, tstr)

0 commit comments

Comments
 (0)