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

Call PassManager's debug hook even after a failing pass #4626

Merged
merged 3 commits into from
Apr 18, 2024

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Apr 17, 2024

breaking change: Debug hooks in PassManager can now be called with the IR::Node being nullptr. This indicates that the last executed pass failed and did not return any value.

This allows running a debug hook also after a failing pass too. This can be useful e.g. to check diagnostic counts for the pass in the debug hook.

@vlstill vlstill added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Apr 17, 2024
@vlstill vlstill requested a review from fruffy April 17, 2024 19:35
@vlstill vlstill self-assigned this Apr 17, 2024
if (node) {
node->apply(toP4);
} else {
*stream << "No P4 program returned by the pass" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this only happens when there is an error right? I would clarify this in the message.

if (stop_on_error && ::errorCount() > initial_error_count) break;
if ((program = after) == nullptr) break;
if (stop_on_error && ::errorCount() > initial_error_count) early_exit_flag = true;
if ((program = after) == nullptr) early_exit_flag = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does it mean when (program = after) == nullptr? Unclear to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is C/C++'s fun "you can embed assignment statements inside of expressions" thing, semantically equivalent to doing:

program = after;
if (program == nullptr) early_exit_flag = true;

Or maybe I don't understand your question.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yes, it was more meant as a clarification question under which circumstances the after is nullptr.
But that expression should also be simplified while we are at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least the Transform's code suggests it is possible to return nullptr in the pre/postorder and if you do that for root the entire apply would yield nullptr. This would be quite weird I guess, but it is allowed.

I've pushed a commit that eliminates the after variable altogether.

@vlstill vlstill requested a review from fruffy April 18, 2024 12:31
Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

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

Approving, although I can not say for sure there won't be any unintended side-effects.

@vlstill
Copy link
Contributor Author

vlstill commented Apr 18, 2024

Approving, although I can not say for sure there won't be any unintended side-effects.

One effect I can see is that the compiler will attempt to dump P4 also form the pass that triggered an error. That would of course happen only if dumping is enabled, so in develompment. The rest will depend on the debug hooks used by downstream projects, which is hard to know... If this turns out to be problematic, the hook can always check ::errorCount().

@vlstill vlstill added this pull request to the merge queue Apr 18, 2024
Merged via the queue into main with commit 8dd9578 Apr 18, 2024
17 checks passed
@vlstill vlstill deleted the vstill/debug-hook-failing-pass branch April 18, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants