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

Move IRUtils Literal get functions to the respective IR members. Add stringliteral get function. #4623

Merged
merged 6 commits into from
May 6, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Apr 17, 2024

I have been doing this a lot lately, so might as well contribute a utility function. Maybe all of these "get" functions should be static class members?

@fruffy fruffy added p4tools Topics related to the P4Tools back end core Topics concerning the core segments of the compiler (frontend, midend, parser) labels Apr 17, 2024
@vlstill
Copy link
Contributor

vlstill commented Apr 17, 2024

Maybe all of these "get" functions should be static class members?

Do you mean e.g. IR::StringLiteral::get?

@fruffy
Copy link
Collaborator Author

fruffy commented Apr 17, 2024

Maybe all of these "get" functions should be static class members?

Do you mean e.g. IR::StringLiteral::get?

Yes, something in that form.

@vlstill
Copy link
Contributor

vlstill commented Apr 19, 2024

Maybe all of these "get" functions should be static class members?

Do you mean e.g. IR::StringLiteral::get?

Yes, something in that form.

OK, I think that would make more sense than the freestanding functions.

@fruffy fruffy marked this pull request as ready for review April 23, 2024 01:31
@fruffy
Copy link
Collaborator Author

fruffy commented Apr 23, 2024

Maybe all of these "get" functions should be static class members?

Do you mean e.g. IR::StringLiteral::get?

Yes, something in that form.

OK, I think that would make more sense than the freestanding functions.

Alright, gave this a shot. There is probably more utils we could add.

ir/expression.def Outdated Show resolved Hide resolved
@fruffy fruffy changed the title Add a getStringLiteral utility function to irutils. Move irutils Literal get functions to the respective IR members. Add stringliteral get function. Apr 23, 2024
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

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

I think there is a problem when caching values that can have valid source info. Either we cannot cache these at all, or we would need the cache to take the source info into account (but then it is unlikely it would hit). Otherwise, we risk breaking error messages because the programmer will believe that the source info is there, but it won't (or it will be wrong one!). I wonder if the cache makes sense at all. Maybe in testgen it could...

I do realize this is not new in the PR. But since you have changed this code and likely intend to use it more widely, I suggest this is fixed now.

ir/expression.def Show resolved Hide resolved
ir/expression.cpp Outdated Show resolved Hide resolved
ir/expression.cpp Outdated Show resolved Hide resolved
ir/expression.cpp Show resolved Hide resolved
@fruffy fruffy force-pushed the fruffy/stringliteral branch 3 times, most recently from 51cef18 to 3acde1b Compare April 27, 2024 17:24
@vlstill vlstill dismissed their stale review April 30, 2024 07:17

my blocking issues now resolved

@fruffy fruffy requested review from vlstill and ChrisDodd May 5, 2024 21:15
@fruffy fruffy changed the title Move irutils Literal get functions to the respective IR members. Add stringliteral get function. Move IRUtils Literal ::get functions to the respective IR members. Add stringliteral get function. May 6, 2024
@fruffy fruffy changed the title Move IRUtils Literal ::get functions to the respective IR members. Add stringliteral get function. Move IRUtils Literal get functions to the respective IR members. Add stringliteral get function. May 6, 2024
@fruffy fruffy enabled auto-merge May 6, 2024 12:48
@fruffy fruffy added this pull request to the merge queue May 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 6, 2024
@fruffy fruffy added this pull request to the merge queue May 6, 2024
@fruffy fruffy removed this pull request from the merge queue due to a manual request May 6, 2024
@fruffy fruffy added this pull request to the merge queue May 6, 2024
Merged via the queue into main with commit 1583086 May 6, 2024
16 of 17 checks passed
@fruffy fruffy deleted the fruffy/stringliteral branch May 6, 2024 16:24
@@ -11,6 +11,8 @@
#include <tuple>
#include <type_traits>

#include "lib/big_int_util.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it would make sense to reverse the dependency and instantiate hasher inside lib/big_int_util.h? Right now it seems that everyone who'd like to use lib/hash.h would pull big_int_util.h, this seems to be not quite a good thing to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

big_int_util is mostly used for the declaration of big_int, which is used fairly pervasively in the compiler. We can split that out?

Copy link
Contributor

@asl asl May 8, 2024

Choose a reason for hiding this comment

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

Right. But why does it become the hash dependency? It seems it should be the opposite: big_int_utils should depend on hash and not vice versa. To make it a bit more clear: why would #include lib/hash.h pull in the declaration of big_int?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I have a fix for that in #4655.

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) p4tools Topics related to the P4Tools back end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants