From e4916fc4c5bbe5cec089ca7537af260c5c150b23 Mon Sep 17 00:00:00 2001 From: kvark Date: Mon, 15 Sep 2014 23:01:45 -0400 Subject: [PATCH 1/2] Updated macros to use P instead of Gc --- serde_macros/src/lib.rs | 76 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/serde_macros/src/lib.rs b/serde_macros/src/lib.rs index a61f298f..66685a2a 100644 --- a/serde_macros/src/lib.rs +++ b/serde_macros/src/lib.rs @@ -7,8 +7,6 @@ extern crate syntax; extern crate rustc; -use std::gc::Gc; - use syntax::ast::{ Attribute, Ident, @@ -21,7 +19,6 @@ use syntax::ast::{ MutMutable, LitNil, LitStr, - P, StructField, Variant, }; @@ -55,6 +52,7 @@ use syntax::ext::deriving::generic::ty::{ borrowed_explicit_self, }; use syntax::parse::token; +use syntax::ptr::P; use rustc::plugin::Registry; @@ -63,18 +61,18 @@ use rustc::plugin::Registry; pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension( token::intern("deriving_serializable"), - ItemDecorator(expand_deriving_serializable)); + ItemDecorator(box expand_deriving_serializable)); reg.register_syntax_extension( token::intern("deriving_deserializable"), - ItemDecorator(expand_deriving_deserializable)); + ItemDecorator(box expand_deriving_deserializable)); } fn expand_deriving_serializable(cx: &mut ExtCtxt, sp: Span, - mitem: Gc, - item: Gc, - push: |Gc|) { + mitem: &MetaItem, + item: &Item, + push: |P|) { let inline = cx.meta_word(sp, token::InternedString::new("inline")); let attrs = vec!(cx.attribute(sp, inline)); @@ -123,11 +121,11 @@ fn expand_deriving_serializable(cx: &mut ExtCtxt, fn serializable_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure, - item: Gc - ) -> Gc { - let serializer = substr.nonself_args[0]; + item: &Item + ) -> P { + let serializer = substr.nonself_args[0].clone(); - match (&item.deref().node, substr.fields) { + match (&item.node, substr.fields) { (&ItemStruct(ref definition, _), &Struct(ref fields)) => { if fields.is_empty() { // unit structs have no fields and need to return `Ok()` @@ -139,10 +137,10 @@ fn serializable_substructure(cx: &ExtCtxt, ); let len = fields.len(); - let mut stmts: Vec> = definition.fields.iter() + let mut stmts: Vec> = definition.fields.iter() .zip(fields.iter()) .enumerate() - .map(|(i, (def, &FieldInfo { name, self_, span, .. }))| { + .map(|(i, (def, &FieldInfo { name, ref self_, span, .. }))| { let serial_name = find_serial_name(def.node.attrs.iter()); let name = match (serial_name, name) { (Some(serial), _) => serial.clone(), @@ -178,9 +176,9 @@ fn serializable_substructure(cx: &ExtCtxt, ); let len = fields.len(); - let stmts: Vec> = definition.variants.iter() + let stmts: Vec> = definition.variants.iter() .zip(fields.iter()) - .map(|(def, &FieldInfo { self_, span, .. })| { + .map(|(def, &FieldInfo { ref self_, span, .. })| { let _serial_name = find_serial_name(def.node.attrs.iter()); quote_stmt!( cx, @@ -202,9 +200,9 @@ fn serializable_substructure(cx: &ExtCtxt, pub fn expand_deriving_deserializable(cx: &mut ExtCtxt, span: Span, - mitem: Gc, - item: Gc, - push: |Gc|) { + mitem: &MetaItem, + item: &Item, + push: |P|) { let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -253,9 +251,9 @@ pub fn expand_deriving_deserializable(cx: &mut ExtCtxt, } fn deserializable_substructure(cx: &mut ExtCtxt, span: Span, - substr: &Substructure) -> Gc { - let deserializer = substr.nonself_args[0]; - let token = substr.nonself_args[1]; + substr: &Substructure) -> P { + let deserializer = substr.nonself_args[0].clone(); + let token = substr.nonself_args[1].clone(); match *substr.fields { StaticStruct(ref definition, ref fields) => { @@ -265,7 +263,7 @@ fn deserializable_substructure(cx: &mut ExtCtxt, span: Span, substr.type_ident, definition.fields.as_slice(), fields, - deserializer, + deserializer.clone(), token) } StaticEnum(ref definition, ref fields) => { @@ -288,9 +286,9 @@ fn deserialize_struct( type_ident: Ident, definitions: &[StructField], fields: &StaticFields, - deserializer: Gc, - token: Gc -) -> Gc { + deserializer: P, + token: P +) -> P { let serial_names: Vec> = definitions.iter().map(|def| find_serial_name(def.node.attrs.iter()) @@ -302,7 +300,7 @@ fn deserialize_struct( type_ident, serial_names.as_slice(), fields, - deserializer + deserializer.clone() ); let map_block = deserialize_struct_from_map( @@ -311,7 +309,7 @@ fn deserialize_struct( type_ident, serial_names.as_slice(), fields, - deserializer + deserializer.clone() ); quote_expr!( @@ -336,8 +334,8 @@ fn deserialize_struct_from_struct( type_ident: Ident, serial_names: &[Option], fields: &StaticFields, - deserializer: Gc -) -> Gc { + deserializer: P +) -> P { let expect_struct_field = cx.ident_of("expect_struct_field"); let call = deserializable_static_fields( @@ -368,15 +366,15 @@ fn deserialize_struct_from_map( type_ident: Ident, serial_names: &[Option], fields: &StaticFields, - deserializer: Gc -) -> Gc { + deserializer: P +) -> P { let fields = match *fields { Unnamed(_) => fail!(), Named(ref fields) => fields.as_slice(), }; // Declare each field. - let let_fields: Vec> = fields.iter() + let let_fields: Vec> = fields.iter() .map(|&(name, span)| { quote_stmt!(cx, let mut $name = None) }) @@ -401,7 +399,7 @@ fn deserialize_struct_from_map( }) .collect(); - let extract_fields: Vec> = serial_names.iter() + let extract_fields: Vec> = serial_names.iter() .zip(fields.iter()) .map(|(serial, &(name, span))| { let serial_name = match serial { @@ -470,9 +468,9 @@ fn deserialize_enum( type_ident: Ident, definitions: &[P], fields: &[(Ident, Span, StaticFields)], - deserializer: Gc, - token: Gc -) -> Gc { + deserializer: P, + token: P +) -> P { let type_name = cx.expr_str(span, token::get_ident(type_ident)); let serial_names = definitions.iter().map(|def| @@ -528,8 +526,8 @@ fn deserializable_static_fields( outer_pat_ident: Ident, serial_names: &[Option], fields: &StaticFields, - getarg: |&ExtCtxt, Span, token::InternedString| -> Gc -) -> Gc { + getarg: |&ExtCtxt, Span, token::InternedString| -> P +) -> P { match *fields { Unnamed(ref fields) => { if fields.is_empty() { From c064b0627227cbe727fdcb3b2cf3a761d0e7e415 Mon Sep 17 00:00:00 2001 From: kvark Date: Tue, 16 Sep 2014 22:34:29 -0400 Subject: [PATCH 2/2] Fixed serde2 --- serde2/serde2_macros/src/lib.rs | 67 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/serde2/serde2_macros/src/lib.rs b/serde2/serde2_macros/src/lib.rs index 74e2032d..586e4410 100644 --- a/serde2/serde2_macros/src/lib.rs +++ b/serde2/serde2_macros/src/lib.rs @@ -6,8 +6,6 @@ extern crate syntax; extern crate rustc; -use std::gc::Gc; - use syntax::ast::{ Ident, MetaItem, @@ -45,6 +43,7 @@ use syntax::ext::deriving::generic::ty::{ borrowed_explicit_self, }; use syntax::parse::token; +use syntax::ptr::P; use rustc::plugin::Registry; @@ -53,20 +52,20 @@ use rustc::plugin::Registry; pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension( token::intern("deriving_serializable"), - ItemDecorator(expand_deriving_serializable)); + ItemDecorator(box expand_deriving_serializable)); /* reg.register_syntax_extension( token::intern("deriving_deserializable"), - ItemDecorator(expand_deriving_deserializable)); + ItemDecorator(box expand_deriving_deserializable)); */ } fn expand_deriving_serializable(cx: &mut ExtCtxt, sp: Span, - mitem: Gc, - item: Gc, - mut push: |Gc|) { + mitem: &MetaItem, + item: &Item, + mut push: |P|) { let inline = cx.meta_word(sp, token::InternedString::new("inline")); let attrs = vec!(cx.attribute(sp, inline)); @@ -105,8 +104,8 @@ fn expand_deriving_serializable(cx: &mut ExtCtxt, trait_def.expand(cx, mitem, item, push) } -fn serializable_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> Gc { - let serializer = substr.nonself_args[0]; +fn serializable_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> P { + let serializer = substr.nonself_args[0].clone(); match *substr.fields { Struct(ref fields) => { @@ -125,16 +124,16 @@ fn serializable_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> } } -fn serialize_tuple_struct(cx: &ExtCtxt) -> Gc { +fn serialize_tuple_struct(cx: &ExtCtxt) -> P { // unit structs have no fields and need to return `Ok()` quote_expr!(cx, Ok(())) } fn serialize_struct(cx: &ExtCtxt, span: Span, - serializer: Gc, + serializer: P, type_ident: Ident, - fields: &Vec) -> Gc { + fields: &Vec) -> P { let type_name = cx.expr_str( span, @@ -197,10 +196,10 @@ fn serialize_struct(cx: &ExtCtxt, fn serialize_enum(cx: &ExtCtxt, span: Span, - serializer: Gc, + serializer: P, type_ident: Ident, variant: &ast::Variant, - fields: &Vec) -> Gc { + fields: &Vec) -> P { let type_name = cx.expr_str( span, token::get_ident(type_ident) @@ -211,8 +210,8 @@ fn serialize_enum(cx: &ExtCtxt, ); let len = fields.len(); - let stmts: Vec> = fields.iter() - .map(|&FieldInfo { self_, span, .. }| { + let stmts: Vec> = fields.iter() + .map(|&FieldInfo { ref self_, span, .. }| { quote_stmt!( cx, try!($serializer.serialize_enum_elt(&$self_)) @@ -230,9 +229,9 @@ fn serialize_enum(cx: &ExtCtxt, /* pub fn expand_deriving_deserializable(cx: &mut ExtCtxt, span: Span, - mitem: Gc, - item: Gc, - push: |Gc|) { + mitem: &MetaItem, + item: &Item, + push: |P|) { let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -281,7 +280,7 @@ pub fn expand_deriving_deserializable(cx: &mut ExtCtxt, } fn deserializable_substructure(cx: &mut ExtCtxt, span: Span, - substr: &Substructure) -> Gc { + substr: &Substructure) -> P { let deserializer = substr.nonself_args[0]; let token = substr.nonself_args[1]; @@ -313,9 +312,9 @@ fn deserialize_struct( span: Span, type_ident: Ident, fields: &StaticFields, - deserializer: Gc, - token: Gc -) -> Gc { + deserializer: P, + token: P +) -> P { let struct_block = deserialize_struct_from_struct( cx, span, @@ -353,8 +352,8 @@ fn deserialize_struct_from_struct( span: Span, type_ident: Ident, fields: &StaticFields, - deserializer: Gc -) -> Gc { + deserializer: P +) -> P { let expect_struct_field = cx.ident_of("expect_struct_field"); let call = deserializable_static_fields( @@ -383,15 +382,15 @@ fn deserialize_struct_from_map( span: Span, type_ident: Ident, fields: &StaticFields, - deserializer: Gc -) -> Gc { + deserializer: P +) -> P { let fields = match *fields { Unnamed(_) => fail!(), Named(ref fields) => fields.as_slice(), }; // Declare each field. - let let_fields: Vec> = fields.iter() + let let_fields: Vec> = fields.iter() .map(|&(name, span)| { quote_stmt!(cx, let mut $name = None) }) @@ -411,7 +410,7 @@ fn deserialize_struct_from_map( }) .collect(); - let extract_fields: Vec> = fields.iter() + let extract_fields: Vec> = fields.iter() .map(|&(name, span)| { let name_str = cx.expr_str(span, token::get_ident(name)); quote_stmt!(cx, @@ -474,9 +473,9 @@ fn deserialize_enum( span: Span, type_ident: Ident, fields: &[(Ident, Span, StaticFields)], - deserializer: Gc, - token: Gc -) -> Gc { + deserializer: P, + token: P +) -> P { let type_name = cx.expr_str(span, token::get_ident(type_ident)); let variants = fields.iter() @@ -526,8 +525,8 @@ fn deserializable_static_fields( span: Span, outer_pat_ident: Ident, fields: &StaticFields, - getarg: |&ExtCtxt, Span, token::InternedString| -> Gc -) -> Gc { + getarg: |&ExtCtxt, Span, token::InternedString| -> P +) -> P { match *fields { Unnamed(ref fields) => { if fields.is_empty() {