-
Notifications
You must be signed in to change notification settings - Fork 444
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
Promote P4
to be THE project-wise top-level namespace
#4825
Conversation
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
One thing to further discuss is whether we want the namespace to be My main reasons for preferring
If possible, I'd propose gradually converting all existing namespaces to the snake_case style. But I also understand this kind of refactoring might be too annoying to downstream projects that are currently depending on P4C as a library. So I'm insisting on this. I'll follow whatever decision the larger community comes to, and update this PR accordingly. |
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
I don't quite understand the macOS-specific compiling issue. Somehow it's confusing between |
@qobilidop Some things were already places in namespace As for namespace p4c {
...
std::cout << "boo" << std::endl;
...
}
I have not checked the diff, but likely you're having |
I always assumed the BTW. Should the namespace be |
It seems this breaks Then there are values like A workaround is to use |
Signed-off-by: Bili Dong <qobilidop@gmail.com>
I think I was already beaten by this before. We define lots of See the comment at Line 93 in 63c4071
|
I also had issues with this, it's hard to keep track of whats floating around. Any ideas on how to clean it up? |
get rid of boost::format :) Though the alternatives are not much better:
Let me play a bit with possible implementations here and there... |
@vlstill They are in |
Some thoughts are here: #4698 (comment) |
Any remaining issues that must be addressed in this PR? It seems all the identified issues could be addressed in follow-up PRs separately. |
I'd say most of the operators should be defined as close to the class as possible (and definitely in the same namespace). Since there is no good way to pull only some operators (except for namespaces), we should not define an For the cases where we really need to pull the operator for a special purpose, I could see defining something like namespace P4::Dbg { // or P4::Log
... operator<<(..., IR::Node *) { ... }
// all the weird operators that should not work normally
// ...
} and then we could modify our logging macros to be something like: #define LOGN(N, X) \
[&]{ \
using P4::Log::operator<<; \
if (LOGGING(N)) \
return ::Log::Detail::fileLogOutput(__FILE__) \
<< ::Log::Detail::OutputLogPrefix(__FILE__, N) << X \
<< ::Log::Detail::clearPrefix << std::endl \
return std::clog; \
}() This would need to be tested thoroughly though to make sure the lambda does not break anything (I've use a lambda instead of the This way we should get the operators available in logging, but not in normal printouts. |
+1
My idea was to introduce a special "debug logging stream. There we can overload |
Signed-off-by: Bili Dong <qobilidop@gmail.com>
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.
Applied this to a downstream backend the hard way (not with using namespace P4
). One weird problem I had was related to expressions like ASSERT_EQ(...) << exprs
where exprs
is a vector of things that have dbpring
. In this case I had to add using P4::operator<<
before the gtest-related includes so that the gtest's stream can see operator<<
overload that we have for vector
(and which we probably should not really have).
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Great, thanks for the heavy lifting here! |
The context is #4707.
Since this refactoring touches almost every C++ (and some non-C++) file, I tried to make the diffs as minimal as possible, to reduce the possibility of breaking things by accident. As a result, there is still much room in improving coding styles.
Details of major changes applied:
P4
, likenamespace IR
, replace them globally to benamespace P4::IR
.namespace P4
manually.::error
, replace them globally to be::P4::error
.using namespace ::P4;
as we see fit.The rest are minor changes to make the code compile without errors.