-
Notifications
You must be signed in to change notification settings - Fork 274
Refactoring around the goto-cc entry point. #5442
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
Refactoring around the goto-cc entry point. #5442
Conversation
95a56d9
to
49e9b69
Compare
src/goto-cc/armcc_cmdline.cpp
Outdated
@@ -265,6 +265,21 @@ static const char *options_with_arg[]= | |||
nullptr | |||
}; | |||
|
|||
static bool | |||
prefix_in_list(const char *option, const char **list, std::string &prefix) |
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.
I think we could simplify a lot of this if we stored the args in the mode as std::vector<std::string>
instead of char **
. Then we could also just use regular std::find
or something like that instead of 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.
That sounds like a good follow up refactoring.
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.
src/goto-cc/armcc_cmdline.cpp
Outdated
@@ -14,6 +14,8 @@ Author: Daniel Kroening | |||
#include <cstring> | |||
#include <iostream> | |||
|
|||
#include "optional.h" |
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.
should be <util/optional.h>
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.
Fixed.
src/goto-cc/armcc_cmdline.cpp
Outdated
@@ -265,19 +267,18 @@ static const char *options_with_arg[]= | |||
nullptr | |||
}; | |||
|
|||
static bool | |||
prefix_in_list(const char *option, const char **list, std::string &prefix) | |||
static optionalt<std::string> |
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.
Like I said above, I'd prefer not touching this like this for now and instead changing how we store command line arguments, then we don't have to invent our own finds at all.
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.
Yes, I think that using a standard container would be a great follow-up refactoring. However I would argue that removing the need for an output parameter is already a step in the right direction, which makes the usages of this function more readable.
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.
@@ -117,3 +117,13 @@ void goto_cc_cmdlinet::add_infile_arg(const std::string &arg) | |||
fclose(tmp); | |||
} | |||
} | |||
|
|||
bool goto_cc_cmdlinet::have_infile_arg() const |
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.
I think we should probably just make sure to put definitions in cpp files in general.
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.
👍
src/util/bv_encoding.h
Outdated
|
||
Author: Diffblue Ltd | ||
|
||
\*******************************************************************/ |
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.
I think I mentioned this before but we want to move away from this style of module header... we might have to adjust our linter for that though.
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.
I have removed this commit from this PR.
src/util/bv_encoding.h
Outdated
|
||
#include <cstddef> | ||
|
||
struct bv_encodingt |
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.
Moves it into a different namespace though
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.
Ok. I'll leave it where it was then.
src/util/bv_encoding.h
Outdated
@@ -11,7 +11,7 @@ Author: Diffblue Ltd | |||
|
|||
#include <cstddef> | |||
|
|||
struct bv_encodingt | |||
struct bv_encodingt final |
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.
I'm not sure that's necessary, I find final
to be a bit noisy. To me final
actually suggests the opposite of what you're saying here: This is part of a class hierarchy, it's just supposed to be at the bottom of it.
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.
You know that isn't part of a hierarchy from reading this line of code, because no base classes are specified. Having it specified as final
also means that you are always safe to pass / return / assign instances of this class by value, without risk of slicing occurring. I do take your point about noise however. I think I may drop this commit as I don't really want to include anything in this PR, where the pros and cons could be argued either way. Suffice to say that my current habit is to make new classes/structs final
by default, in the same way as I would make variables and member functions const
by default.
src/util/bv_encoding.cpp
Outdated
const std::string &argument, | ||
const std::size_t pointer_width) | ||
{ | ||
const unsigned int object_bits = unsafe_string2unsigned(argument); |
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.
Use string2optional
here so you can handle a parse error with a proper error message. The unsafe_
functions are for when you know the parse will succeed.
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.
Yep. A non-integer argument will cause an invariant violation, both before and after this PR. This is expected as the PR is intended to be refactoring only, not bug fixing. I agree that we should improve the error handling here.
Making this member function non-virtual makes it easier to follow the control flow because it is clear it not overridden in any sub class. This is should be easy enough to add back should a need to override this arise.
Putting implementations in `.cpp` files is the best-practise because it reduces compile times.
This avoids the need to declare and mutate iterators. Its states what it is doing by means of the name of the algorithm - `std::any_of`, which saves on reading a loop to work it out.
Making this member function non-virtual makes it easier to follow the control flow because it is clear it not overridden in any sub class. This is should be easy enough to add back should a need to override this arise.
This makes the `goto_cc_cmdlinet` class easier to follow because it can be read without seeing this special case for `armcc`.
This avoids using an output parameter, which makes it more straight forward to read the data flow.
49e9b69
to
c562025
Compare
object-bits
argument.Because this gives us compatability with modern C++ features such as ranged for loops and the algorithms in the standard template library. Because using a standard container rather than a null terminated array improves memory safety. Clang format is off for the lists of options in order to keep the existing manual formatting. This existing formatting is consistent with the other lists of options.
c562025
to
53d609d
Compare
1f3710f
to
feacb93
Compare
unit/goto-cc/armcc_cmdline.cpp
Outdated
@@ -0,0 +1,32 @@ | |||
// Copyright 2020 Diffblue Limited. All Rights Reserved. |
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.
I think the licence header is wrong - thats the internal Diffblue header - CBMC contributions require a different header.
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.
All looks good apart from the copyright header - happy to approve once that is fixed up.
To demonstrate that the refactored version works as expected.
feacb93
to
f7787c8
Compare
As I was working on #5440, I found the entry point code less than straight forward to follow. I carried out this refactorings locally in order to make it easier for me to understand. I am raising this separate PR containing the refactoring work only as it was not required in order to implement the feature in the original PR, but should still improve maintainability.
The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/My commit message includes data points confirming performance improvements (if claimed).