This is an archive of the discontinued LLVM Phabricator instance.

Convert CheckICE into a statment visitor
AbandonedPublic

Authored by void on Nov 9 2018, 2:15 PM.

Details

Reviewers
rsmith
shafik
Summary

This cleans up the code somewhat and allows us conditionally to act on
different types of nodes depending on their context. E.g., if we're
checking for an ICE in a constant context.

Diff Detail

Event Timeline

void created this revision.Nov 9 2018, 2:15 PM

Can you explain more about the justification for this? The code today has a covered switch, which is useful for maintainability -- anyone adding a new Expr node gets told they need to think about and update this code. Are there any cases where we check for an ICE and aren't in a constant context? I would have expected that the fact we're asking implies that we are in a constant context (at least when the answer is "yes").

void added a comment.Nov 13 2018, 12:40 PM

This code is called in over 90 places, so it's hard to tell if they all are in a constant context. Though I suppose that what this code is supposed to check for would work the same in a constant context as without one. I can revert this if you want, but to be honest the original function was terrible--it's huge and hard to understand what's going on. As for adding new expressions, this isn't the only place where a StmtVisitor is used. One still needs to go through all of those visitors to see if they need to add their expression.

Can you explain more about the justification for this? The code today has a covered switch, which is useful for maintainability -- anyone adding a new Expr node gets told they need to think about and update this code. Are there any cases where we check for an ICE and aren't in a constant context? I would have expected that the fact we're asking implies that we are in a constant context (at least when the answer is "yes").

Oh, I see, you want to temporarily set "IsConstantContext" to true while evaluating the subexpression of a ConstantExpr. I think that's unnecessary, because anywhere we ask "is this syntactically an ICE?", we always want to evaluate as if in a constant context (unlike places where we run the evaluator on an expression, where that doesn't necessarily imply anything in particular about the nature of the expression.)

void added a comment.Nov 13 2018, 12:54 PM

Okay. I'll revert this then.

rsmith accepted this revision.Nov 13 2018, 12:59 PM

This code is called in over 90 places, so it's hard to tell if they all are in a constant context. Though I suppose that what this code is supposed to check for would work the same in a constant context as without one. I can revert this if you want, but to be honest the original function was terrible--it's huge and hard to understand what's going on. As for adding new expressions, this isn't the only place where a StmtVisitor is used. One still needs to go through all of those visitors to see if they need to add their expression.

Thinking about this some more: in the case where adding a new Stmt node without considering this code is likely to result in a silent and initially-unnoticed bug, I think it's useful to use one of our covered-switch-like patterns. But I don't think this actually is such a case; the C ICE rules are pretty conservative in what they allow, and new Stmt nodes should nearly always be treated as non-ICE. Thank you!

This revision is now accepted and ready to land.Nov 13 2018, 12:59 PM

Okay. I'll revert this then.

I don't think we necessarily need the change in the other patch that's based on this one, but I still think this refactoring is an improvement :)

void abandoned this revision.Nov 13 2018, 1:02 PM

This isn't necessary. We can assume it's in a constant context because it's checking for an ICE.

void added a comment.Nov 13 2018, 1:06 PM

Okay. I'll revert this then.

I don't think we necessarily need the change in the other patch that's based on this one, but I still think this refactoring is an improvement :)

Thanks. I can resurrect this after these changes go in. This will keep the resulting changes small. :-)