Rust: move body skipping logic to code generation#19559
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.mustachetemplate to wrap “body” fields withshould_skip_bodies() - Extend the AST generator to mark specific fields (e.g., function body) as
Bodyand 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_excludedonly applies to attribute-based exclusion now. Consider renaming toshould_be_excluded_by_attrsor 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_attrsblock, 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; }
529b714 to
78bb41e
Compare
Contributor
Author
|
I'm pulling out the part about extracting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.