-
Notifications
You must be signed in to change notification settings - Fork 285
Refinements to class_method_descriptor_exprt
#5145
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
Refinements to class_method_descriptor_exprt
#5145
Conversation
The class as stored in an `class_method_descriptor_exprt` is actually a unique identifier of the class in the symbol table. Therefore it makes sense to refer to it as a `class_id` rather than just as a name.
Because it is preferable to use the interface provided.
This is specifically the name of the method only. Not any other part of the expression.
The component to which a `class_method_descriptor_exprt` is referring to is specifically a particular overload of a method. The particular overload is distinguished based on a mangling process. Therefore `mangled_method_name` more accurately describes that this component is the the mangled name of a method, as opposed to any other kind of class component such as a field.
This makes it possible to find the code for constructing the identifier for a `class_method_descriptor_exprt` by looking at `class_method_descriptor_exprt` only. Where as previously it would have been neccessary to search for all places where the contructor was used.
To complete the documentation of each of the getters.
In order to ensure we an invalid expression is never constructed or cast to.
As the expresion is now checked on construction and casting, we no longer need check for its validity in the places where it is used.
92e1859 to
d2d7736
Compare
To complete the complete the documentation of the constructor.
allredj
left a comment
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 89d2d73).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/130227916
thk123
left a comment
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.
Couple of questions but lgtm. But the 💡 seems to be like a really strong improvement
| const irep_idt method_name = get_virtual_method_target( | ||
| instantiated_classes, call_basename, call_class, symbol_table); | ||
| CHECK_RETURN(!method_name.empty()); | ||
| const irep_idt &method_name = virtual_function.mangled_method_name(); |
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.
⛏️ keep one rename per commit in future
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.
❓ method_name and method_id is confusing as to what is the difference between them. Perhaps method_name and resolved_method_symbol_id?
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.
Would it be an improvement if I renamed the method_name variable to mangled_method_name?
smowton
left a comment
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.
One suggestion
| const irep_idt method_name = get_virtual_method_target( | ||
| instantiated_classes, call_basename, call_class, symbol_table); | ||
| CHECK_RETURN(!method_name.empty()); | ||
| const irep_idt &method_name = virtual_function.mangled_method_name(); |
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.
Might be easier if we used method_base_name and mangled_method_base_name, making it clear that neither includes the package/class qualifiers?
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.
To me, base_name means "not mangled". So mangled_method_base_name would read as a contradiction.
| } | ||
| }; | ||
|
|
||
| inline void validate_expr(const class class_method_descriptor_exprt &value) |
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 what the class keyword is doing here. Seems redundant?
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.
It isn't redundant. It is an inline forward declaration of the class_method_descriptor_exprt class. The forward declaration of this validate_expr function needs to be before the definition of the class_method_descriptor_exprt class because it is used from inside the classes constructor. The class also needs to be forward declared in order for the function forward declaration to be valid. So the two forward declarations break a cyclic dependency problem and can't be removed without either re-introducing the problem, or defining the constructor out of line instead of in-line. I could remove the keyword class from this line of code and put class class_method_descriptor_exprt; on the proceeding line, but this was a little more succinct.
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.
FWIW coding guidelines say forward declarations should be put at the top of the file with the includes
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.
Ah, I'll try and remember for next time.
This PR renames the components of
class_method_descriptor_exprt, in order to make their purpose clearer. The constructor of this class and its getters are documented and validation is added.The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/N/A (No user visible behaviour.)My commit message includes data points confirming performance improvements (if claimed).N/A (None claimed)