Skip to content

Rust: extract source files of dependencies #19506

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 32 commits into from
May 24, 2025
Merged

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented May 16, 2025

No description provided.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 16, 2025
@aibaars aibaars force-pushed the aibaars/rust-extract-libs branch 2 times, most recently from 69eed04 to e4ee4a9 Compare May 16, 2025 14:57
@redsun82 redsun82 changed the title Rust: extract source files of depdendencies Rust: extract source files of dependencies May 19, 2025
@aibaars aibaars force-pushed the aibaars/rust-extract-libs branch from f7f434b to af440c3 Compare May 20, 2025 08:52
@hvitved hvitved force-pushed the aibaars/rust-extract-libs branch from af440c3 to b5a0317 Compare May 20, 2025 09:26
@aibaars aibaars force-pushed the aibaars/rust-extract-libs branch 6 times, most recently from 4865293 to 4313513 Compare May 21, 2025 13:45
@hvitved hvitved force-pushed the aibaars/rust-extract-libs branch from ed28076 to fd5e4a4 Compare May 22, 2025 08:13
@aibaars aibaars force-pushed the aibaars/rust-extract-libs branch from fd5e4a4 to 7e5f652 Compare May 22, 2025 09:36
@@ -621,6 +637,45 @@ impl<'a> Translator<'a> {
})
}

pub(crate) fn should_be_excluded(&self, item: &impl ast::AstNode) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot shake the feeling this is a bit a roundabout way of doing it: what I mean, is reconstructing the context around the AstNode by visiting the parent, when the emission was requested by emitting the parent already.

I wonder if we shouldn't do this by generating a new exclusion point where the emission of the body takes place. What about having this in the template for ast node emission:

    pub(crate) fn emit_{{snake_case_name}}(&mut self, node: &ast::{{ast_name}}) -> Option<Label<generated::{{name}}>> {
        pre_emit!({{name}}, self, node);
        {{#has_attrs}}
        if self.should_be_excluded(node) { return None; }
        {{/has_attrs}}
        {{#fields}}
        let {{name}} =
            {{#is_body}}
            if self.should_skip_bodies() { None } else {
            {{/is_body}}
            {{#predicate}}
            node.{{method}}().is_some()
            {{/predicate}}
            {{#string}}
            node.try_get_text()
            {{/string}}
            {{#list}}
            node.{{method}}().filter_map(|x| self.emit_{{snake_case_ty}}(&x)).collect()
            {{/list}}
            {{#optional}}
            node.{{method}}().and_then(|x| self.emit_{{snake_case_ty}}(&x))
            {{/optional}}
            {{#is_body}}
            }
            {{/is_body}}
            ;
        {{/fields}}
        ...

(and adding is_body: field.name == "body", to the FieldType::Optional(ty) => ExtractorNodeFieldInfo creation). This will cover all possible bodies, and avoid their emission at the sources without working up the AST. For example:

        let body = if self.should_skip_bodies() {
            None
        } else {
            node.body().and_then(|x| self.emit_expr(&x))
        };

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, the above does not also skip pat, but something could be done there at generation level as well

Copy link
Contributor

Choose a reason for hiding this comment

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

here's what I mean: #19559 shifts the logic from climbing up the AST in the base extractor to generating the property skipping at field emission level, with the logic in the ast-generator instead.

Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

LGTM, but we do need a DCA run on this before merging. #19559 can be considered as separate follow-up.

@aibaars aibaars force-pushed the aibaars/rust-extract-libs branch from 7df384b to df99e06 Compare May 23, 2025 05:47
aibaars added 2 commits May 23, 2025 10:35
…brary mode

When analysing a repository with multiple separate but related sub-projects there is a
risk that some source file are extracted in library mode as well as source  mode.

To prevent this we pre-fill 'processed_files' set with all source files, even though they have
not be processed yet, but are known to be processed later..

This prevents source file to be
@aibaars aibaars marked this pull request as ready for review May 23, 2025 10:03
@aibaars aibaars requested a review from a team as a code owner May 23, 2025 10:03
Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

Happy to merge this if we're satisfied by DCA

@hvitved hvitved merged commit 16690cc into main May 24, 2025
19 checks passed
@hvitved hvitved deleted the aibaars/rust-extract-libs branch May 24, 2025 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy