mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-28 14:25:43 +00:00
Remove unnecessary boxing of ASDL product children
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
6e89b3ab1a
commit
f4672e4256
5 changed files with 15 additions and 17 deletions
|
@ -89,6 +89,7 @@ class TypeInfo:
|
|||
self.has_userdata = None
|
||||
self.children = set()
|
||||
self.boxed = False
|
||||
self.product = False
|
||||
|
||||
def __repr__(self):
|
||||
return f"<TypeInfo: {self.name}>"
|
||||
|
@ -145,6 +146,7 @@ class FindUserdataTypesVisitor(asdl.VisitorBase):
|
|||
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 @@ class StructVisitor(TypeInfoEmitVisitor):
|
|||
if fieldtype and fieldtype.has_userdata:
|
||||
typ = f"{typ}<U>"
|
||||
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
|
||||
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}>"
|
||||
|
|
|
@ -337,8 +337,8 @@ pub enum Cmpop {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Comprehension<U = ()> {
|
||||
pub target: Box<Expr<U>>,
|
||||
pub iter: Box<Expr<U>>,
|
||||
pub target: Expr<U>,
|
||||
pub iter: Expr<U>,
|
||||
pub ifs: Vec<Expr<U>>,
|
||||
pub is_async: usize,
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ pub type Arg<U = ()> = Located<ArgData<U>, U>;
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct KeywordData<U = ()> {
|
||||
pub arg: Option<Ident>,
|
||||
pub value: Box<Expr<U>>,
|
||||
pub value: Expr<U>,
|
||||
}
|
||||
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
|
||||
|
||||
|
@ -388,13 +388,13 @@ pub type Alias<U = ()> = Located<AliasData, U>;
|
|||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Withitem<U = ()> {
|
||||
pub context_expr: Box<Expr<U>>,
|
||||
pub context_expr: Expr<U>,
|
||||
pub optional_vars: Option<Box<Expr<U>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct MatchCase<U = ()> {
|
||||
pub pattern: Box<Pattern<U>>,
|
||||
pub pattern: Pattern<U>,
|
||||
pub guard: Option<Box<Expr<U>>>,
|
||||
pub body: Vec<Stmt<U>>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue