Skip to content

Rust: re-enable attribute macro expansion in library mode #19588

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 1 commit into from
May 29, 2025

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented May 27, 2025

Now #19572 is merged it should be possible to remove the workaround and re-enable attribute macro expansion on library files. Reverts df99e06

@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 08:54
@aibaars aibaars requested a review from a team as a code owner May 27, 2025 08:54
@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 27, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 restores attribute macro expansion for library crates by removing the early-return guard that skipped expansion in library mode.

  • Removed the if self.source_kind == SourceKind::Library block and accompanying TODO.
  • Now emit_item_expansion runs uniformly for both binary and library sources.
  • Ensures that previously disabled macro expansions are once again performed in library mode.
Comments suppressed due to low confidence (3)

rust/extractor/src/translate/base.rs:734

  • [nitpick] Add or update the doc comment for emit_item_expansion to explain that attribute macro expansion is now always performed for library crates and note any implications for performance or configuration.
pub(crate) fn emit_item_expansion(&mut self, node: &ast::Item, label: Label<generated::Item>) {

rust/extractor/src/translate/base.rs:737

  • Re-enabling expansion for libraries may reintroduce exponential expansion issues (as noted by the removed TODO). Consider adding a configurable expansion depth limit or heuristic to prevent performance regressions on large library crates.
(|| {

rust/extractor/src/translate/base.rs:737

  • Add unit tests covering emit_item_expansion behavior in library mode to ensure macro expansions are handled correctly and to catch performance or correctness regressions early.
(|| {

@geoffw0
Copy link
Contributor

geoffw0 commented May 27, 2025

Where might we have expected to see a failure if this had been re-enabled without the underlying fix?

@aibaars
Copy link
Contributor Author

aibaars commented May 27, 2025

Where might we have expected to see a failure if this had been re-enabled without the underlying fix?

We ran into likely exponential performance problem for some nested macro expansions causing the extractor to use an enormous amount of memory (100GB+). An example library that caused issues was: https://github.com/ferrilab/ferrilab/blob/4105b12e8d6c213156149bb6ba170a821c434e14/funty/src/lib.rs#L1466-L1524

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

We ran into likely exponential performance problem for some nested macro expansions causing the extractor to use an enormous amount of memory (100GB+).

I see no such regression in the DCA run, so 👍.

There is a decrease in "Lines of user-written code in the database", is that expected?

update: ah, that's probably because one of the projects failed (timed out). It would be good to be confident this is not a problem.

@aibaars
Copy link
Contributor Author

aibaars commented May 28, 2025

There is a decrease in "Lines of user-written code in the database", is that expected?

update: ah, that's probably because one of the projects failed (timed out). It would be good to be confident this is not a problem.

The new version has much fewer extracted files. Comparing the list of files of both variants I see that the missing files are all in /tests/ folders which ought to have been excluded by the `paths-ignore: '**/tests' line. I have no idea why the run with the old version included those files. So, the new run shows better results, but this cannot be due to the changes in this PR, so it's a bit of a mystery .

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

OK, happy for this to be merged now / after the second DCA run is finished.

@aibaars aibaars merged commit 55be5fb into main May 29, 2025
14 checks passed
@aibaars aibaars deleted the aibaars/rust-enable-attribute-macros branch May 29, 2025 08:59
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.

2 participants