Skip to content

Commit 7785fe1

Browse files
committed
syntax: make OptVec immutable.
This is the first step to replacing OptVec with a new representation: remove all mutability. Any mutations have to go via `Vec` and then make to `OptVec`. Many of the uses of OptVec are unnecessary now that Vec has no-alloc emptiness (and have been converted to Vec): the only ones that really need it are the AST and sty's (and so on) where there are a *lot* of instances of them, and they're (mostly) immutable.
1 parent 7334c11 commit 7785fe1

File tree

15 files changed

+79
-126
lines changed

15 files changed

+79
-126
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(opt_vec::from(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/resolve_lifetime.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use driver::session::Session;
2121
use util::nodemap::NodeMap;
2222
use syntax::ast;
2323
use syntax::codemap::Span;
24-
use syntax::opt_vec;
2524
use syntax::opt_vec::OptVec;
2625
use syntax::parse::token::special_idents;
2726
use syntax::parse::token;
@@ -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: &OptVec<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/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/ty.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,11 +5072,10 @@ pub fn construct_parameter_environment(
50725072

50735073
// map bound 'a => free 'a
50745074
let region_params = {
5075-
fn push_region_params(accum: OptVec<ty::Region>,
5075+
fn push_region_params(mut accum: Vec<ty::Region>,
50765076
free_id: ast::NodeId,
50775077
region_params: &[RegionParameterDef])
5078-
-> OptVec<ty::Region> {
5079-
let mut accum = accum;
5078+
-> Vec<ty::Region> {
50805079
for r in region_params.iter() {
50815080
accum.push(
50825081
ty::ReFree(ty::FreeRegion {
@@ -5086,14 +5085,14 @@ pub fn construct_parameter_environment(
50865085
accum
50875086
}
50885087

5089-
let t = push_region_params(opt_vec::Empty, free_id, item_region_params);
5088+
let t = push_region_params(vec!(), free_id, item_region_params);
50905089
push_region_params(t, free_id, method_region_params)
50915090
};
50925091

50935092
let free_substs = substs {
50945093
self_ty: self_ty,
50955094
tps: type_params,
5096-
regions: ty::NonerasedRegions(region_params)
5095+
regions: ty::NonerasedRegions(opt_vec::from(region_params))
50975096
};
50985097

50995098
//

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ use syntax::ast::{MutMutable, MutImmutable};
104104
use syntax::ast;
105105
use syntax::codemap::Span;
106106
use syntax::parse::token;
107+
use syntax::opt_vec;
107108

108109
#[deriving(Eq)]
109110
pub enum CheckTraitsFlag {
@@ -1102,8 +1103,8 @@ impl<'a> LookupContext<'a> {
11021103

11031104
// Determine values for the early-bound lifetime parameters.
11041105
// FIXME -- permit users to manually specify lifetimes
1105-
let mut all_regions = match candidate.rcvr_substs.regions {
1106-
NonerasedRegions(ref v) => v.clone(),
1106+
let mut all_regions: Vec<Region> = match candidate.rcvr_substs.regions {
1107+
NonerasedRegions(ref v) => v.iter().map(|r| r.clone()).collect(),
11071108
ErasedRegions => tcx.sess.span_bug(self.span, "ErasedRegions")
11081109
};
11091110
let m_regions =
@@ -1119,7 +1120,7 @@ impl<'a> LookupContext<'a> {
11191120
let all_substs = substs {
11201121
tps: vec::append(candidate.rcvr_substs.tps.clone(),
11211122
m_substs.as_slice()),
1122-
regions: NonerasedRegions(all_regions),
1123+
regions: NonerasedRegions(opt_vec::from(all_regions)),
11231124
self_ty: candidate.rcvr_substs.self_ty,
11241125
};
11251126

src/librustc/middle/typeck/infer/combine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub trait Combine {
160160

161161
assert_eq!(num_region_params, a_rs.len());
162162
assert_eq!(num_region_params, b_rs.len());
163-
let mut rs = opt_vec::Empty;
163+
let mut rs = vec!();
164164
for i in range(0, num_region_params) {
165165
let a_r = *a_rs.get(i);
166166
let b_r = *b_rs.get(i);
@@ -176,7 +176,7 @@ pub trait Combine {
176176
};
177177
rs.push(if_ok!(r));
178178
}
179-
Ok(ty::NonerasedRegions(rs))
179+
Ok(ty::NonerasedRegions(opt_vec::from(rs)))
180180
}
181181
}
182182
}

src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ use syntax::ast;
8080
use syntax::ast_map;
8181
use syntax::ast_util;
8282
use syntax::ast_util::name_to_dummy_lifetime;
83-
use syntax::opt_vec;
84-
use syntax::opt_vec::OptVec;
8583
use syntax::parse::token;
8684
use syntax::print::pprust;
8785
use util::ppaux::UserString;
@@ -90,10 +88,10 @@ use util::ppaux::note_and_explain_region;
9088

9189
pub trait ErrorReporting {
9290
fn report_region_errors(&self,
93-
errors: &OptVec<RegionResolutionError>);
91+
errors: &Vec<RegionResolutionError>);
9492

95-
fn process_errors(&self, errors: &OptVec<RegionResolutionError>)
96-
-> OptVec<RegionResolutionError>;
93+
fn process_errors(&self, errors: &Vec<RegionResolutionError>)
94+
-> Vec<RegionResolutionError>;
9795

9896
fn report_type_error(&self, trace: TypeTrace, terr: &ty::type_err);
9997

@@ -151,7 +149,7 @@ trait ErrorReportingHelpers {
151149

152150
impl<'a> ErrorReporting for InferCtxt<'a> {
153151
fn report_region_errors(&self,
154-
errors: &OptVec<RegionResolutionError>) {
152+
errors: &Vec<RegionResolutionError>) {
155153
let p_errors = self.process_errors(errors);
156154
let errors = if p_errors.is_empty() { errors } else { &p_errors };
157155
for error in errors.iter() {
@@ -195,12 +193,12 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
195193
// complete view of what lifetimes should be the same.
196194
// If the return value is an empty vector, it means that processing
197195
// failed (so the return value of this method should not be used)
198-
fn process_errors(&self, errors: &OptVec<RegionResolutionError>)
199-
-> OptVec<RegionResolutionError> {
196+
fn process_errors(&self, errors: &Vec<RegionResolutionError>)
197+
-> Vec<RegionResolutionError> {
200198
let mut var_origins = Vec::new();
201199
let mut trace_origins = Vec::new();
202200
let mut same_regions = Vec::new();
203-
let mut processed_errors = opt_vec::Empty;
201+
let mut processed_errors = Vec::new();
204202
for error in errors.iter() {
205203
match *error {
206204
ConcreteFailure(origin, sub, sup) => {
@@ -239,7 +237,7 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
239237
// declaration, we want to make sure that they are, in fact,
240238
// from the same scope
241239
if sr.scope_id != common_scope_id {
242-
return opt_vec::Empty;
240+
return vec!();
243241
}
244242
}
245243
let pe = ProcessedErrors(var_origins, trace_origins, same_regions);

src/librustc/middle/typeck/infer/region_inference/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ use std::uint;
2929
use std::slice;
3030
use collections::{HashMap, HashSet};
3131
use syntax::ast;
32-
use syntax::opt_vec;
33-
use syntax::opt_vec::OptVec;
3432

3533
mod doc;
3634

@@ -561,9 +559,9 @@ impl<'a> RegionVarBindings<'a> {
561559
constraints, assuming such values can be found; if they cannot,
562560
errors are reported.
563561
*/
564-
pub fn resolve_regions(&self) -> OptVec<RegionResolutionError> {
562+
pub fn resolve_regions(&self) -> Vec<RegionResolutionError> {
565563
debug!("RegionVarBindings: resolve_regions()");
566-
let mut errors = opt_vec::Empty;
564+
let mut errors = vec!();
567565
let v = self.infer_variable_values(&mut errors);
568566
let mut values = self.values.borrow_mut();
569567
*values.get() = Some(v);
@@ -815,7 +813,7 @@ type RegionGraph = graph::Graph<(), Constraint>;
815813

816814
impl<'a> RegionVarBindings<'a> {
817815
fn infer_variable_values(&self,
818-
errors: &mut OptVec<RegionResolutionError>)
816+
errors: &mut Vec<RegionResolutionError>)
819817
-> Vec<VarValue> {
820818
let mut var_data = self.construct_var_data();
821819
self.expansion(var_data.as_mut_slice());
@@ -1004,7 +1002,7 @@ impl<'a> RegionVarBindings<'a> {
10041002

10051003
fn collect_concrete_region_errors(
10061004
&self,
1007-
errors: &mut OptVec<RegionResolutionError>)
1005+
errors: &mut Vec<RegionResolutionError>)
10081006
{
10091007
let constraints = self.constraints.borrow();
10101008
for (constraint, _) in constraints.get().iter() {
@@ -1033,7 +1031,7 @@ impl<'a> RegionVarBindings<'a> {
10331031
fn extract_values_and_collect_conflicts(
10341032
&self,
10351033
var_data: &[VarData],
1036-
errors: &mut OptVec<RegionResolutionError>)
1034+
errors: &mut Vec<RegionResolutionError>)
10371035
-> Vec<VarValue> {
10381036
debug!("extract_values_and_collect_conflicts()");
10391037

@@ -1157,7 +1155,7 @@ impl<'a> RegionVarBindings<'a> {
11571155
var_data: &[VarData],
11581156
dup_vec: &mut [uint],
11591157
node_idx: RegionVid,
1160-
errors: &mut OptVec<RegionResolutionError>)
1158+
errors: &mut Vec<RegionResolutionError>)
11611159
{
11621160
// Errors in expanding nodes result from a lower-bound that is
11631161
// not contained by an upper-bound.
@@ -1206,7 +1204,7 @@ impl<'a> RegionVarBindings<'a> {
12061204
var_data: &[VarData],
12071205
dup_vec: &mut [uint],
12081206
node_idx: RegionVid,
1209-
errors: &mut OptVec<RegionResolutionError>)
1207+
errors: &mut Vec<RegionResolutionError>)
12101208
{
12111209
// Errors in contracting nodes result from two upper-bounds
12121210
// that have no intersection.

0 commit comments

Comments
 (0)