Skip to content

Generate rustpython-ast based off of Python.asdl #2399

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

Merged
merged 10 commits into from
Jan 25, 2021
Merged

Conversation

coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Jan 10, 2021

cc @isidentical, I think you had mentioned being interested in this

Closes #2395, closes #2388

@coolreader18 coolreader18 force-pushed the coolreader18/asdl branch 6 times, most recently from 0135b91 to 11a1255 Compare January 11, 2021 01:40
@coolreader18
Copy link
Member Author

🎉

❯ rustpython
Welcome to the magnificent Rust Python 0.1.2 interpreter 😱 🖖
>>>>> import flask
>>>>> flask
<module 'flask' from '/home/coolreader18/rspy-tests/pallets/flask/__init__.py'>

@coolreader18 coolreader18 marked this pull request as ready for review January 11, 2021 18:58
@coolreader18
Copy link
Member Author

@pca006132 this also implements AST mapping, since it's pretty easy when everything's autogenerated :)

@pca006132
Copy link
Contributor

@pca006132 this also implements AST mapping, since it's pretty easy when everything's autogenerated :)

I just have a glance on it, so the python scripts are used for parsing the python asdl file, and generate the rust code for AST definitions?

Considering the change would break `rustpython_parser' API, maybe a version bump would be needed?

@coolreader18
Copy link
Member Author

Yeah, I was planning to release all new versions next time we release, we make breaking changes often to all of our crates.

@coolreader18
Copy link
Member Author

@youknowone could you review this?

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry to be late 😵

Self::Str(s)
}
}
impl From<Vec<u8>> for Constant {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intended to be a Vec not a Box<[u8]>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured it doesn't make too much of a difference since it's not going to be "alive" for very long.

Comment on lines +8 to +11
match result {
Ok(mapped) => mapped,
Err(never) => match never {},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Err is Infallible, isn't it just result.unwrap()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but this guarantees that no panic machinery gets pulled in.

Comment on lines +83 to +85
let ast = match parser::parse(source, mode) {
Ok(x) => x,
Err(e) => return Err(CompileError::from_parse(e, source, source_path)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let ast = parser::parse(source, mode).map_err(|e| CompileError::from_parse(e, source, source_path))?;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source_path is moved into from_parse(), and rust doesn't connect the closure to the early return, so I have to manually do the map_err.

if let OptionalArg::Present(default) = default {
ret.or_else(|ex| catch_attr_exception(ex, default, vm))
Ok(vm.get_attribute_opt(obj, attr)?.unwrap_or(default))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this better to be changed like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, I added the get_attribute_opt function for use in _ast, but I realized that the logic was being duplicated here as well.

@coolreader18 coolreader18 merged commit 19f9ca6 into master Jan 25, 2021
@youknowone youknowone deleted the coolreader18/asdl branch January 27, 2021 23:11
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 this pull request may close these issues.

[RFC] AST Customization
3 participants