Skip to content

Conversation

@PetroZarytskyi
Copy link
Collaborator

Currently, we track the correspondance of the original variables and their adjoints in a map m_Variables as x --> _d_x. However, x is stored a decl and _d_x is stored as an expr. The latter results in us reusing the same DeclRefExpr of _d_x. Apart from that, it makes it hard to get the actual declaration of _d_x.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions


/// Map used to keep track of variable declarations and match them
/// with their derivatives.
std::unordered_map<const clang::ValueDecl*, clang::Expr*> m_Variables;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member variable 'm_Variables' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::unordered_map<const clang::ValueDecl*, clang::Expr*> m_Variables;
                                                            ^

clang::Expr* m_RestoreTracker = nullptr;
/// Map used to keep track of variable declarations and match them
/// with their derivatives.
std::unordered_map<const clang::ValueDecl*, clang::VarDecl*> m_Variables;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member variable 'm_Variables' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

    std::unordered_map<const clang::ValueDecl*, clang::VarDecl*> m_Variables;
                                                                 ^

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@vgvassilev Should we avoid protected members?

Copy link
Owner

Choose a reason for hiding this comment

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

Probably that's to late to consider... Let's ignore this and maybe adjust the config file.

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Currently, we track the correspondance of the original variables and their adjoints in a map `m_Variables` as `x` --> `_d_x`. However, `x` is stored a decl and `_d_x` is stored as an expr. The latter results in us reusing the same `DeclRefExpr` of `_d_x`. Apart from that, it makes it hard to get the actual declaration of `_d_x`.

/// Map used to keep track of variable declarations and match them
/// with their derivatives.
std::unordered_map<const clang::ValueDecl*, clang::Expr*> m_Variables;
Copy link
Owner

Choose a reason for hiding this comment

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

What is this files used for? In principle we cannot reuse expressions (or decl-ref expressions) as clang builds a separate whenever they are needed. Can we drop this in favor of some utility function that builds a new expression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants