Skip to content

Commit 2730981

Browse files
committed
Improve OwnedSlice and use it in HIR
1 parent 3391630 commit 2730981

File tree

23 files changed

+222
-154
lines changed

23 files changed

+222
-154
lines changed

src/librustc/middle/infer/error_reporting.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ use syntax::ast;
9393
use syntax::codemap::{self, Pos, Span};
9494
use syntax::parse::token;
9595
use syntax::ptr::P;
96+
use syntax::util::MoveMap;
9697

9798
impl<'tcx> ty::ctxt<'tcx> {
9899
pub fn note_and_explain_region(&self,
@@ -1153,19 +1154,19 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11531154
}
11541155

11551156
fn rebuild_ty_params(&self,
1156-
ty_params: P<[hir::TyParam]>,
1157+
ty_params: hir::HirVec<hir::TyParam>,
11571158
lifetime: hir::Lifetime,
11581159
region_names: &HashSet<ast::Name>)
1159-
-> P<[hir::TyParam]> {
1160-
ty_params.map(|ty_param| {
1161-
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
1160+
-> hir::HirVec<hir::TyParam> {
1161+
ty_params.move_map(|ty_param| {
1162+
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds,
11621163
lifetime,
11631164
region_names);
11641165
hir::TyParam {
11651166
name: ty_param.name,
11661167
id: ty_param.id,
11671168
bounds: bounds,
1168-
default: ty_param.default.clone(),
1169+
default: ty_param.default,
11691170
span: ty_param.span,
11701171
}
11711172
})
@@ -1176,15 +1177,15 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11761177
lifetime: hir::Lifetime,
11771178
region_names: &HashSet<ast::Name>)
11781179
-> hir::TyParamBounds {
1179-
ty_param_bounds.map(|tpb| {
1180+
ty_param_bounds.move_map(|tpb| {
11801181
match tpb {
1181-
&hir::RegionTyParamBound(lt) => {
1182+
hir::RegionTyParamBound(lt) => {
11821183
// FIXME -- it's unclear whether I'm supposed to
11831184
// substitute lifetime here. I suspect we need to
11841185
// be passing down a map.
11851186
hir::RegionTyParamBound(lt)
11861187
}
1187-
&hir::TraitTyParamBound(ref poly_tr, modifier) => {
1188+
hir::TraitTyParamBound(ref poly_tr, modifier) => {
11881189
let tr = &poly_tr.trait_ref;
11891190
let last_seg = tr.path.segments.last().unwrap();
11901191
let mut insert = Vec::new();
@@ -1248,7 +1249,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12481249
add: &Vec<hir::Lifetime>,
12491250
keep: &HashSet<ast::Name>,
12501251
remove: &HashSet<ast::Name>,
1251-
ty_params: P<[hir::TyParam]>,
1252+
ty_params: hir::HirVec<hir::TyParam>,
12521253
where_clause: hir::WhereClause)
12531254
-> hir::Generics {
12541255
let mut lifetimes = Vec::new();
@@ -1498,10 +1499,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
14981499
}
14991500
}
15001501
}
1501-
let new_types = data.types.map(|t| {
1502+
let new_types = data.types.iter().map(|t| {
15021503
self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
1503-
});
1504-
let new_bindings = data.bindings.map(|b| {
1504+
}).collect();
1505+
let new_bindings = data.bindings.iter().map(|b| {
15051506
hir::TypeBinding {
15061507
id: b.id,
15071508
name: b.name,
@@ -1511,7 +1512,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
15111512
region_names),
15121513
span: b.span
15131514
}
1514-
});
1515+
}).collect();
15151516
hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
15161517
lifetimes: new_lts.into(),
15171518
types: new_types,

src/librustc_front/fold.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir;
1919
use syntax::codemap::{respan, Span, Spanned};
2020
use syntax::ptr::P;
2121
use syntax::parse::token;
22-
use syntax::util::move_map::MoveMap;
22+
use syntax::util::{MoveMap, MoveFlatMap};
2323

2424
pub trait Folder : Sized {
2525
// Any additions to this trait should happen in form
@@ -210,7 +210,7 @@ pub trait Folder : Sized {
210210
noop_fold_ty_param(tp, self)
211211
}
212212

213-
fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> {
213+
fn fold_ty_params(&mut self, tps: HirVec<TyParam>) -> HirVec<TyParam> {
214214
noop_fold_ty_params(tps, self)
215215
}
216216

@@ -575,9 +575,9 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
575575
}
576576
}
577577

578-
pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>,
578+
pub fn noop_fold_ty_params<T: Folder>(tps: HirVec<TyParam>,
579579
fld: &mut T)
580-
-> P<[TyParam]> {
580+
-> HirVec<TyParam> {
581581
tps.move_map(|tp| fld.fold_ty_param(tp))
582582
}
583583

src/librustc_front/hir.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ impl PathParameters {
208208
pub fn none() -> PathParameters {
209209
AngleBracketedParameters(AngleBracketedParameterData {
210210
lifetimes: HirVec::new(),
211-
types: P::empty(),
212-
bindings: P::empty(),
211+
types: HirVec::new(),
212+
bindings: HirVec::new(),
213213
})
214214
}
215215

@@ -282,10 +282,10 @@ pub struct AngleBracketedParameterData {
282282
/// The lifetime parameters for this path segment.
283283
pub lifetimes: HirVec<Lifetime>,
284284
/// The type parameters for this path segment, if present.
285-
pub types: P<[P<Ty>]>,
285+
pub types: HirVec<P<Ty>>,
286286
/// Bindings (equality constraints) on associated types, if present.
287287
/// E.g., `Foo<A=Bar>`.
288-
pub bindings: P<[TypeBinding]>,
288+
pub bindings: HirVec<TypeBinding>,
289289
}
290290

291291
impl AngleBracketedParameterData {
@@ -325,7 +325,7 @@ pub enum TraitBoundModifier {
325325
Maybe,
326326
}
327327

328-
pub type TyParamBounds = P<[TyParamBound]>;
328+
pub type TyParamBounds = HirVec<TyParamBound>;
329329

330330
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
331331
pub struct TyParam {
@@ -341,7 +341,7 @@ pub struct TyParam {
341341
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
342342
pub struct Generics {
343343
pub lifetimes: HirVec<LifetimeDef>,
344-
pub ty_params: P<[TyParam]>,
344+
pub ty_params: HirVec<TyParam>,
345345
pub where_clause: WhereClause,
346346
}
347347

src/librustc_front/lowering.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ pub fn lower_ty_param(lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam {
433433
}
434434

435435
pub fn lower_ty_params(lctx: &LoweringContext,
436-
tps: &P<[TyParam]>)
437-
-> P<[hir::TyParam]> {
436+
tps: &[TyParam])
437+
-> hir::HirVec<hir::TyParam> {
438438
tps.iter().map(|tp| lower_ty_param(lctx, tp)).collect()
439439
}
440440

@@ -1771,19 +1771,19 @@ fn path_ident(span: Span, id: hir::Ident) -> hir::Path {
17711771
}
17721772

17731773
fn path(span: Span, strs: Vec<hir::Ident>) -> hir::Path {
1774-
path_all(span, false, strs, hir::HirVec::new(), Vec::new(), Vec::new())
1774+
path_all(span, false, strs, hir::HirVec::new(), hir::HirVec::new(), hir::HirVec::new())
17751775
}
17761776

17771777
fn path_global(span: Span, strs: Vec<hir::Ident>) -> hir::Path {
1778-
path_all(span, true, strs, hir::HirVec::new(), Vec::new(), Vec::new())
1778+
path_all(span, true, strs, hir::HirVec::new(), hir::HirVec::new(), hir::HirVec::new())
17791779
}
17801780

17811781
fn path_all(sp: Span,
17821782
global: bool,
17831783
mut idents: Vec<hir::Ident>,
17841784
lifetimes: hir::HirVec<hir::Lifetime>,
1785-
types: Vec<P<hir::Ty>>,
1786-
bindings: Vec<hir::TypeBinding>)
1785+
types: hir::HirVec<P<hir::Ty>>,
1786+
bindings: hir::HirVec<hir::TypeBinding>)
17871787
-> hir::Path {
17881788
let last_identifier = idents.pop().unwrap();
17891789
let mut segments: Vec<hir::PathSegment> = idents.into_iter()
@@ -1798,8 +1798,8 @@ fn path_all(sp: Span,
17981798
identifier: last_identifier,
17991799
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
18001800
lifetimes: lifetimes,
1801-
types: P::from_vec(types),
1802-
bindings: P::from_vec(bindings),
1801+
types: types.into(),
1802+
bindings: bindings.into(),
18031803
}),
18041804
});
18051805
hir::Path {

src/librustc_front/print/pprust.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<'a> State<'a> {
518518
hir::TyBareFn(ref f) => {
519519
let generics = hir::Generics {
520520
lifetimes: f.lifetimes.clone(),
521-
ty_params: P::empty(),
521+
ty_params: hir::HirVec::new(),
522522
where_clause: hir::WhereClause {
523523
id: ast::DUMMY_NODE_ID,
524524
predicates: hir::HirVec::new(),
@@ -2257,7 +2257,7 @@ impl<'a> State<'a> {
22572257
}
22582258
let generics = hir::Generics {
22592259
lifetimes: hir::HirVec::new(),
2260-
ty_params: P::empty(),
2260+
ty_params: hir::HirVec::new(),
22612261
where_clause: hir::WhereClause {
22622262
id: ast::DUMMY_NODE_ID,
22632263
predicates: hir::HirVec::new(),

src/librustc_front/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ pub fn is_path(e: P<Expr>) -> bool {
335335
pub fn empty_generics() -> Generics {
336336
Generics {
337337
lifetimes: HirVec::new(),
338-
ty_params: P::empty(),
338+
ty_params: HirVec::new(),
339339
where_clause: WhereClause {
340340
id: DUMMY_NODE_ID,
341341
predicates: HirVec::new(),
@@ -353,8 +353,8 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path {
353353
identifier: ident,
354354
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
355355
lifetimes: HirVec::new(),
356-
types: P::empty(),
357-
bindings: P::empty(),
356+
types: HirVec::new(),
357+
bindings: HirVec::new(),
358358
}),
359359
}],
360360
}

src/librustc_mir/hair/cx/to_ref.rs

+10
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,13 @@ impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec<T>
6161
self.iter().map(|expr| expr.to_ref()).collect()
6262
}
6363
}
64+
65+
impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]>
66+
where &'tcx T: ToRef<Output=U>
67+
{
68+
type Output = Vec<U>;
69+
70+
fn to_ref(self) -> Vec<U> {
71+
self.iter().map(|expr| expr.to_ref()).collect()
72+
}
73+
}

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4906,7 +4906,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &hir::Block) -> bool {
49064906
}
49074907

49084908
pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
4909-
tps: &P<[hir::TyParam]>,
4909+
tps: &[hir::TyParam],
49104910
ty: Ty<'tcx>) {
49114911
debug!("check_bounds_are_used(n_tps={}, ty={:?})",
49124912
tps.len(), ty);

src/libsyntax/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ impl PathParameters {
260260
pub fn none() -> PathParameters {
261261
AngleBracketedParameters(AngleBracketedParameterData {
262262
lifetimes: Vec::new(),
263-
types: P::empty(),
264-
bindings: P::empty(),
263+
types: P::new(),
264+
bindings: P::new(),
265265
})
266266
}
267267

@@ -429,7 +429,7 @@ impl Default for Generics {
429429
fn default() -> Generics {
430430
Generics {
431431
lifetimes: Vec::new(),
432-
ty_params: P::empty(),
432+
ty_params: P::new(),
433433
where_clause: WhereClause {
434434
id: DUMMY_NODE_ID,
435435
predicates: Vec::new(),

src/libsyntax/ast_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
4242
identifier: identifier,
4343
parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
4444
lifetimes: Vec::new(),
45-
types: P::empty(),
46-
bindings: P::empty(),
45+
types: P::new(),
46+
bindings: P::new(),
4747
})
4848
}
4949
),

src/libsyntax/ext/build.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ pub trait AstBuilder {
6969
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
7070
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
7171

72-
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
73-
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
72+
fn ty_vars(&self, ty_params: &[ast::TyParam]) -> Vec<P<ast::Ty>> ;
73+
fn ty_vars_global(&self, ty_params: &[ast::TyParam]) -> Vec<P<ast::Ty>> ;
7474

7575
fn typaram(&self,
7676
span: Span,
@@ -330,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
330330
identifier: last_identifier,
331331
parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
332332
lifetimes: lifetimes,
333-
types: P::from_vec(types),
334-
bindings: P::from_vec(bindings),
333+
types: P::from(types),
334+
bindings: P::from(bindings),
335335
})
336336
});
337337
ast::Path {
@@ -368,8 +368,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
368368
identifier: ident,
369369
parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
370370
lifetimes: lifetimes,
371-
types: P::from_vec(types),
372-
bindings: P::from_vec(bindings),
371+
types: P::from(types),
372+
bindings: P::from(bindings),
373373
})
374374
});
375375

@@ -461,11 +461,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
461461
// these are strange, and probably shouldn't be used outside of
462462
// pipes. Specifically, the global version possible generates
463463
// incorrect code.
464-
fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
464+
fn ty_vars(&self, ty_params: &[ast::TyParam]) -> Vec<P<ast::Ty>> {
465465
ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect()
466466
}
467467

468-
fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
468+
fn ty_vars_global(&self, ty_params: &[ast::TyParam]) -> Vec<P<ast::Ty>> {
469469
ty_params
470470
.iter()
471471
.map(|p| self.ty_path(self.path_global(DUMMY_SP, vec!(p.ident))))

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ use ext::base::*;
2424
use feature_gate::{self, Features};
2525
use fold;
2626
use fold::*;
27-
use util::move_map::MoveMap;
2827
use parse;
2928
use parse::token::{fresh_mark, fresh_name, intern};
3029
use ptr::P;
3130
use util::small_vector::SmallVector;
3231
use visit;
3332
use visit::Visitor;
3433
use std_inject;
34+
use util::MoveMap;
3535

3636
use std::collections::HashSet;
3737

src/libsyntax/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use ast_util;
2525
use codemap::{respan, Span, Spanned};
2626
use parse::token;
2727
use ptr::P;
28+
use util::{MoveMap, MoveFlatMap};
2829
use util::small_vector::SmallVector;
29-
use util::move_map::MoveMap;
3030

3131
use std::rc::Rc;
3232

src/libsyntax/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ macro_rules! panictry {
6161
}
6262

6363
pub mod util {
64+
pub use self::move_map::{MoveMap, MoveFlatMap};
65+
6466
pub mod interner;
6567
pub mod lev_distance;
68+
pub mod move_map;
6669
pub mod node_count;
6770
pub mod parser;
6871
#[cfg(test)]
6972
pub mod parser_testing;
7073
pub mod small_vector;
71-
pub mod move_map;
7274
}
7375

7476
pub mod diagnostics {

src/libsyntax/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ mod tests {
946946
abi::Rust,
947947
ast::Generics{ // no idea on either of these:
948948
lifetimes: Vec::new(),
949-
ty_params: P::empty(),
949+
ty_params: P::new(),
950950
where_clause: ast::WhereClause {
951951
id: ast::DUMMY_NODE_ID,
952952
predicates: Vec::new(),

0 commit comments

Comments
 (0)