diff --git a/compiler/ast/asdl_rs.py b/compiler/ast/asdl_rs.py index 06ee2e571e..ed5800f5de 100755 --- a/compiler/ast/asdl_rs.py +++ b/compiler/ast/asdl_rs.py @@ -89,6 +89,7 @@ def __init__(self, name): self.has_userdata = None self.children = set() self.boxed = False + self.product = False def __repr__(self): return f"" @@ -145,6 +146,7 @@ def visitProduct(self, product, name): info.has_userdata = True if len(product.fields) > 2: info.boxed = True + info.product = True self.add_children(name, product.fields) def add_children(self, name, fields): @@ -236,7 +238,7 @@ def visitField(self, field, parent, vis, depth): if fieldtype and fieldtype.has_userdata: typ = f"{typ}" # don't box if we're doing Vec, but do box if we're doing Vec>> - if fieldtype and fieldtype.boxed and (not field.seq or field.opt): + if fieldtype and fieldtype.boxed and (not (parent.product or field.seq) or field.opt): typ = f"Box<{typ}>" if field.opt: typ = f"Option<{typ}>" diff --git a/compiler/ast/src/ast_gen.rs b/compiler/ast/src/ast_gen.rs index 1917bec977..241ebe135a 100644 --- a/compiler/ast/src/ast_gen.rs +++ b/compiler/ast/src/ast_gen.rs @@ -337,8 +337,8 @@ pub enum Cmpop { #[derive(Clone, Debug, PartialEq)] pub struct Comprehension { - pub target: Box>, - pub iter: Box>, + pub target: Expr, + pub iter: Expr, pub ifs: Vec>, pub is_async: usize, } @@ -375,7 +375,7 @@ pub type Arg = Located, U>; #[derive(Clone, Debug, PartialEq)] pub struct KeywordData { pub arg: Option, - pub value: Box>, + pub value: Expr, } pub type Keyword = Located, U>; @@ -388,13 +388,13 @@ pub type Alias = Located; #[derive(Clone, Debug, PartialEq)] pub struct Withitem { - pub context_expr: Box>, + pub context_expr: Expr, pub optional_vars: Option>>, } #[derive(Clone, Debug, PartialEq)] pub struct MatchCase { - pub pattern: Box>, + pub pattern: Pattern, pub guard: Option>>, pub body: Vec>, } diff --git a/compiler/parser/python.lalrpop b/compiler/parser/python.lalrpop index cca2a46e9f..c2cf616b5b 100644 --- a/compiler/parser/python.lalrpop +++ b/compiler/parser/python.lalrpop @@ -520,12 +520,12 @@ WithItems: Vec = { > =>? items.try_into(), > "as" =>? { let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store))); - let context_expr = Box::new(first.try_into()?); + let context_expr = first.try_into()?; Ok(vec![ast::Withitem { context_expr, optional_vars }]) }, > "," > =>? { let optional_vars = n.map(|val| Box::new(set_context(val.1, ast::ExprContext::Store))); - let context_expr = Box::new(first.try_into()?); + let context_expr = first.try_into()?; items.insert(0, ast::Withitem { context_expr, optional_vars }); Ok(items) } @@ -534,7 +534,6 @@ WithItems: Vec = { WithItem: ast::Withitem = { => { let optional_vars = n.map(|val| Box::new(set_context(val.1, ast::ExprContext::Store))); - let context_expr = Box::new(context_expr); ast::Withitem { context_expr, optional_vars } }, }; @@ -1280,8 +1279,8 @@ SingleForComprehension: ast::Comprehension = { "for" "in" => { let is_async = is_async.is_some(); ast::Comprehension { - target: Box::new(set_context(target, ast::ExprContext::Store)), - iter: Box::new(iter), + target: set_context(target, ast::ExprContext::Store), + iter, ifs, is_async: if is_async { 1 } else { 0 }, } diff --git a/compiler/parser/src/function.rs b/compiler/parser/src/function.rs index bc4d5142ea..0cc934fb44 100644 --- a/compiler/parser/src/function.rs +++ b/compiler/parser/src/function.rs @@ -72,10 +72,7 @@ pub fn parse_args(func_args: Vec) -> Result { diff --git a/compiler/parser/src/with.rs b/compiler/parser/src/with.rs index 57ee1a6cf7..5f018c6b32 100644 --- a/compiler/parser/src/with.rs +++ b/compiler/parser/src/with.rs @@ -117,7 +117,7 @@ impl TryFrom for Vec { .items .into_iter() .map(|(context_expr, optional_vars)| ast::Withitem { - context_expr: Box::new(context_expr), + context_expr, optional_vars: optional_vars.map(|expr| { Box::new(context::set_context(*expr, ast::ExprContext::Store)) }), @@ -125,7 +125,7 @@ impl TryFrom for Vec { .collect()) } _ => Ok(vec![ast::Withitem { - context_expr: Box::new(expr_or_withitems.try_into()?), + context_expr: expr_or_withitems.try_into()?, optional_vars: None, }]), }