1
Fork 0

Box Block, fn_decl, variant and Ty in the AST, as they were inflating critical enum sizes.

This commit is contained in:
Eduard Burtescu 2013-12-01 00:00:39 +02:00
parent 80991bb578
commit a9c4b18b18
60 changed files with 623 additions and 640 deletions

View file

@ -9,7 +9,7 @@
// except according to those terms.
use abi::AbiSet;
use ast::Ident;
use ast::{P, Ident};
use ast;
use ast_util;
use codemap::{Span, respan, dummy_sp};
@ -39,30 +39,30 @@ pub trait AstBuilder {
global: bool,
idents: ~[ast::Ident],
lifetimes: OptVec<ast::Lifetime>,
types: ~[ast::Ty])
types: ~[P<ast::Ty>])
-> ast::Path;
// types
fn ty_mt(&self, ty: ast::Ty, mutbl: ast::Mutability) -> ast::mt;
fn ty_mt(&self, ty: P<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_ident(&self, span: Span, idents: ast::Ident) -> ast::Ty;
fn ty(&self, span: Span, ty: ast::ty_) -> P<ast::Ty>;
fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty>;
fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
fn ty_rptr(&self, span: Span,
ty: ast::Ty,
ty: P<ast::Ty>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::Mutability) -> ast::Ty;
fn ty_uniq(&self, span: Span, ty: ast::Ty) -> ast::Ty;
fn ty_box(&self, span: Span, ty: ast::Ty, mutbl: ast::Mutability) -> ast::Ty;
mutbl: ast::Mutability) -> P<ast::Ty>;
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty>;
fn ty_box(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty>;
fn ty_option(&self, ty: ast::Ty) -> ast::Ty;
fn ty_infer(&self, sp: Span) -> ast::Ty;
fn ty_nil(&self) -> ast::Ty;
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
fn ty_nil(&self) -> P<ast::Ty>;
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty];
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty];
fn ty_field_imm(&self, span: Span, name: Ident, ty: ast::Ty) -> ast::TypeField;
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>];
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>];
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField;
fn strip_bounds(&self, bounds: &Generics) -> Generics;
fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam;
@ -78,17 +78,17 @@ pub trait AstBuilder {
sp: Span,
mutbl: bool,
ident: ast::Ident,
typ: ast::Ty,
typ: P<ast::Ty>,
ex: @ast::Expr)
-> @ast::Stmt;
// blocks
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> ast::Block;
fn block_expr(&self, expr: @ast::Expr) -> ast::Block;
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@ast::Expr>) -> P<ast::Block>;
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block>;
fn block_all(&self, span: Span,
view_items: ~[ast::view_item],
stmts: ~[@ast::Stmt],
expr: Option<@ast::Expr>) -> ast::Block;
expr: Option<@ast::Expr>) -> P<ast::Block>;
// expressions
fn expr(&self, span: Span, node: ast::Expr_) -> @ast::Expr;
@ -112,8 +112,8 @@ pub trait AstBuilder {
fn expr_method_call(&self, span: Span,
expr: @ast::Expr, ident: ast::Ident,
args: ~[@ast::Expr]) -> @ast::Expr;
fn expr_block(&self, b: ast::Block) -> @ast::Expr;
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: ast::Ty) -> @ast::Expr;
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr;
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: P<ast::Ty>) -> @ast::Expr;
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field;
fn expr_struct(&self, span: Span, path: ast::Path, fields: ~[ast::Field]) -> @ast::Expr;
@ -159,11 +159,12 @@ pub trait AstBuilder {
fn expr_if(&self, span: Span,
cond: @ast::Expr, then: @ast::Expr, els: Option<@ast::Expr>) -> @ast::Expr;
fn lambda_fn_decl(&self, span: Span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::Expr;
fn lambda_fn_decl(&self, span: Span,
fn_decl: P<ast::fn_decl>, blk: P<ast::Block>) -> @ast::Expr;
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: ast::Block) -> @ast::Expr;
fn lambda0(&self, span: Span, blk: ast::Block) -> @ast::Expr;
fn lambda1(&self, span: Span, blk: ast::Block, ident: ast::Ident) -> @ast::Expr;
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr;
fn lambda0(&self, span: Span, blk: P<ast::Block>) -> @ast::Expr;
fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr;
fn lambda_expr(&self, span: Span, ids: ~[ast::Ident], blk: @ast::Expr) -> @ast::Expr;
fn lambda_expr_0(&self, span: Span, expr: @ast::Expr) -> @ast::Expr;
@ -177,25 +178,25 @@ pub trait AstBuilder {
fn item(&self, span: Span,
name: Ident, attrs: ~[ast::Attribute], node: ast::item_) -> @ast::item;
fn arg(&self, span: Span, name: Ident, ty: ast::Ty) -> ast::arg;
fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::arg;
// XXX unused self
fn fn_decl(&self, inputs: ~[ast::arg], output: ast::Ty) -> ast::fn_decl;
fn fn_decl(&self, inputs: ~[ast::arg], output: P<ast::Ty>) -> P<ast::fn_decl>;
fn item_fn_poly(&self,
span: Span,
name: Ident,
inputs: ~[ast::arg],
output: ast::Ty,
output: P<ast::Ty>,
generics: Generics,
body: ast::Block) -> @ast::item;
body: P<ast::Block>) -> @ast::item;
fn item_fn(&self,
span: Span,
name: Ident,
inputs: ~[ast::arg],
output: ast::Ty,
body: ast::Block) -> @ast::item;
output: P<ast::Ty>,
body: P<ast::Block>) -> @ast::item;
fn variant(&self, span: Span, name: Ident, tys: ~[ast::Ty]) -> ast::variant;
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::variant;
fn item_enum_poly(&self,
span: Span,
name: Ident,
@ -217,9 +218,9 @@ pub trait AstBuilder {
fn item_ty_poly(&self,
span: Span,
name: Ident,
ty: ast::Ty,
ty: P<ast::Ty>,
generics: Generics) -> @ast::item;
fn item_ty(&self, span: Span, name: Ident, ty: ast::Ty) -> @ast::item;
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::item;
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
@ -250,7 +251,7 @@ impl AstBuilder for @ExtCtxt {
global: bool,
mut idents: ~[ast::Ident],
lifetimes: OptVec<ast::Lifetime>,
types: ~[ast::Ty])
types: ~[P<ast::Ty>])
-> ast::Path {
let last_identifier = idents.pop();
let mut segments: ~[ast::PathSegment] = idents.move_iter()
@ -273,23 +274,23 @@ impl AstBuilder for @ExtCtxt {
}
}
fn ty_mt(&self, ty: ast::Ty, mutbl: ast::Mutability) -> ast::mt {
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::mt {
ast::mt {
ty: ~ty,
ty: ty,
mutbl: mutbl
}
}
fn ty(&self, span: Span, ty: ast::ty_) -> ast::Ty {
ast::Ty {
fn ty(&self, span: Span, ty: ast::ty_) -> P<ast::Ty> {
P(ast::Ty {
id: ast::DUMMY_NODE_ID,
span: span,
node: ty
}
})
}
fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>)
-> ast::Ty {
-> P<ast::Ty> {
self.ty(path.span,
ast::ty_path(path, bounds, ast::DUMMY_NODE_ID))
}
@ -297,28 +298,28 @@ impl AstBuilder for @ExtCtxt {
// Might need to take bounds as an argument in the future, if you ever want
// to generate a bounded existential trait type.
fn ty_ident(&self, span: Span, ident: ast::Ident)
-> ast::Ty {
-> P<ast::Ty> {
self.ty_path(self.path_ident(span, ident), None)
}
fn ty_rptr(&self,
span: Span,
ty: ast::Ty,
ty: P<ast::Ty>,
lifetime: Option<ast::Lifetime>,
mutbl: ast::Mutability)
-> ast::Ty {
-> P<ast::Ty> {
self.ty(span,
ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl)))
}
fn ty_uniq(&self, span: Span, ty: ast::Ty) -> ast::Ty {
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
self.ty(span, ast::ty_uniq(self.ty_mt(ty, ast::MutImmutable)))
}
fn ty_box(&self, span: Span,
ty: ast::Ty, mutbl: ast::Mutability) -> ast::Ty {
ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> {
self.ty(span, ast::ty_box(self.ty_mt(ty, mutbl)))
}
fn ty_option(&self, ty: ast::Ty) -> ast::Ty {
fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
self.ty_path(
self.path_all(dummy_sp(),
true,
@ -331,24 +332,24 @@ impl AstBuilder for @ExtCtxt {
~[ ty ]), None)
}
fn ty_field_imm(&self, span: Span, name: Ident, ty: ast::Ty) -> ast::TypeField {
fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField {
ast::TypeField {
ident: name,
mt: ast::mt { ty: ~ty, mutbl: ast::MutImmutable },
mt: ast::mt { ty: ty, mutbl: ast::MutImmutable },
span: span,
}
}
fn ty_infer(&self, span: Span) -> ast::Ty {
fn ty_infer(&self, span: Span) -> P<ast::Ty> {
self.ty(span, ast::ty_infer)
}
fn ty_nil(&self) -> ast::Ty {
ast::Ty {
fn ty_nil(&self) -> P<ast::Ty> {
P(ast::Ty {
id: ast::DUMMY_NODE_ID,
node: ast::ty_nil,
span: dummy_sp(),
}
})
}
fn typaram(&self, id: ast::Ident, bounds: OptVec<ast::TyParamBound>) -> ast::TyParam {
@ -358,12 +359,12 @@ impl AstBuilder for @ExtCtxt {
// 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: &OptVec<ast::TyParam>) -> ~[ast::Ty] {
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>] {
opt_vec::take_vec(
ty_params.map(|p| self.ty_ident(dummy_sp(), p.ident)))
}
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[ast::Ty] {
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[P<ast::Ty>] {
opt_vec::take_vec(
ty_params.map(|p| self.ty_path(
self.path_global(dummy_sp(), ~[p.ident]), None)))
@ -419,7 +420,7 @@ impl AstBuilder for @ExtCtxt {
sp: Span,
mutbl: bool,
ident: ast::Ident,
typ: ast::Ty,
typ: P<ast::Ty>,
ex: @ast::Expr)
-> @ast::Stmt {
let pat = if mutbl {
@ -438,26 +439,26 @@ impl AstBuilder for @ExtCtxt {
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
}
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@Expr>) -> ast::Block {
fn block(&self, span: Span, stmts: ~[@ast::Stmt], expr: Option<@Expr>) -> P<ast::Block> {
self.block_all(span, ~[], stmts, expr)
}
fn block_expr(&self, expr: @ast::Expr) -> ast::Block {
fn block_expr(&self, expr: @ast::Expr) -> P<ast::Block> {
self.block_all(expr.span, ~[], ~[], Some(expr))
}
fn block_all(&self,
span: Span,
view_items: ~[ast::view_item],
stmts: ~[@ast::Stmt],
expr: Option<@ast::Expr>) -> ast::Block {
ast::Block {
expr: Option<@ast::Expr>) -> P<ast::Block> {
P(ast::Block {
view_items: view_items,
stmts: stmts,
expr: expr,
id: ast::DUMMY_NODE_ID,
rules: ast::DefaultBlock,
span: span,
}
})
}
fn expr(&self, span: Span, node: ast::Expr_) -> @ast::Expr {
@ -525,7 +526,7 @@ impl AstBuilder for @ExtCtxt {
self.expr(span,
ast::ExprMethodCall(ast::DUMMY_NODE_ID, expr, ident, ~[], args, ast::NoSugar))
}
fn expr_block(&self, b: ast::Block) -> @ast::Expr {
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr {
self.expr(b.span, ast::ExprBlock(b))
}
fn field_imm(&self, span: Span, name: Ident, e: @ast::Expr) -> ast::Field {
@ -575,7 +576,7 @@ impl AstBuilder for @ExtCtxt {
}
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: ast::Ty) -> @ast::Expr {
fn expr_cast(&self, sp: Span, expr: @ast::Expr, ty: P<ast::Ty>) -> @ast::Expr {
self.expr(sp, ast::ExprCast(expr, ty))
}
@ -673,23 +674,24 @@ impl AstBuilder for @ExtCtxt {
self.expr(span, ast::ExprIf(cond, self.block_expr(then), els))
}
fn lambda_fn_decl(&self, span: Span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::Expr {
fn lambda_fn_decl(&self, span: Span,
fn_decl: P<ast::fn_decl>, blk: P<ast::Block>) -> @ast::Expr {
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
}
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: ast::Block) -> @ast::Expr {
fn lambda(&self, span: Span, ids: ~[ast::Ident], blk: P<ast::Block>) -> @ast::Expr {
let fn_decl = self.fn_decl(
ids.map(|id| self.arg(span, *id, self.ty_infer(span))),
self.ty_infer(span));
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
}
fn lambda0(&self, _span: Span, blk: ast::Block) -> @ast::Expr {
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
fn lambda0(&self, _span: Span, blk: P<ast::Block>) -> @ast::Expr {
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
quote_expr!(*self, || $blk_e )
}
fn lambda1(&self, _span: Span, blk: ast::Block, ident: ast::Ident) -> @ast::Expr {
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
fn lambda1(&self, _span: Span, blk: P<ast::Block>, ident: ast::Ident) -> @ast::Expr {
let blk_e = self.expr(blk.span, ast::ExprBlock(blk));
quote_expr!(*self, |$ident| $blk_e )
}
@ -713,7 +715,7 @@ impl AstBuilder for @ExtCtxt {
self.lambda1(span, self.block(span, stmts, None), ident)
}
fn arg(&self, span: Span, ident: ast::Ident, ty: ast::Ty) -> ast::arg {
fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::arg {
let arg_pat = self.pat_ident(span, ident);
ast::arg {
ty: ty,
@ -723,13 +725,13 @@ impl AstBuilder for @ExtCtxt {
}
// XXX unused self
fn fn_decl(&self, inputs: ~[ast::arg], output: ast::Ty) -> ast::fn_decl {
ast::fn_decl {
fn fn_decl(&self, inputs: ~[ast::arg], output: P<ast::Ty>) -> P<ast::fn_decl> {
P(ast::fn_decl {
inputs: inputs,
output: output,
cf: ast::return_val,
variadic: false
}
})
}
fn item(&self, span: Span,
@ -748,9 +750,9 @@ impl AstBuilder for @ExtCtxt {
span: Span,
name: Ident,
inputs: ~[ast::arg],
output: ast::Ty,
output: P<ast::Ty>,
generics: Generics,
body: ast::Block) -> @ast::item {
body: P<ast::Block>) -> @ast::item {
self.item(span,
name,
~[],
@ -765,8 +767,8 @@ impl AstBuilder for @ExtCtxt {
span: Span,
name: Ident,
inputs: ~[ast::arg],
output: ast::Ty,
body: ast::Block
output: P<ast::Ty>,
body: P<ast::Block>
) -> @ast::item {
self.item_fn_poly(
span,
@ -777,7 +779,7 @@ impl AstBuilder for @ExtCtxt {
body)
}
fn variant(&self, span: Span, name: Ident, tys: ~[ast::Ty]) -> ast::variant {
fn variant(&self, span: Span, name: Ident, tys: ~[P<ast::Ty>]) -> ast::variant {
let args = tys.move_iter().map(|ty| {
ast::variant_arg { ty: ty, id: ast::DUMMY_NODE_ID }
}).collect();
@ -844,12 +846,12 @@ impl AstBuilder for @ExtCtxt {
)
}
fn item_ty_poly(&self, span: Span, name: Ident, ty: ast::Ty,
fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
generics: Generics) -> @ast::item {
self.item(span, name, ~[], ast::item_ty(ty, generics))
}
fn item_ty(&self, span: Span, name: Ident, ty: ast::Ty) -> @ast::item {
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::item {
self.item_ty_poly(span, name, ty, ast_util::empty_generics())
}