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

Move checks in CladFunction to compile-time #1090

Merged
merged 3 commits into from
Sep 29, 2024

Conversation

MihailMihov
Copy link
Collaborator

No description provided.

@MihailMihov MihailMihov force-pushed the clad-function-constexpr branch from 5f143db to c15ec08 Compare September 11, 2024 22:51
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

}
: m_Function(f), m_Functor(functor), m_CUDAkernel(CUDAkernel) {
#ifndef __CLAD_SO_LOADED
static_assert(false, "clad doesn't appear to be loaded; make sure that "
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: static assertion failed: clad doesn't appear to be loaded; make sure that you pass clad.so to clang. [clang-diagnostic-error]

      static_assert(false, "clad doesn't appear to be loaded; make sure that "
      ^

#endif

size_t length = GetLength(code);
char* temp = (char*)malloc(length + 1);
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 manage memory manually; consider a container or a smart pointer [cppcoreguidelines-no-malloc]

      char* temp = (char*)malloc(length + 1);
                          ^

#endif

size_t length = GetLength(code);
char* temp = (char*)malloc(length + 1);
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 C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

      char* temp = (char*)malloc(length + 1);
                   ^

#endif

size_t length = GetLength(code);
char* temp = (char*)malloc(length + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: initializing non-owner 'char *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

      char* temp = (char*)malloc(length + 1);
      ^

size_t length = GetLength(code);
char* temp = (char*)malloc(length + 1);
m_Code = temp;
while ((*temp++ = *code++))
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 pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

      while ((*temp++ = *code++))
                             ^

size_t length = GetLength(code);
char* temp = (char*)malloc(length + 1);
m_Code = temp;
while ((*temp++ = *code++))
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 pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

      while ((*temp++ = *code++))
                   ^

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.28%. Comparing base (e2b8e35) to head (efa67b3).
Report is 5 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1090      +/-   ##
==========================================
+ Coverage   94.26%   94.28%   +0.02%     
==========================================
  Files          55       55              
  Lines        8445     8441       -4     
==========================================
- Hits         7961     7959       -2     
+ Misses        484      482       -2     
Files with missing lines Coverage Δ
include/clad/Differentiator/Differentiator.h 86.11% <100.00%> (+6.11%) ⬆️
tools/ClangPlugin.cpp 95.62% <100.00%> (+0.04%) ⬆️

... and 2 files with indirect coverage changes

Files with missing lines Coverage Δ
include/clad/Differentiator/Differentiator.h 86.11% <100.00%> (+6.11%) ⬆️
tools/ClangPlugin.cpp 95.62% <100.00%> (+0.04%) ⬆️

... and 2 files with indirect coverage changes

@vgvassilev vgvassilev force-pushed the clad-function-constexpr branch from 1b944d2 to d7a3d63 Compare September 18, 2024 14:22
@MihailMihov MihailMihov force-pushed the clad-function-constexpr branch 2 times, most recently from 8484807 to af905d1 Compare September 18, 2024 15:42
@vgvassilev vgvassilev force-pushed the clad-function-constexpr branch from af905d1 to cc3518e Compare September 18, 2024 17:17
@@ -0,0 +1,58 @@
// RUN: %cladclang %s -I%S/../../include -std=c++23 -oConstevalTest.out | %filecheck %s
// RUN: ./ConstevalTest.out | %filecheck_exec %s
// XFAIL: *
Copy link
Owner

Choose a reason for hiding this comment

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

Why the tests are marked with XFAIL? Can we make a test that makes sure this does not regress again into some runtime evaluation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changes that would allow constexpr/consteval are not in this pr so I disabled them and we can enable them in that pr, or should I remove them from here?

Copy link
Owner

Choose a reason for hiding this comment

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

In that case we should not add the tests as part of this pr.

@MihailMihov MihailMihov force-pushed the clad-function-constexpr branch from cc3518e to e86a47d Compare September 23, 2024 07:36
@MihailMihov MihailMihov marked this pull request as ready for review September 28, 2024 14:37
@MihailMihov MihailMihov force-pushed the clad-function-constexpr branch from e86a47d to 710b779 Compare September 28, 2024 14:38
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!

@@ -90,6 +90,12 @@ namespace clad {
CGOpts.PassPlugins.push_back(CladSoPath.str());
}
#endif // CLANG_VERSION_MAJOR > 8

// Add define for CLAD_SO_LOADED, so that CladFunction::CladFunction()
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
// Add define for CLAD_SO_LOADED, so that CladFunction::CladFunction()
// Add define for __CLAD_SO_LOADED, so that CladFunction::CladFunction()

Copy link
Owner

Choose a reason for hiding this comment

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

Can you make that change and put it in the right place in the commit history.

These asserts will only assert if clad has malfunctioned, which won't fix
anything. Also there isn't a way to keep them while making the
methods constexpr.
@MihailMihov MihailMihov force-pushed the clad-function-constexpr branch from 710b779 to efa67b3 Compare September 29, 2024 13:41
@vgvassilev vgvassilev merged commit 821683f into vgvassilev:master Sep 29, 2024
90 checks passed
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