-
Notifications
You must be signed in to change notification settings - Fork 32
[Base] replace some instances of SourceLocation by std::source_location #1858
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()) { | ||
|
|
||
| __shamrock_stack_entry_with_callsite(callsite); | ||
|
|
||
|
|
@@ -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()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20, std::source_location callsite = std::source_location::current()) { |
||
|
|
||
| __shamrock_log_callsite(callsite); | ||
|
|
||
|
|
@@ -517,7 +517,7 @@ namespace sham { | |
| RefOut in_out, | ||
| u32 n, | ||
| Functor &&func, | ||
| SourceLocation &&callsite = SourceLocation{}) { | ||
| std::source_location &&callsite = std::source_location::current()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20, std::source_location callsite = std::source_location::current()) { |
||
|
|
||
| __shamrock_log_callsite(callsite); | ||
|
|
||
|
|
@@ -533,7 +533,7 @@ namespace sham { | |
| RefOut in_out, | ||
| u64 n, | ||
| Functor &&func, | ||
| SourceLocation &&callsite = SourceLocation{}) { | ||
| std::source_location &&callsite = std::source_location::current()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20, std::source_location callsite = std::source_location::current()) { |
||
|
|
||
| __shamrock_log_callsite(callsite); | ||
|
|
||
|
|
@@ -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()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20, std::source_location callsite = std::source_location::current()) { |
||
|
|
||
| __shamrock_log_callsite(callsite); | ||
|
|
||
|
|
@@ -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()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20, std::source_location callsite = std::source_location::current()) { |
||
|
|
||
| __shamrock_log_callsite(callsite); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20,
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // This class is not safe if copied or moved | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| CallStackEntry(const CallStackEntry &) = delete; | ||||||||||||||||||||||
|
|
@@ -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) { | ||||||||||||||||||||||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++20,
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * @brief Destroy the Basic Stack Entry object. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C++20,
std::source_locationis 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 lvaluestd::source_locationobjects and adds unnecessary indirection. It should be passed by value instead.