Skip to content

Add slic macros that log once per call site#1831

Merged
bmhan12 merged 22 commits intodevelopfrom
feature/han12/slic_once
Apr 2, 2026
Merged

Add slic macros that log once per call site#1831
bmhan12 merged 22 commits intodevelopfrom
feature/han12/slic_once

Conversation

@bmhan12
Copy link
Copy Markdown
Contributor

@bmhan12 bmhan12 commented Mar 26, 2026

This PR:

  • Adds suffixed SLIC_*_ONCE macros that are invoked once per call site.

Addresses #1685

@bmhan12 bmhan12 added the Slic Issues related to Axom's 'slic' component label Mar 26, 2026
Comment on lines +885 to +897
#define SLIC_DETAIL_LOG_IF_ONCE(macro, EXP, msg) \
do \
{ \
static bool once = true; \
if(EXP) \
{ \
if(once) \
{ \
macro(true, msg); \
once = false; \
} \
} \
} while(axom::slic::detail::false_value)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Helper macro that the SLIC_*_ONCE macros use.

Comment on lines +150 to +151
// Convenience test macro that checks slic macro has logged a message
#define EXPECT_SLIC_LOG(macro_call, level, message) \
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Convenience macro for testing, mainly to alleviate the tracking of __LINE__ in the original tests. It works pretty well for gcc, except...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use std::source_location when we move to c++20 --- https://en.cppreference.com/w/cpp/utility/source_location.html

Comment on lines +185 to +188
// Single line - Placement of ")" matters for __LINE__ for slic call and checking
// clang-format off
EXPECT_SLIC_LOG(SLIC_ERROR_IF(true, "this message is logged!"), "ERROR", "this message is logged!");
// clang-format on
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

... clang and intel compilers have different __LINE__ behavior, I need to disable formatting here to keep the entire call to one line.
Otherwise, the observed behavior for example is something like:

  EXPECT_SLIC_LOG(
    SLIC_ERROR_IF(true, "this message is logged!"), // <-- This is the line number that is logged
    "ERROR", 
    "this message is logged!"); // <-- This is the line number the macro is checking for

The line number as far as I can tell in both instances is actually determined by the line placement of the closing parantheses ")".

Another example for future reference:

  EXPECT_SLIC_LOG(SLIC_ERROR_ROOT_IF(true,
    "this message is logged!"


    ), // <-- This is the line number that is logged
                  "ERROR",
                  "this message is logged!"
                  ); // <-- This is the line number the macro is checking for

Copy link
Copy Markdown
Member

@kennyweiss kennyweiss left a comment

Choose a reason for hiding this comment

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

Thanks for adding this @bmhan12

  • Please reintroduce the do { } while() to the macros
  • Let's ensure that we have the right semantics for SLIC_*_IF_ONCE( false )

Comment on lines +889 to +896
if(EXP) \
{ \
if(once) \
{ \
macro(true, msg); \
once = false; \
} \
} \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gut check -- this can call the macro multiple times, until EXP evaluates as true.
Is this the semantics we're looking for? Or should it only call the the macro once, independent of whether EXP is true/false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this can call the macro multiple times, until EXP evaluates as true.

I think this is the behavior we want, and is what was in the original #1683 snippet.

A once-only if-check I think would be false and print nothing most of the time, unless you knew the true condition ahead of time to guarantee the first invocation prints, in which case, your SLIC_*_IF_ONCE usage is more like SLIC_*_ONCE .

Comment on lines +150 to +151
// Convenience test macro that checks slic macro has logged a message
#define EXPECT_SLIC_LOG(macro_call, level, message) \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use std::source_location when we move to c++20 --- https://en.cppreference.com/w/cpp/utility/source_location.html

Copy link
Copy Markdown
Contributor

@Arlie-Capps Arlie-Capps left a comment

Choose a reason for hiding this comment

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

Thanks for your careful work, @bmhan12 .

| | ``SLIC_WARNING_ROOT`` | | | | No longer collective after calling ``slic::disableAbortOnWarning()`` |
| | ``SLIC_WARNING_ROOT_IF`` | | | | |
+----------------------------+------------------------------------------------+----------------------------------------------------------------------------+
.. list-table:: SLIC macro availability and collective behavior
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bmhan12 thank you for this. Much better way to make a table in sphinx -- avoid lining up all the characters across rows and columns 🥇

@bmhan12 bmhan12 merged commit be2a0b4 into develop Apr 2, 2026
15 checks passed
@bmhan12 bmhan12 deleted the feature/han12/slic_once branch April 2, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Slic Issues related to Axom's 'slic' component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants