Skip to content
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

Rev ref returns #601

Merged
merged 1 commit into from
Aug 28, 2023
Merged

Conversation

PhrygianGates
Copy link
Contributor

@PhrygianGates PhrygianGates commented Jul 20, 2023

This PR rebase the #425 pull-request on top of master.

@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #601 (ea8b406) into master (24a15f9) will increase coverage by 0.20%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #601      +/-   ##
==========================================
+ Coverage   93.83%   94.03%   +0.20%     
==========================================
  Files          41       43       +2     
  Lines        6032     6218     +186     
==========================================
+ Hits         5660     5847     +187     
+ Misses        372      371       -1     
Files Changed Coverage Δ
include/clad/Differentiator/Compatibility.h 90.76% <ø> (ø)
include/clad/Differentiator/DerivativeBuilder.h 100.00% <ø> (ø)
include/clad/Differentiator/ReverseModeVisitor.h 98.70% <ø> (ø)
...e/clad/Differentiator/ReverseModeForwPassVisitor.h 100.00% <100.00%> (ø)
lib/Differentiator/BaseForwardModeVisitor.cpp 98.71% <100.00%> (-0.01%) ⬇️
lib/Differentiator/DerivativeBuilder.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ForwardModeVisitor.cpp 99.06% <100.00%> (ø)
lib/Differentiator/HessianModeVisitor.cpp 99.46% <100.00%> (ø)
lib/Differentiator/ReverseModeForwPassVisitor.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ReverseModeVisitor.cpp 95.73% <100.00%> (+0.13%) ⬆️
... and 1 more
Files Changed Coverage Δ
include/clad/Differentiator/Compatibility.h 90.76% <ø> (ø)
include/clad/Differentiator/DerivativeBuilder.h 100.00% <ø> (ø)
include/clad/Differentiator/ReverseModeVisitor.h 98.70% <ø> (ø)
...e/clad/Differentiator/ReverseModeForwPassVisitor.h 100.00% <100.00%> (ø)
lib/Differentiator/BaseForwardModeVisitor.cpp 98.71% <100.00%> (-0.01%) ⬇️
lib/Differentiator/DerivativeBuilder.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ForwardModeVisitor.cpp 99.06% <100.00%> (ø)
lib/Differentiator/HessianModeVisitor.cpp 99.46% <100.00%> (ø)
lib/Differentiator/ReverseModeForwPassVisitor.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ReverseModeVisitor.cpp 95.73% <100.00%> (+0.13%) ⬆️
... and 1 more

@parth-07
Copy link
Collaborator

@PhrygianGates Can you please debug and fix the failing debug checks?

@parth-07
Copy link
Collaborator

Is the pull request ready for review?

@PhrygianGates
Copy link
Contributor Author

@PhrygianGates Can you please debug and fix the failing debug checks?

I'm not sure as it seems to go wrong when installing something. I'll push again to see what happens.

@vgvassilev
Copy link
Owner

@PhrygianGates Can you please debug and fix the failing debug checks?

I'm not sure as it seems to go wrong when installing something. I'll push again to see what happens.

This fails elsewhere due to some server outage it seems. We can ignore this for now.

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

There were too many comments to post at once. Showing the first 10 out of 40. Check the log or trigger a new build to see more.

include/clad/Differentiator/ReverseModeForwPassVisitor.h Outdated Show resolved Hide resolved
#include "llvm/ADT/SmallVector.h"

namespace clad {
class ReverseModeForwPassVisitor : public ReverseModeVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: destructor of 'ReverseModeForwPassVisitor' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class ReverseModeForwPassVisitor : public ReverseModeVisitor {
      ^
Additional context

include/clad/Differentiator/ReverseModeForwPassVisitor.h:12: make it public and virtual

class ReverseModeForwPassVisitor : public ReverseModeVisitor {
      ^

Copy link
Owner

Choose a reason for hiding this comment

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

Likewise.

private:
Stmts m_Globals;

llvm::SmallVector<clang::QualType, 8>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

  llvm::SmallVector<clang::QualType, 8>
                                     ^

Copy link
Owner

Choose a reason for hiding this comment

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

We should be able to suppress these by adding IgnorePowersOf2IntegerValues=true in the clang-tidy config: https://clang.llvm.org/extra/clang-tidy/checks/readability/magic-numbers.html

llvm::SmallVector<clang::QualType, 8>
ComputeParamTypes(const DiffParams& diffParams);
clang::QualType ComputeReturnType();
llvm::SmallVector<clang::ParmVarDecl*, 8> BuildParams(DiffParams& diffParams);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

  llvm::SmallVector<clang::ParmVarDecl*, 8> BuildParams(DiffParams& diffParams);
                                         ^

@@ -22,6 +22,9 @@
#include "clad/Differentiator/HessianModeVisitor.h"
#include "clad/Differentiator/JacobianModeVisitor.h"
#include "clad/Differentiator/ReverseModeVisitor.h"
#include "clad/Differentiator/ReverseModeForwPassVisitor.h"

#include "clad/Differentiator/DiffPlanner.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: duplicate include [readability-duplicate-include]

lib/Differentiator/DerivativeBuilder.cpp:25:

- 
- #include "clad/Differentiator/DiffPlanner.h"

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved

llvm::SaveAndRestore<DeclContext*> saveContext(m_Sema.CurContext);
llvm::SaveAndRestore<Scope*> saveScope(m_CurScope);
m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]

  m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());
                      ^

m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: slicing object from type 'ReverseModeForwPassVisitor' to 'VisitorBase' discards 1096 bytes of state [cppcoreguidelines-slicing]

      m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
                                          ^

m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: slicing object from type 'ReverseModeForwPassVisitor' to 'VisitorBase' discards override 'VisitCompoundStmt' [cppcoreguidelines-slicing]

      m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
                                          ^

m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: slicing object from type 'ReverseModeForwPassVisitor' to 'VisitorBase' discards override 'VisitDeclRefExpr' [cppcoreguidelines-slicing]

      m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
                                          ^

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/DerivativeBuilder.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
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

There were too many comments to post at once. Showing the first 10 out of 31. Check the log or trigger a new build to see more.

lib/Differentiator/DerivativeBuilder.cpp Outdated Show resolved Hide resolved
m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: slicing object from type 'ReverseModeForwPassVisitor' to 'VisitorBase' discards override 'VisitReturnStmt' [cppcoreguidelines-slicing]

      m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
                                          ^

m_Sema.CurContext = const_cast<DeclContext*>(m_Function->getDeclContext());

DeclWithContext fnBuildRes =
m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: slicing object from type 'ReverseModeForwPassVisitor' to 'VisitorBase' discards override 'VisitStmt' [cppcoreguidelines-slicing]

      m_Builder.cloneFunction(m_Function, *this, m_Sema.CurContext, m_Sema,
                                          ^

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
@PhrygianGates PhrygianGates marked this pull request as ready for review August 11, 2023 13:17
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

There were too many comments to post at once. Showing the first 10 out of 21. Check the log or trigger a new build to see more.

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
return T;
}

llvm::SmallVector<clang::ParmVarDecl*, 8>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

llvm::SmallVector<clang::ParmVarDecl*, 8>
                                       ^

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved

llvm::SmallVector<clang::ParmVarDecl*, 8>
ReverseModeForwPassVisitor::BuildParams(DiffParams& diffParams) {
llvm::SmallVector<clang::ParmVarDecl*, 8> params, paramDerivatives;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

  llvm::SmallVector<clang::ParmVarDecl*, 8> params, paramDerivatives;
                                         ^

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
include/clad/Differentiator/ReverseModeForwPassVisitor.h Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
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

There were too many comments to post at once. Showing the first 10 out of 11. Check the log or trigger a new build to see more.

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
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


llvm::SmallVector<clang::ParmVarDecl*, 8>
ReverseModeForwPassVisitor::BuildParams(DiffParams& diffParams) {
llvm::SmallVector<clang::ParmVarDecl*, 8> params;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

  llvm::SmallVector<clang::ParmVarDecl*, 8> params;
                                         ^

llvm::SmallVector<clang::ParmVarDecl*, 8>
ReverseModeForwPassVisitor::BuildParams(DiffParams& diffParams) {
llvm::SmallVector<clang::ParmVarDecl*, 8> params;
llvm::SmallVector<clang::ParmVarDecl*, 8> paramDerivatives;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]

  llvm::SmallVector<clang::ParmVarDecl*, 8> paramDerivatives;
                                         ^

lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
@PhrygianGates PhrygianGates force-pushed the rev-ref-returns branch 2 times, most recently from e2b5e5f to d087419 Compare August 16, 2023 12:27
Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Most of the clang-tidy suggestions make sense. Could you incorporate them in the PR?

include/clad/Differentiator/ReverseModeForwPassVisitor.h Outdated Show resolved Hide resolved
#include "llvm/ADT/SmallVector.h"

namespace clad {
class ReverseModeForwPassVisitor : public ReverseModeVisitor {
Copy link
Owner

Choose a reason for hiding this comment

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

Likewise.

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

#define CLAD_COMPAT_CLANG11_LangOptions_EtraParams Ctx.getLangOpts()
#endif
#define CLAD_COMPAT_CLANG11_Ctx_ExtraParams Ctx,
#define CLAD_COMPAT_CREATE11(CLASS, CTORARGS) (CLASS::Create CTORARGS)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function-like macro 'CLAD_COMPAT_CREATE11' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]

#define CLAD_COMPAT_CREATE11(CLASS, CTORARGS) (CLASS::Create CTORARGS)
        ^

DiffInputVarsInfo m_DiffVarsInfo;
bool m_UsesEnzyme = false;

DerivedFnInfo() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use '= default' to define a trivial default constructor [modernize-use-equals-default]

Suggested change
DerivedFnInfo() {}
DerivedFnInfo() = default;

@vgvassilev vgvassilev force-pushed the rev-ref-returns branch 6 times, most recently from 0947893 to f3a7d33 Compare August 19, 2023 08:58
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

clang::SourceLocation& noLoc,
clang::DeclarationNameInfo name,
clang::QualType functionType) {
DeclWithContext DerivativeBuilder::cloneFunction(
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'cloneFunction' can be made static [readability-convert-member-functions-to-static]

include/clad/Differentiator/DerivativeBuilder.h:94:

-     DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
+     static DeclWithContext cloneFunction(const clang::FunctionDecl* FD,

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

@@ -93,7 +93,7 @@ namespace clad {
llvm::SmallVector<std::unique_ptr<ErrorEstimationHandler>, 4>
m_ErrorEstHandler;
DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'clad::DerivativeBuilder::cloneFunction' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]

    DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
                    ^
Additional context

lib/Differentiator/DerivativeBuilder.cpp:93: the definition seen here

  DeclWithContext DerivativeBuilder::cloneFunction(
                                     ^

include/clad/Differentiator/DerivativeBuilder.h:94: differing parameters are named here: ('VB'), in definition: ('VD')

    DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
                    ^

lib/Differentiator/DerivativeBuilder.cpp Outdated Show resolved Hide resolved
lib/Differentiator/DerivativeBuilder.cpp Outdated Show resolved Hide resolved
@vgvassilev vgvassilev force-pushed the rev-ref-returns branch 2 times, most recently from 89e33f9 to 0c0290e Compare August 22, 2023 13:42
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

@@ -427,7 +427,8 @@ static inline QualType getConstantArrayType(const ASTContext &Ctx,
#if CLANG_VERSION_MAJOR < 10
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) /**/
#elif CLANG_VERSION_MAJOR >= 10
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) ,((x)?VD.Clone((x)):nullptr)
#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x) \
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function-like macro 'CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]

#define CLAD_COMPAT_CLANG10_FunctionDecl_Create_ExtraParams(x)                 \
        ^

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
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

lib/Differentiator/ReverseModeForwPassVisitor.cpp Outdated Show resolved Hide resolved
@PhrygianGates PhrygianGates force-pushed the rev-ref-returns branch 2 times, most recently from 90e383d to a90bfc6 Compare August 28, 2023 13:46
Co-authored-by: Daemond <daemondzh@gmail.com>
Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

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.

3 participants