Skip to content

New layout for Arguments node to enhance performance. (and more so if possible) #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
youknowone opened this issue May 18, 2023 · 1 comment · Fixed by #59
Closed

Comments

@youknowone
Copy link
Member

Currently the rust AST nodes layout is almost same as Python ast defined in Python side.

pub struct Arguments<R = TextRange> {
    pub range: OptionalRange<R>,
    pub posonlyargs: Vec<Arg<R>>,
    pub args: Vec<Arg<R>>,
    pub vararg: Option<Box<Arg<R>>>,
    pub kwonlyargs: Vec<Arg<R>>,
    pub kw_defaults: Vec<Expr<R>>,
    pub kwarg: Option<Box<Arg<R>>>,
    pub defaults: Vec<Expr<R>>,
}

Which is less parser-friendly than:

pub struct Arguments<R = TextRange> {
    range: ...,
    posonlyargs: Vec<Argument>,
    args: Vec<Argument>,
    vararg: Option<Box<Argument>>,
    kwonlyargs: Vec<Argument>,
    kwarg: Option<Box<Argument>>,
    type_comment: Option<String>,  // unparsed type_comment
    // no defaults and kw_defaults here
}

struct Argument {
    arg: Identifier,
    annotation: Option<Expr>,
    default: Option<Expr>,   // default is placed here unlike Arg
}

cc @MichaReiser

@MichaReiser
Copy link
Contributor

MichaReiser commented May 18, 2023

I like that. It should also make it less error prone to inspect the AST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants