Skip to content

Commit

Permalink
De-manage OptVec<TyParamBounds>
Browse files Browse the repository at this point in the history
  • Loading branch information
James Miller committed Jul 7, 2013
1 parent 97c5a44 commit 46a1f54
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Expand Up @@ -1014,7 +1014,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs);
match ty.node {
ast::ty_path(ref path, bounds, _) if path.idents.len() == 1 => {
ast::ty_path(ref path, ref bounds, _) if path.idents.len() == 1 => {
assert!(bounds.is_none());
encode_impl_type_basename(ecx, ebml_w,
ast_util::path_to_ident(path));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Expand Up @@ -125,7 +125,7 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
if cx.tcx.lang_items.drop_trait() == trait_def_id {
// Yes, it's a destructor.
match self_type.node {
ty_path(_, bounds, path_node_id) => {
ty_path(_, ref bounds, path_node_id) => {
assert!(bounds.is_none());
let struct_def = cx.tcx.def_map.get_copy(
&path_node_id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/region.rs
Expand Up @@ -784,7 +784,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
// then check whether it is region-parameterized and consider
// that as a direct dependency.
match ty.node {
ast::ty_path(ref path, _bounds, id) => {
ast::ty_path(ref path, _, id) => {
match cx.def_map.find(&id) {
Some(&ast::def_ty(did)) |
Some(&ast::def_trait(did)) |
Expand Down Expand Up @@ -820,7 +820,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
visit_mt(mt, (cx, visitor));
}

ast::ty_path(ref path, _bounds, _) => {
ast::ty_path(ref path, _, _) => {
// type parameters are---for now, anyway---always invariant
do cx.with_ambient_variance(rv_invariant) {
for path.types.iter().advance |tp| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Expand Up @@ -4117,7 +4117,7 @@ impl Resolver {
// Like path expressions, the interpretation of path types depends
// on whether the path has multiple elements in it or not.

ty_path(ref path, bounds, path_id) => {
ty_path(ref path, ref bounds, path_id) => {
// This is a path in the type namespace. Walk through scopes
// scopes looking for it.
let mut result_def = None;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/astconv.rs
Expand Up @@ -276,7 +276,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
}
return ty::mk_evec(tcx, mt, vst);
}
ast::ty_path(ref path, bounds, id) => {
ast::ty_path(ref path, ref bounds, id) => {
// Note that the "bounds must be empty if path is not a trait"
// restriction is enforced in the below case for ty_path, which
// will run after this as long as the path isn't a trait.
Expand Down Expand Up @@ -405,7 +405,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
ast_ty.span);
ty::mk_closure(tcx, fn_decl)
}
ast::ty_path(ref path, bounds, id) => {
ast::ty_path(ref path, ref bounds, id) => {
let a_def = match tcx.def_map.find(&id) {
None => tcx.sess.span_fatal(
ast_ty.span, fmt!("unbound path %s",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/collect.rs
Expand Up @@ -1149,7 +1149,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
let param_ty = ty::param_ty {idx: base_index + offset,
def_id: local_def(param.id)};
let bounds = @compute_bounds(ccx, rp, generics,
param_ty, param.bounds);
param_ty, &param.bounds);
let def = ty::TypeParameterDef {
def_id: local_def(param.id),
bounds: bounds
Expand All @@ -1167,7 +1167,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
rp: Option<ty::region_variance>,
generics: &ast::Generics,
param_ty: ty::param_ty,
ast_bounds: @OptVec<ast::TyParamBound>) -> ty::ParamBounds
ast_bounds: &OptVec<ast::TyParamBound>) -> ty::ParamBounds
{
/*!
*
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Expand Up @@ -140,7 +140,7 @@ pub enum TyParamBound {
pub struct TyParam {
ident: ident,
id: node_id,
bounds: @OptVec<TyParamBound>
bounds: OptVec<TyParamBound>
}

#[deriving(Eq, Encodable, Decodable,IterBytes)]
Expand Down Expand Up @@ -734,7 +734,7 @@ pub enum ty_ {
ty_closure(@TyClosure),
ty_bare_fn(@TyBareFn),
ty_tup(~[@Ty]),
ty_path(Path, @Option<OptVec<TyParamBound>>, node_id), // for #7264; see above
ty_path(Path, Option<OptVec<TyParamBound>>, node_id), // for #7264; see above
ty_mac(mac),
// ty_infer means the type should be inferred instead of it having been
// specified. This should only appear at the "top level" of a type and not
Expand Down
18 changes: 8 additions & 10 deletions src/libsyntax/ext/build.rs
Expand Up @@ -46,7 +46,7 @@ pub trait AstBuilder {
fn ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt;

fn ty(&self, span: span, ty: ast::ty_) -> @ast::Ty;
fn ty_path(&self, ast::Path, @Option<OptVec<ast::TyParamBound>>) -> @ast::Ty;
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> @ast::Ty;
fn ty_ident(&self, span: span, idents: ast::ident) -> @ast::Ty;

fn ty_rptr(&self, span: span,
Expand All @@ -66,7 +66,7 @@ pub trait AstBuilder {
fn ty_field_imm(&self, span: span, name: ident, ty: @ast::Ty) -> ast::ty_field;
fn strip_bounds(&self, bounds: &Generics) -> Generics;

fn typaram(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam;
fn typaram(&self, id: ast::ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam;

fn trait_ref(&self, path: ast::Path) -> ast::trait_ref;
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
Expand Down Expand Up @@ -265,7 +265,7 @@ impl AstBuilder for @ExtCtxt {
}
}

fn ty_path(&self, path: ast::Path, bounds: @Option<OptVec<ast::TyParamBound>>)
fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>)
-> @ast::Ty {
self.ty(path.span,
ast::ty_path(path, bounds, self.next_id()))
Expand All @@ -275,7 +275,7 @@ impl AstBuilder for @ExtCtxt {
// to generate a bounded existential trait type.
fn ty_ident(&self, span: span, ident: ast::ident)
-> @ast::Ty {
self.ty_path(self.path_ident(span, ident), @None)
self.ty_path(self.path_ident(span, ident), None)
}

fn ty_rptr(&self,
Expand Down Expand Up @@ -305,8 +305,7 @@ impl AstBuilder for @ExtCtxt {
self.ident_of("Option")
],
None,
~[ ty ]),
@None)
~[ ty ]), None)
}

fn ty_field_imm(&self, span: span, name: ident, ty: @ast::Ty) -> ast::ty_field {
Expand All @@ -329,7 +328,7 @@ impl AstBuilder for @ExtCtxt {
}
}

fn typaram(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam {
fn typaram(&self, id: ast::ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam {
ast::TyParam { ident: id, id: self.next_id(), bounds: bounds }
}

Expand All @@ -344,13 +343,12 @@ impl AstBuilder for @ExtCtxt {
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
opt_vec::take_vec(
ty_params.map(|p| self.ty_path(
self.path_global(dummy_sp(), ~[p.ident]), @None)))
self.path_global(dummy_sp(), ~[p.ident]), None)))
}

fn strip_bounds(&self, generics: &Generics) -> Generics {
let no_bounds = @opt_vec::Empty;
let new_params = do generics.ty_params.map |ty_param| {
ast::TyParam { bounds: no_bounds, ..copy *ty_param }
ast::TyParam { bounds: opt_vec::Empty, ..copy *ty_param }
};
Generics {
ty_params: new_params,
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/ext/deriving/generic.rs
Expand Up @@ -337,7 +337,7 @@ impl<'self> TraitDef<'self> {
// require the current trait
bounds.push(cx.typarambound(copy trait_path));

trait_generics.ty_params.push(cx.typaram(ty_param.ident, @bounds));
trait_generics.ty_params.push(cx.typaram(ty_param.ident, bounds));
}

// Create the reference to the trait.
Expand All @@ -356,8 +356,7 @@ impl<'self> TraitDef<'self> {

// Create the type of `self`.
let self_type = cx.ty_path(cx.path_all(span, false, ~[ type_ident ], self_lifetime,
opt_vec::take_vec(self_ty_params)),
@None);
opt_vec::take_vec(self_ty_params)), None);

let doc_attr = cx.attribute(
span,
Expand Down
8 changes: 3 additions & 5 deletions src/libsyntax/ext/deriving/ty.rs
Expand Up @@ -62,8 +62,7 @@ impl<'self> Path<'self> {
self_ty: ident,
self_generics: &Generics)
-> @ast::Ty {
cx.ty_path(self.to_path(cx, span,
self_ty, self_generics), @None)
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
}
pub fn to_path(&self,
cx: @ExtCtxt,
Expand Down Expand Up @@ -142,8 +141,7 @@ impl<'self> Ty<'self> {
}
Literal(ref p) => { p.to_ty(cx, span, self_ty, self_generics) }
Self => {
cx.ty_path(self.to_path(cx, span, self_ty, self_generics),
@None)
cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None)
}
Tuple(ref fields) => {
let ty = if fields.is_empty() {
Expand Down Expand Up @@ -194,7 +192,7 @@ fn mk_ty_param(cx: @ExtCtxt, span: span, name: &str, bounds: &[Path],
let path = b.to_path(cx, span, self_ident, self_generics);
cx.typarambound(path)
});
cx.typaram(cx.ident_of(name), @bounds)
cx.typaram(cx.ident_of(name), bounds)
}

fn mk_generics(lifetimes: ~[ast::Lifetime], ty_params: ~[ast::TyParam]) -> Generics {
Expand Down
27 changes: 13 additions & 14 deletions src/libsyntax/ext/pipes/pipec.rs
Expand Up @@ -60,7 +60,7 @@ impl gen_send for message {

let pipe_ty = cx.ty_path(
path(~[this.data_name()], span)
.add_tys(cx.ty_vars(&this.generics.ty_params)), @None);
.add_tys(cx.ty_vars(&this.generics.ty_params)), None);
let args_ast = vec::append(
~[cx.arg(span, cx.ident_of("pipe"), pipe_ty)],
args_ast);
Expand Down Expand Up @@ -117,7 +117,7 @@ impl gen_send for message {

let mut rty = cx.ty_path(path(~[next.data_name()],
span)
.add_tys(copy next_state.tys), @None);
.add_tys(copy next_state.tys), None);
if try {
rty = cx.ty_option(rty);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ impl gen_send for message {
cx.ty_path(
path(~[this.data_name()], span)
.add_tys(cx.ty_vars(
&this.generics.ty_params)), @None))],
&this.generics.ty_params)), None))],
args_ast);

let message_args = if arg_names.len() == 0 {
Expand Down Expand Up @@ -191,7 +191,7 @@ impl gen_send for message {

fn to_ty(&mut self, cx: @ExtCtxt) -> @ast::Ty {
cx.ty_path(path(~[cx.ident_of(self.name())], self.span())
.add_tys(cx.ty_vars(&self.get_generics().ty_params)), @None)
.add_tys(cx.ty_vars(&self.get_generics().ty_params)), None)
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ impl to_type_decls for state {
cx.ty_path(
path(~[cx.ident_of(dir),
cx.ident_of(next_name)], span)
.add_tys(copy next_state.tys), @None))
.add_tys(copy next_state.tys), None))
}
None => tys
};
Expand Down Expand Up @@ -278,8 +278,7 @@ impl to_type_decls for state {
self.data_name()],
dummy_sp())
.add_tys(cx.ty_vars(
&self.generics.ty_params)), @None)),
@None),
&self.generics.ty_params)), None)), None),
cx.strip_bounds(&self.generics)));
}
else {
Expand All @@ -298,8 +297,8 @@ impl to_type_decls for state {
self.data_name()],
dummy_sp())
.add_tys(cx.ty_vars_global(
&self.generics.ty_params)), @None),
self.proto.buffer_ty_path(cx)]), @None),
&self.generics.ty_params)), None),
self.proto.buffer_ty_path(cx)]), None),
cx.strip_bounds(&self.generics)));
};
items
Expand Down Expand Up @@ -372,10 +371,10 @@ impl gen_init for protocol {

fn buffer_ty_path(&self, cx: @ExtCtxt) -> @ast::Ty {
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
for (copy self.states).iter().advance |s| {
for self.states.iter().advance |s| {
for s.generics.ty_params.iter().advance |tp| {
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp),
None => params.push(copy *tp),
_ => ()
}
}
Expand All @@ -384,16 +383,16 @@ impl gen_init for protocol {
cx.ty_path(path(~[cx.ident_of("super"),
cx.ident_of("__Buffer")],
copy self.span)
.add_tys(cx.ty_vars_global(&params)), @None)
.add_tys(cx.ty_vars_global(&params)), None)
}

fn gen_buffer_type(&self, cx: @ExtCtxt) -> @ast::item {
let ext_cx = cx;
let mut params: OptVec<ast::TyParam> = opt_vec::Empty;
let fields = do (copy self.states).iter().transform |s| {
let fields = do self.states.iter().transform |s| {
for s.generics.ty_params.iter().advance |tp| {
match params.iter().find_(|tpp| tp.ident == tpp.ident) {
None => params.push(*tp),
None => params.push(copy *tp),
_ => ()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/pipes/proto.rs
Expand Up @@ -99,7 +99,7 @@ impl state_ {
pub fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty {
cx.ty_path
(path(~[cx.ident_of(self.name)],self.span).add_tys(
cx.ty_vars(&self.generics.ty_params)), @None)
cx.ty_vars(&self.generics.ty_params)), None)
}

/// Iterate over the states that can be reached in one message
Expand Down
9 changes: 5 additions & 4 deletions src/libsyntax/fold.rs
Expand Up @@ -171,12 +171,13 @@ pub fn fold_ty_param(tp: TyParam,
fld: @ast_fold) -> TyParam {
TyParam {ident: tp.ident,
id: fld.new_id(tp.id),
bounds: @tp.bounds.map(|x| fold_ty_param_bound(x, fld))}
bounds: tp.bounds.map(|x| fold_ty_param_bound(x, fld))}
}

pub fn fold_ty_params(tps: &OptVec<TyParam>,
fld: @ast_fold) -> OptVec<TyParam> {
tps.map(|tp| fold_ty_param(*tp, fld))
let tps = /*bad*/ copy *tps;
tps.map_consume(|tp| fold_ty_param(tp, fld))
}

pub fn fold_lifetime(l: &Lifetime,
Expand Down Expand Up @@ -682,8 +683,8 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ {
})
}
ty_tup(ref tys) => ty_tup(tys.map(|ty| fld.fold_ty(*ty))),
ty_path(ref path, bounds, id) =>
ty_path(fld.fold_path(path), @fold_opt_bounds(bounds, fld), fld.new_id(id)),
ty_path(ref path, ref bounds, id) =>
ty_path(fld.fold_path(path), fold_opt_bounds(bounds, fld), fld.new_id(id)),
ty_fixed_length_vec(ref mt, e) => {
ty_fixed_length_vec(
fold_mt(mt, fld),
Expand Down
9 changes: 8 additions & 1 deletion src/libsyntax/opt_vec.rs
Expand Up @@ -16,7 +16,7 @@
* other useful things like `push()` and `len()`.
*/

use std::vec::VecIterator;
use std::vec::{VecIterator};

#[deriving(Encodable, Decodable,IterBytes)]
pub enum OptVec<T> {
Expand Down Expand Up @@ -58,6 +58,13 @@ impl<T> OptVec<T> {
}
}

fn map_consume<U>(self, op: &fn(T) -> U) -> OptVec<U> {
match self {
Empty => Empty,
Vec(v) => Vec(v.consume_iter().transform(op).collect())
}
}

fn get<'a>(&'a self, i: uint) -> &'a T {
match *self {
Empty => fail!("Invalid index %u", i),
Expand Down

0 comments on commit 46a1f54

Please sign in to comment.