-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Refactor StringifyTypeExpr
#4597
Conversation
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.
Looks good to me. A couple of comments but neither of them needs to be addressed in this PR.
toolchain/sem_ir/stringify_type.cpp
Outdated
struct Step { | ||
// The instruction's file. | ||
const File& sem_ir; | ||
class StepStack { |
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.
Would it make sense to move this out of the function? That might enable more refactoring, such as splitting this function into smaller functions, at a later stage.
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.
Possibly, though that seems out of scope for this PR.
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.
Oh I hadn't realized how little else was going on in this file. I've moved it out into an anonymous namespace.
toolchain/sem_ir/stringify_type.cpp
Outdated
step_stack.PushString("]"); | ||
step_stack.PushArrayBound(inst.bound_id); | ||
step_stack.PushString("; "); | ||
step_stack.PushInstId(sem_ir.types().GetInstId(inst.element_type_id)); |
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.
We seem to be doing this a lot; maybe we should add a PushTypeId
for this.
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.
Done.
FYI, I did some small cleanups to the |
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.
This is nice, thank you :)
* Make the step stack into a class * Make the operations on the stack (pushing, popping, test for done) into methods on the stack class. * Add more kinds of steps (array bound and name). * Rewrite cases to use the new kinds of steps. Afterward, none use `Step::Next()` or the step index, so those get removed. * Add another convenience method `PushTypeId`. * Remove the `SemIR::File&` member from the steps, since it doesn't change. Hopefully using `step_stack.Push`... calls makes it clear that they are resolved in the reverse order they are executed. --------- Co-authored-by: Josh L <[email protected]>
Step::Next()
or the step index, so those get removed.PushTypeId
.SemIR::File&
member from the steps, since it doesn't change.Hopefully using
step_stack.Push
... calls makes it clear that they are resolved in the reverse order they are executed.