Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/shambackends/include/shambackends/kernel_call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ namespace sham {
RefOut in_out,
index_t n,
Functor &&kernel_gen,
SourceLocation &&callsite = SourceLocation{}) {
std::source_location &&callsite = std::source_location::current()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object (typically consisting of a couple of pointers and integers). Passing it by rvalue reference (std::source_location&&) is an anti-pattern that prevents passing lvalue std::source_location objects and adds unnecessary indirection. It should be passed by value instead.

            std::source_location callsite = std::source_location::current()) {


__shamrock_stack_entry_with_callsite(callsite);

Expand Down Expand Up @@ -324,7 +324,7 @@ namespace sham {
RefOut in_out,
index_t n,
Functor &&func,
SourceLocation &&callsite = SourceLocation{}) {
std::source_location &&callsite = std::source_location::current()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by rvalue reference (std::source_location&&) is an anti-pattern that prevents passing lvalue std::source_location objects and adds unnecessary indirection. It should be passed by value instead.

            std::source_location callsite = std::source_location::current()) {


__shamrock_log_callsite(callsite);

Expand Down Expand Up @@ -517,7 +517,7 @@ namespace sham {
RefOut in_out,
u32 n,
Functor &&func,
SourceLocation &&callsite = SourceLocation{}) {
std::source_location &&callsite = std::source_location::current()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by rvalue reference (std::source_location&&) is an anti-pattern that prevents passing lvalue std::source_location objects and adds unnecessary indirection. It should be passed by value instead.

        std::source_location callsite = std::source_location::current()) {


__shamrock_log_callsite(callsite);

Expand All @@ -533,7 +533,7 @@ namespace sham {
RefOut in_out,
u64 n,
Functor &&func,
SourceLocation &&callsite = SourceLocation{}) {
std::source_location &&callsite = std::source_location::current()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by rvalue reference (std::source_location&&) is an anti-pattern that prevents passing lvalue std::source_location objects and adds unnecessary indirection. It should be passed by value instead.

        std::source_location callsite = std::source_location::current()) {


__shamrock_log_callsite(callsite);

Expand All @@ -549,7 +549,7 @@ namespace sham {
RefOut in_out,
u32 n,
Functor &&kernel_gen,
SourceLocation &&callsite = SourceLocation{}) {
std::source_location &&callsite = std::source_location::current()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by rvalue reference (std::source_location&&) is an anti-pattern that prevents passing lvalue std::source_location objects and adds unnecessary indirection. It should be passed by value instead.

        std::source_location callsite = std::source_location::current()) {


__shamrock_log_callsite(callsite);

Expand All @@ -565,7 +565,7 @@ namespace sham {
RefOut in_out,
u64 n,
Functor &&kernel_gen,
SourceLocation &&callsite = SourceLocation{}) {
std::source_location &&callsite = std::source_location::current()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by rvalue reference (std::source_location&&) is an anti-pattern that prevents passing lvalue std::source_location objects and adds unnecessary indirection. It should be passed by value instead.

        std::source_location callsite = std::source_location::current()) {


__shamrock_log_callsite(callsite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace sham {
"kern call",
"called DDMultiRef.get, id =",
id,
SourceLocation{}.format_one_line_func());
shambase::format_one_line_func(std::source_location::current()));
return std::apply(
[id](auto &...args) {
return sham::MultiRef{args.get(id)...};
Expand Down
17 changes: 15 additions & 2 deletions src/shambase/include/shambase/stacktrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ namespace shambase::details {

/// Helper class to manage the call stack entry
struct CallStackEntry {
inline CallStackEntry(SourceLocation &loc) {
inline CallStackEntry(const SourceLocation &loc) {
// Push the source location to the call stack
call_stack.emplace(loc);
}

inline CallStackEntry(const std::source_location &loc) {
// Push the source location to the call stack
call_stack.emplace(SourceLocation{loc});
}
Comment on lines +93 to +96

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by const std::source_location& is less efficient than passing by value because it introduces pointer indirection. It should be passed by value instead.

Suggested change
inline CallStackEntry(const std::source_location &loc) {
// Push the source location to the call stack
call_stack.emplace(SourceLocation{loc});
}
inline CallStackEntry(std::source_location loc) {
// Push the source location to the call stack
call_stack.emplace(SourceLocation{loc});
}


// This class is not safe if copied or moved

CallStackEntry(const CallStackEntry &) = delete;
Expand Down Expand Up @@ -138,7 +143,9 @@ namespace shambase::details {
* @param loc Source location attached to the entry (default: SourceLocation{})
*/
inline BasicStackEntry(
SourceLocation &callsite, bool do_timer = true, SourceLocation &&loc = SourceLocation{})
const SourceLocation &callsite,
bool do_timer = true,
SourceLocation &&loc = SourceLocation{})
: loc(loc), do_timer(do_timer), scoped_callstack_entry(callsite) {
#ifdef SHAMROCK_USE_PROFILING
if (do_timer) {
Expand All @@ -150,6 +157,12 @@ namespace shambase::details {
#endif
}

inline BasicStackEntry(
const std::source_location &callsite,
bool do_timer = true,
std::source_location &&loc = std::source_location::current())
: BasicStackEntry(SourceLocation{callsite}, do_timer, SourceLocation{loc}) {}
Comment on lines +160 to +164

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In C++20, std::source_location is a small, trivially copyable object. Passing it by reference (const std::source_location& or std::source_location&&) is less efficient and can prevent passing lvalue objects. It should be passed by value instead.

Suggested change
inline BasicStackEntry(
const std::source_location &callsite,
bool do_timer = true,
std::source_location &&loc = std::source_location::current())
: BasicStackEntry(SourceLocation{callsite}, do_timer, SourceLocation{loc}) {}
inline BasicStackEntry(
std::source_location callsite,
bool do_timer = true,
std::source_location loc = std::source_location::current())
: BasicStackEntry(SourceLocation{callsite}, do_timer, SourceLocation{loc}) {}


/**
* @brief Destroy the Basic Stack Entry object.
*
Expand Down
19 changes: 10 additions & 9 deletions src/shamtest/shamtest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ namespace shamtest::details {
shamtest::asserts().assert_bool_with_log( \
assert_name, \
eval, \
STDSTRINGIFY(a) + " evaluated to false\n\n" \
+ " -> location : " + SourceLocation{}.format_one_line()); \
STDSTRINGIFY(a) + " evaluated to false\n\n" + " -> location : " \
+ shambase::format_one_line(std::source_location::current())); \
} \
} while (0)

Expand Down Expand Up @@ -232,8 +232,8 @@ namespace shamtest::details {
eval, \
assert_name + " evaluated to false\n\n" + " -> " #_a \
+ shambase::format(" = {}", _______a) + "\n" + " -> " #_b \
+ shambase::format(" = {}", _______b) + "\n" \
+ " -> location : " + SourceLocation{}.format_one_line()); \
+ shambase::format(" = {}", _______b) + "\n" + " -> location : " \
+ shambase::format_one_line(std::source_location::current())); \
} \
} while (0)

Expand Down Expand Up @@ -276,8 +276,8 @@ namespace shamtest::details {
eval, \
assert_name + " evaluated to false\n\n" + shambase::format(" -> " #_a " = {}", a) \
+ "\n" + shambase::format(" -> " #_b " = {}", b) + "\n" \
+ shambase::format(" -> " #prec " = {}", prec) + "\n" \
+ " -> location : " + SourceLocation{}.format_one_line()); \
+ shambase::format(" -> " #prec " = {}", prec) + "\n" + " -> location : " \
+ shambase::format_one_line(std::source_location::current())); \
} \
} while (0)

Expand Down Expand Up @@ -368,7 +368,7 @@ namespace shamtest::details {
false, \
"Expected throw of type " #exception_type ", but nothing was thrown\n" \
" -> location : " \
+ SourceLocation{}.format_one_line()); \
+ shambase::format_one_line(std::source_location::current())); \
} catch (const exception_type &ex) { \
/* If wanted exception is thrown, assert that the test pass */ \
shamtest::asserts().assert_bool_with_log( \
Expand All @@ -379,14 +379,15 @@ namespace shamtest::details {
#exception_type " was not thrown", \
false, \
"Expected throw of type " #exception_type ", but got " + std::string(e.what()) \
+ "\n" + " -> location : " + SourceLocation{}.format_one_line()); \
+ "\n" + " -> location : " \
+ shambase::format_one_line(std::source_location::current())); \
} catch (...) { \
/* If an unknown exception is thrown, assert that the test failed */ \
shamtest::asserts().assert_bool_with_log( \
#exception_type " was not thrown", \
false, \
"Expected throw of type " #exception_type ", but got unknown exception\n" \
" -> location : " \
+ SourceLocation{}.format_one_line()); \
+ shambase::format_one_line(std::source_location::current())); \
} \
} while (0)
Loading