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

Refactor StringifyTypeExpr #4597

Merged
merged 6 commits into from
Nov 27, 2024
Merged

Refactor StringifyTypeExpr #4597

merged 6 commits into from
Nov 27, 2024

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Nov 27, 2024

  • 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.

Copy link
Contributor

@zygoloid zygoloid left a 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.

struct Step {
// The instruction's file.
const File& sem_ir;
class StepStack {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

step_stack.PushString("]");
step_stack.PushArrayBound(inst.bound_id);
step_stack.PushString("; ");
step_stack.PushInstId(sem_ir.types().GetInstId(inst.element_type_id));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@josh11b josh11b removed the request for review from geoffromer November 27, 2024 02:02
@josh11b josh11b enabled auto-merge November 27, 2024 02:07
@josh11b josh11b disabled auto-merge November 27, 2024 02:07
@josh11b josh11b enabled auto-merge November 27, 2024 02:09
@josh11b josh11b disabled auto-merge November 27, 2024 02:12
@josh11b
Copy link
Contributor Author

josh11b commented Nov 27, 2024

FYI, I did some small cleanups to the StepStack class.

@josh11b josh11b enabled auto-merge November 27, 2024 02:14
@josh11b josh11b added this pull request to the merge queue Nov 27, 2024
Merged via the queue into carbon-language:trunk with commit b894d4e Nov 27, 2024
8 checks passed
@josh11b josh11b deleted the stringify branch November 27, 2024 02:29
Copy link
Contributor

@danakj danakj left a 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 :)

bricknerb pushed a commit to bricknerb/carbon-lang that referenced this pull request Nov 28, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants