Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve OwnedSlice and use it in HIR #30095

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ use syntax::ast;
use syntax::codemap::{self, Pos, Span};
use syntax::parse::token;
use syntax::ptr::P;
use syntax::util::MoveMap;

impl<'tcx> ty::ctxt<'tcx> {
pub fn note_and_explain_region(&self,
Expand Down Expand Up @@ -1153,19 +1154,19 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}

fn rebuild_ty_params(&self,
ty_params: P<[hir::TyParam]>,
ty_params: hir::HirVec<hir::TyParam>,
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> P<[hir::TyParam]> {
ty_params.map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
-> hir::HirVec<hir::TyParam> {
ty_params.move_map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds,
lifetime,
region_names);
hir::TyParam {
name: ty_param.name,
id: ty_param.id,
bounds: bounds,
default: ty_param.default.clone(),
default: ty_param.default,
span: ty_param.span,
}
})
Expand All @@ -1176,15 +1177,15 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> hir::TyParamBounds {
ty_param_bounds.map(|tpb| {
ty_param_bounds.move_map(|tpb| {
match tpb {
&hir::RegionTyParamBound(lt) => {
hir::RegionTyParamBound(lt) => {
// FIXME -- it's unclear whether I'm supposed to
// substitute lifetime here. I suspect we need to
// be passing down a map.
hir::RegionTyParamBound(lt)
}
&hir::TraitTyParamBound(ref poly_tr, modifier) => {
hir::TraitTyParamBound(ref poly_tr, modifier) => {
let tr = &poly_tr.trait_ref;
let last_seg = tr.path.segments.last().unwrap();
let mut insert = Vec::new();
Expand Down Expand Up @@ -1248,7 +1249,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
add: &Vec<hir::Lifetime>,
keep: &HashSet<ast::Name>,
remove: &HashSet<ast::Name>,
ty_params: P<[hir::TyParam]>,
ty_params: hir::HirVec<hir::TyParam>,
where_clause: hir::WhereClause)
-> hir::Generics {
let mut lifetimes = Vec::new();
Expand Down Expand Up @@ -1498,10 +1499,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
}
}
}
let new_types = data.types.map(|t| {
let new_types = data.types.iter().map(|t| {
self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names)
});
let new_bindings = data.bindings.map(|b| {
}).collect();
let new_bindings = data.bindings.iter().map(|b| {
hir::TypeBinding {
id: b.id,
name: b.name,
Expand All @@ -1511,7 +1512,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
region_names),
span: b.span
}
});
}).collect();
hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: new_lts.into(),
types: new_types,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use hir;
use syntax::codemap::{respan, Span, Spanned};
use syntax::ptr::P;
use syntax::parse::token;
use syntax::util::move_map::MoveMap;
use syntax::util::{MoveMap, MoveFlatMap};

pub trait Folder : Sized {
// Any additions to this trait should happen in form
Expand Down Expand Up @@ -210,7 +210,7 @@ pub trait Folder : Sized {
noop_fold_ty_param(tp, self)
}

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

Expand Down Expand Up @@ -575,9 +575,9 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
}
}

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

Expand Down
12 changes: 6 additions & 6 deletions src/librustc_front/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl PathParameters {
pub fn none() -> PathParameters {
AngleBracketedParameters(AngleBracketedParameterData {
lifetimes: HirVec::new(),
types: P::empty(),
bindings: P::empty(),
types: HirVec::new(),
bindings: HirVec::new(),
})
}

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

impl AngleBracketedParameterData {
Expand Down Expand Up @@ -325,7 +325,7 @@ pub enum TraitBoundModifier {
Maybe,
}

pub type TyParamBounds = P<[TyParamBound]>;
pub type TyParamBounds = HirVec<TyParamBound>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TyParam {
Expand All @@ -341,7 +341,7 @@ pub struct TyParam {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Generics {
pub lifetimes: HirVec<LifetimeDef>,
pub ty_params: P<[TyParam]>,
pub ty_params: HirVec<TyParam>,
pub where_clause: WhereClause,
}

Expand Down
16 changes: 8 additions & 8 deletions src/librustc_front/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ pub fn lower_ty_param(lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam {
}

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

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

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

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

fn path_all(sp: Span,
global: bool,
mut idents: Vec<hir::Ident>,
lifetimes: hir::HirVec<hir::Lifetime>,
types: Vec<P<hir::Ty>>,
bindings: Vec<hir::TypeBinding>)
types: hir::HirVec<P<hir::Ty>>,
bindings: hir::HirVec<hir::TypeBinding>)
-> hir::Path {
let last_identifier = idents.pop().unwrap();
let mut segments: Vec<hir::PathSegment> = idents.into_iter()
Expand All @@ -1798,8 +1798,8 @@ fn path_all(sp: Span,
identifier: last_identifier,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: lifetimes,
types: P::from_vec(types),
bindings: P::from_vec(bindings),
types: types.into(),
bindings: bindings.into(),
}),
});
hir::Path {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_front/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<'a> State<'a> {
hir::TyBareFn(ref f) => {
let generics = hir::Generics {
lifetimes: f.lifetimes.clone(),
ty_params: P::empty(),
ty_params: hir::HirVec::new(),
where_clause: hir::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: hir::HirVec::new(),
Expand Down Expand Up @@ -2257,7 +2257,7 @@ impl<'a> State<'a> {
}
let generics = hir::Generics {
lifetimes: hir::HirVec::new(),
ty_params: P::empty(),
ty_params: hir::HirVec::new(),
where_clause: hir::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: hir::HirVec::new(),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_front/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn is_path(e: P<Expr>) -> bool {
pub fn empty_generics() -> Generics {
Generics {
lifetimes: HirVec::new(),
ty_params: P::empty(),
ty_params: HirVec::new(),
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: HirVec::new(),
Expand All @@ -353,8 +353,8 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path {
identifier: ident,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: HirVec::new(),
types: P::empty(),
bindings: P::empty(),
types: HirVec::new(),
bindings: HirVec::new(),
}),
}],
}
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_mir/hair/cx/to_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec<T>
self.iter().map(|expr| expr.to_ref()).collect()
}
}

impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]>
where &'tcx T: ToRef<Output=U>
{
type Output = Vec<U>;

fn to_ref(self) -> Vec<U> {
self.iter().map(|expr| expr.to_ref()).collect()
}
}
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4906,7 +4906,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &hir::Block) -> bool {
}

pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
tps: &P<[hir::TyParam]>,
tps: &[hir::TyParam],
ty: Ty<'tcx>) {
debug!("check_bounds_are_used(n_tps={}, ty={:?})",
tps.len(), ty);
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ impl PathParameters {
pub fn none() -> PathParameters {
AngleBracketedParameters(AngleBracketedParameterData {
lifetimes: Vec::new(),
types: P::empty(),
bindings: P::empty(),
types: P::new(),
bindings: P::new(),
})
}

Expand Down Expand Up @@ -429,7 +429,7 @@ impl Default for Generics {
fn default() -> Generics {
Generics {
lifetimes: Vec::new(),
ty_params: P::empty(),
ty_params: P::new(),
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
identifier: identifier,
parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
lifetimes: Vec::new(),
types: P::empty(),
bindings: P::empty(),
types: P::new(),
bindings: P::new(),
})
}
),
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pub trait AstBuilder {
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;

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

fn typaram(&self,
span: Span,
Expand Down Expand Up @@ -330,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
identifier: last_identifier,
parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
lifetimes: lifetimes,
types: P::from_vec(types),
bindings: P::from_vec(bindings),
types: P::from(types),
bindings: P::from(bindings),
})
});
ast::Path {
Expand Down Expand Up @@ -368,8 +368,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
identifier: ident,
parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
lifetimes: lifetimes,
types: P::from_vec(types),
bindings: P::from_vec(bindings),
types: P::from(types),
bindings: P::from(bindings),
})
});

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

fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
fn ty_vars_global(&self, ty_params: &[ast::TyParam]) -> Vec<P<ast::Ty>> {
ty_params
.iter()
.map(|p| self.ty_path(self.path_global(DUMMY_SP, vec!(p.ident))))
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ use ext::base::*;
use feature_gate::{self, Features};
use fold;
use fold::*;
use util::move_map::MoveMap;
use parse;
use parse::token::{fresh_mark, fresh_name, intern};
use ptr::P;
use util::small_vector::SmallVector;
use visit;
use visit::Visitor;
use std_inject;
use util::MoveMap;

use std::collections::HashSet;

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use ast_util;
use codemap::{respan, Span, Spanned};
use parse::token;
use ptr::P;
use util::{MoveMap, MoveFlatMap};
use util::small_vector::SmallVector;
use util::move_map::MoveMap;

use std::rc::Rc;

Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ macro_rules! panictry {
}

pub mod util {
pub use self::move_map::{MoveMap, MoveFlatMap};

pub mod interner;
pub mod lev_distance;
pub mod move_map;
pub mod node_count;
pub mod parser;
#[cfg(test)]
pub mod parser_testing;
pub mod small_vector;
pub mod move_map;
}

pub mod diagnostics {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ mod tests {
abi::Rust,
ast::Generics{ // no idea on either of these:
lifetimes: Vec::new(),
ty_params: P::empty(),
ty_params: P::new(),
where_clause: ast::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
Expand Down
Loading