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

Simplify logic in StringifyTypeExpr using push_string #4561

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Nov 21, 2024

Follow-on to #4511.

out << ">";
}
out << "<associated ";
push_string(">");
Copy link
Contributor

Choose a reason for hiding this comment

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

I was able to infer from reading that these push statements are executed in reverse order (FILO), though I was confused for a minute :) Do you think we could add a comment on push_string and push_inst_id saying so to help future readers?

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 have been enough if steps were named steps_stack, to emphasize the stack behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, something in the name calling out would be nice as an alternative

Copy link
Contributor

Choose a reason for hiding this comment

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

Though I suppose that would have mostly helped in this diff from seeing it in the deleted lines. It doesn't appear really in the text otherwise as it's being bound into the lambdas, but it would be found when reading the lambdas (in place of a comment on them), which would indeed be better than having to reverse engineer it a bit more. Anything helps :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talked about this with @zygoloid , and he suggested we could make push_string, push_inst_id, and push_specific_id into methods on a "work stack" object, which would hopefully address this concern. I would be happy to do that in a follow-up PR, because that work is largely independent of 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.

In the meantime, I've added some comments to the push_* functions about the order reversing.

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems reasonable for now. The subsequent refactoring does seem like another useful improvement.

We have a lot of stack-ish worklists, but this one is surprisingly critical to work that way to make it do the right thing.

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

LG, this seems like in a good state and a significant improvement over the state before. Good idea inline for a further refactoring.

out << ">";
}
out << "<associated ";
push_string(">");
Copy link
Contributor

Choose a reason for hiding this comment

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

That seems reasonable for now. The subsequent refactoring does seem like another useful improvement.

We have a lot of stack-ish worklists, but this one is surprisingly critical to work that way to make it do the right thing.

@josh11b josh11b added this pull request to the merge queue Nov 26, 2024
Merged via the queue into carbon-language:trunk with commit 01ea408 Nov 26, 2024
8 checks passed
@josh11b josh11b deleted the stringify branch November 26, 2024 02:09
bricknerb pushed a commit to bricknerb/carbon-lang that referenced this pull request Nov 28, 2024
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.

4 participants