Skip to content

Migrate #[autodiff] and #[rustc_autodiff] to the new attribute parser. #137774

Open
@ZuseZ4

Description

@ZuseZ4

Location

I think the author wants to add info to the rustc dev guide.

Summary

Hi @jdonszelmann,
first of all, thanks for the attribute refactor work and congrats on landing your big pr!
I recently introduced an #[autodiff] macro which can be applied on top of a function, and generates a second function. Both of the function then automatically receive a #[rustc_autodiff] attribute.
On of the two rustc_autodiff attributes, as well as the original autodiff macro take user arguments, so there is some duplicated parsing and verification. I'd like to move over to the new infra, and since a few people offered to help with autodiff, I thought this might be a nice opportunity to introduce them to it.
For reference, this was the original autodiff frontend PR: #129458

As a dummy example:

#[autodiff(df, Reverse, Duplicated, Duplicated)]
fn f(x: &f32, y: &mut f32) { *y  *= *x; }

would expand to:

#[rustc_autodiff]
fn f(x: &f32, y: &mut f32) { *y  *= *x; }
#[rustc_autodiff(Reverse, Duplicated, Duplicated)]
fn df(x: &f32, dx: &f32, y: &mut f32, dy: &mut f32) { // dummy code }

I think you haven't yet completed your plan to write a migration guide for the rustc-dev-guide, but do you have a migration PR that you can recommend to us as a blueprint to see how this could be done? Also, I don't know too much about your rework. Do you think the migration is going to end up as one big PR, or is it possible to split the work up?

Activity

added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Feb 28, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Feb 28, 2025
jdonszelmann

jdonszelmann commented on Feb 28, 2025

@jdonszelmann
Contributor

Yes, see #137687 for now. I'm also available for questions on zulip

jdonszelmann

jdonszelmann commented on Feb 28, 2025

@jdonszelmann
Contributor

Though you shouldn't have to deal with the limited pre-ast lowering parsing

added
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
A-attributesArea: Attributes (`#[…]`, `#![…]`)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-discussionCategory: Discussion or questions that doesn't represent real issues.
F-autodiff`#![feature(autodiff)]`
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
C-discussionCategory: Discussion or questions that doesn't represent real issues.
on Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.F-autodiff`#![feature(autodiff)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jdonszelmann@ZuseZ4@jieyouxu@rustbot

        Issue actions

          Migrate #[autodiff] and #[rustc_autodiff] to the new attribute parser. · Issue #137774 · rust-lang/rust