-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: move body skipping logic to code generation #19559
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors how body-skipping logic is applied by moving it from the Rust extractor’s translator into the AST code generator, so that function/const/static bodies (and other designated “body” fields) are conditionally omitted during code generation for library crates.
- Remove translator-level node exclusion and introduce a simple
should_skip_bodies()
check - Update the
extractor.mustache
template to wrap “body” fields withshould_skip_bodies()
- Extend the AST generator to mark specific fields (e.g., function body) as
Body
and generalizeFieldInfo
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
rust/extractor/src/translate/base.rs | Deleted the complex should_be_excluded(&AstNode) fn and added should_skip_bodies() ; renamed should_be_excluded_attrs to should_be_excluded |
rust/ast-generator/templates/extractor.mustache | Moved node-level exclusion into attribute-only block and added template logic to skip “body” fields |
rust/ast-generator/src/main.rs | Introduced FieldType::Body , helper constructors, and wired up Body fields in get_additional_fields and get_fields |
Comments suppressed due to low confidence (2)
rust/extractor/src/translate/base.rs:630
- [nitpick] The name
should_be_excluded
only applies to attribute-based exclusion now. Consider renaming toshould_be_excluded_by_attrs
or similar for clarity and to avoid confusion if a future node-level exclusion is needed.
pub(crate) fn should_be_excluded(&self, item: &impl ast::HasAttrs) -> bool {
rust/ast-generator/templates/extractor.mustache:38
- The global node exclusion check was moved inside the
has_attrs
block, so nodes without attributes no longer respectshould_be_excluded
. Reintroduce the unconditional check before handling attributes to preserve prior behavior.
if self.should_be_excluded(node) { return None; }
It also contains a refactoring where
FieldInfo{ name: "xxx".to_string(), ty: FieldType::Optional("Yyy".to_string() }
can now be written more succintlyFieldInfo::optional("xxx", "Yyy")
, and similarly for other field types.