Remove unnecessary boxing of ASDL product children

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2022-12-11 15:39:47 -08:00
parent f126b79b93
commit 408d15f608
5 changed files with 15 additions and 17 deletions

View file

@ -520,12 +520,12 @@ WithItems: Vec<ast::Withitem> = {
<items:TestAs<ExprOrWithitemsGoal>> =>? items.try_into(),
<first:TestAs<ExprOrWithitemsGoal>> "as" <vars:Expression> =>? {
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 }])
},
<first:TestAs<ExprOrWithitemsGoal>> <n:("as" Expression)?> "," <mut items:OneOrMore<WithItem>> =>? {
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<ast::Withitem> = {
WithItem: ast::Withitem = {
<context_expr:Test> <n:("as" Expression)?> => {
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 = {
<location:@L> <is_async:"async"?> "for" <target:ExpressionList> "in" <iter:OrTest> <ifs:ComprehensionIf*> <end_location:@R> => {
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 },
}

View file

@ -72,10 +72,7 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentList, Lexi
keywords.push(ast::Keyword::new(
start,
end,
ast::KeywordData {
arg: name,
value: Box::new(value),
},
ast::KeywordData { arg: name, value },
));
}
None => {

View file

@ -117,7 +117,7 @@ impl TryFrom<ExprOrWithitems> for Vec<ast::Withitem> {
.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<ExprOrWithitems> for Vec<ast::Withitem> {
.collect())
}
_ => Ok(vec![ast::Withitem {
context_expr: Box::new(expr_or_withitems.try_into()?),
context_expr: expr_or_withitems.try_into()?,
optional_vars: None,
}]),
}