Skip to content

Add environment var as input for SSA CFG debug log level#16581

Draft
matheusaaguiar wants to merge 10 commits intodevelopfrom
ssa-cfg-debug-stdout-logging-env-var
Draft

Add environment var as input for SSA CFG debug log level#16581
matheusaaguiar wants to merge 10 commits intodevelopfrom
ssa-cfg-debug-stdout-logging-env-var

Conversation

@matheusaaguiar
Copy link
Copy Markdown
Contributor

No description provided.

@matheusaaguiar matheusaaguiar requested a review from clonker April 7, 2026 12:43
m_options.logLevel = *level;
}
// Check if env VAR is defined
else if(char const* levelValue = std::getenv("SOLC_LOG_LEVEL"))
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.

Just curious - why an environment variable instead of doing this via cmake? Are we planning for this to be available to the end users as well (although in that case an actual CLI option would make more sense)?

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.

Leaving this here for context: #16540 (comment)

TLDR if we do it via cmake and macro it's super easy to get drift. Compiling it in allows us to simply turn it on if we need it on any version if there's a problem somewhere. With the forced no-inline I think we have performance that is close to having it compiled out, so why not leave it in :)
As for cli arg vs environment var: Since the thing should be configurable down to components and individual levels, it's not entirely trivial (although Daniel might say so) and I'm sure Kamil has opinions on it. So env var seemed like the easiest for now to enable it for ssa cfg where it's currently needed.

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.

Sure, makes sense.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So env var seemed like the easiest for now to enable it for ssa cfg where it's currently needed.

You already have both here though. I'm not sure we really need the var. It's just a sneaky way to introduce a global without declaring one :) A bit pointless if you need a singleton for the registry anyway.

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.

thanks, I am acutely aware that we have both here :) not so sure about sneaky or not, it seemed to me there is some discussion to be had about having a proper cli concept for logging. to sidestep that for the time being, an environment variable could be used. or making the cli experimental. or just a bool flag somewhere in the code. or a cmake option. i don't care what it is in the end as long as it enables me to get some logging output if needed.

@matheusaaguiar matheusaaguiar force-pushed the ssa-cfg-debug-stdout-logging-env-var branch from b8e744b to 55a795d Compare April 8, 2026 01:14
bool matched = false;
for (auto const& [prefix, level] : presets) {
if (prefix.empty() || name == prefix || name.starts_with(prefix + ".")) {
if (!matched || prefix.size() >= best_match) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Coding style error

@matheusaaguiar matheusaaguiar changed the base branch from ssa-cfg-debug-stdout-logging to develop April 8, 2026 01:17
@matheusaaguiar matheusaaguiar force-pushed the ssa-cfg-debug-stdout-logging-env-var branch from 55a795d to e7e1338 Compare April 8, 2026 18:12
m_options = parser.options();

if (m_options.logLevel)
Registry::instance().set_level("", *m_options.logLevel);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Registry of what? Why doesn't it have a more descriptive name?

Copy link
Copy Markdown
Member

@clonker clonker Apr 9, 2026

Choose a reason for hiding this comment

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

because it's a draft. but yeah, should def be changed.

solThrow(
CommandLineValidationError,
"Invalid option for --" + g_strLogLevel + ": " + levelStr +
". Valid options: trace, debug, info, warn, error, off."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There should be some way to get a list of those to avoid hard-coding them in multiple places.

Copy link
Copy Markdown
Member

@clonker clonker Apr 9, 2026

Choose a reason for hiding this comment

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

agreed.


m_options.formatting.withErrorIds = m_args.count(g_strErrorIds);

if (m_args.contains(g_strLogLevel))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be processed way earlier. The values of some the options might actually be something we might want to log at some point.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's lot of stuff here that does not follow our style. Is it copied from somewhere?

  • Braces not on a new line
  • Abbreviated or even single-letter variable names
  • No _ prefix in function parameters
  • Whole enums squished into a single line
  • Function names with underscores rather than camel case
  • The file name starts with a lowercase letter (logging.cpp)
  • Tons of auto even where using the type directly is straightforward
  • No SPDX comment (or copyright boilerplace, though TBH I'd be glad to get rid of it at some point)

Copy link
Copy Markdown
Member

@clonker clonker Apr 9, 2026

Choose a reason for hiding this comment

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

do you think it is productive to drive-by review this PR at that level especially considering in the state it is in right now? while it is being in draft and clearly not in a finalized state?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, but SSA CFG-related PRs tend to get merged very quickly, sometimes before I manage to even take a look at them so I learned that I have to act fast and leave a comment if something catches my eye. This bit wasn't my focus here, but it stood out and it wasn't very clear to me how close to completion this PR really was as I only skimmed through parts of it and it has no description (is it a normal initial version or just a messy final version?) so I decided it's better to comment on it regardless. Note that I intentionally wrapped it into a single comment rather than flood you with comments on every individual thing.

Comment on lines +41 to +45
solidity::Logger const& log()
{
static solidity::Logger const& instance = solidity::Registry::instance().get("yul.ssa.stacklayout");
return instance;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we should have a macro for automatically declaring something like this?

DEFINE_LOGGER(log, "yul.ssa.stacklayout");

This is something that we'll be doing in almost every file eventually, so it would be best to be able to do this without much boilerplate.

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.

Right. Or a static helper function. I am not particularly fond of macros and try to avoid them if possible. :)

Comment on lines +133 to +135
log().debug("--------------------\n");
log().debug("Running SSA CFG code transform\n");
log().debug("--------------------\n");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that a newline at the end should be the default. We'll want it in the vast majority of cases. For those few were we don't we could have a parameter to disable it or even just an alternative function.

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.

yes I agree and this code is still extremely messy and not cleaned up. we should also add prefixes to the logs. perhaps ansi colors if we want to be fancy. but why don't we follow an incremental approach. default-adding newline at the end seems like a good thing to have for the initial draft though.

Copy link
Copy Markdown
Collaborator

@cameel cameel Apr 9, 2026

Choose a reason for hiding this comment

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

Sorry for jumping into it already. I did not realize how early of a draft this is meant to be. My bad.

Incremental approach is fine as long as it's clear it's incremental. What I'm really missing here is at least a short comment in the description about the intended scope and current status of this.

But overall I would have really preferred if this started with an issue or a design note so that the higher-level details can be hashed out separately from the implementation. There are things we can easily agree on at that level without being distracted by the unfinished details. Starting with the code actually always makes me more anxious because I know I have to fish out the things I care about from the PR and I have to be constantly on guard not to miss them. IMO incremental should mean that we create at least a rough design and implement it one step at a time, not that we incrementally design and implement as we go. The latter does not lead to a smooth review.

Copy link
Copy Markdown
Member

@clonker clonker Apr 9, 2026

Choose a reason for hiding this comment

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

No worries at all and I'm sorry you were at the receiving end of my venty replies. A description to the PR really would have helped. We ought to do better there.
Regarding design discussion, I thought we were in agreement on how it should look like - at least roughly - when you brought up logging here #16540 (comment). If you think it helps we can set up an issue or so to track progress and discuss it more :)

Copy link
Copy Markdown
Collaborator

@cameel cameel Apr 9, 2026

Choose a reason for hiding this comment

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

If you think it helps we can set up an issue or so to track progress and discuss it more :)

What I'd really like to have is a separate artifact that constrains the implementation, describing what we're trying to achieve, why and the high-level decisions, like interfaces, backwards-compatibility, general structure. It could be an issue, but I feel that these usually encourage thinking about steps or tasks to be checked off, while what I'd prefer to end up with is more like a spec or docs.

That discussion we had is a good basis for that, but it lacked details I'd expect to see in such a design note (e.g. the specific logging levels, how we're changing the CLI/Standard JSON or how we'll make logging macros/functions ergonomic). I could have continued it, but it already felt like it was too detailed for a comment thread tucked away in a PR :) It's hard to iterate on it in that format.

Copy link
Copy Markdown
Collaborator

@cameel cameel Apr 9, 2026

Choose a reason for hiding this comment

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

Now that I think of it, maybe some day we could just feed these notes to an LLM and get an automatic review of the implementation based on that :)

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.

Hehe. As long as it's not a mandatory quality gate and we have to bow to our AI overlords. :D

@argotorg argotorg deleted a comment from stackenbotten3000 Apr 10, 2026
@argotorg argotorg deleted a comment from stackenbotten3000 Apr 10, 2026
@argotorg argotorg deleted a comment from stackenbotten3000 Apr 10, 2026
@argotorg argotorg deleted a comment from stackenbotten3000 Apr 10, 2026
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.

5 participants