Imported from Bugzilla
Reporter: Morgan Deters
Status: RESOLVED
Severity: review
Assigned to: Tim King
Component: {Internals} Expression package
Milestone: ---
Version: master
Platform: All
OS: All
On 2009-12-15 14:06:38 -0800, Morgan Deters wrote:
Code review of Morgan's and Dejan's code in src/expr.
On 2009-12-16 12:48:21 -0800, Tim King wrote:
****cvc4/src/expr/expr.h ****
Near L32, Expr();
Documentation does not specify the associated memory manager?
The documentation for the _@return value does not match the description of the function. For example:
/**
* Syntactic comparison operator. Returns true if expressions belong to the
* same expression manager and are syntactically identical.
* _@param e the expression to compare to
* _@return true if expressions are syntactically the same, false otherwise
*/
The description specifies that the expression manager must be the same, but the _@return value does not mention the expression manager.
Near L70, I'm not sure what this means:
"The only invariant on the order of expressions
* is that the expressions that were created sooner will be smaller in the
* ordering than all the expressions created later."
Near L100, std::string toString() const;
I added _@return value.
TODO: Where is the string representation specified?
Is this an SMT-lib expr? Presentation?
Near L113, bool isNull() const;
"Check if this is a null expression."
What does this mean? Should be defined here.
Near L117, ExprManager* getExprManager() const;
No _@return value.
Question: Expr iteExpr(const Expr& then_e, const Expr& else_e) const;
Is this type checked?
i.e. do we check that then_e and else_e are of the same type?
On 2009-12-16 13:00:15 -0800, Tim King wrote:
****cvc4/src/expr/expr.cpp****
Near L49, bool Expr::operator==(const Expr& e) const
On 2009-12-16 14:47:24 -0800, Tim King wrote:
****cvc4/src/expr/expr.cpp****
Near L49, bool Expr::operator==(const Expr& e) const
Refactored
Should probably have different names for the following 2 similar but different functions:
Expr BoolExpr::iteExpr(const Expr& then_e, const Expr& else_e) const {
BoolExpr BoolExpr::iteExpr(const BoolExpr& then_e, const BoolExpr& else_e) const {
****cvc4/src/expr/node.h****
Author of the file?
Near L16,
Why is this "#include "expr/node_value.h" before the "#ifndef" for the header file?
The documentation says "expression" everywhere.
Should we refactor "d_ev" to "d_nv"?
ALL of the following private methods need to be documented:
inline ev_iterator ev_begin();
inline ev_iterator ev_end();
inline const_ev_iterator ev_begin() const;
inline const_ev_iterator ev_end() const;
ALL of the following public methods need to be documented:
bool operator==(const Node& e) const { return d_ev == e.d_ev; }
bool operator!=(const Node& e) const { return d_ev != e.d_ev; }
Node& operator=(const Node&);
uint64_t hash() const;
Node eqExpr(const Node& right) const;
Node notExpr() const;
Node andExpr(const Node& right) const;
Node orExpr(const Node& right) const;
Node iteExpr(const Node& thenpart, const Node& elsepart) const;
Node iffExpr(const Node& right) const;
Node impExpr(const Node& right) const;
Node xorExpr(const Node& right) const;
Node plusExpr(const Node& right) const;
Node uMinusExpr() const;
Node multExpr(const Node& right) const;
inline Kind getKind() const;
inline size_t numChildren() const;
static Node null();
inline iterator begin();
inline iterator end();
inline const_iterator begin() const;
inline const_iterator end() const;
inline std::string toString() const;
inline void toStream(std::ostream&) const;
bool isNull() const;
**** cvc4/src/expr/node.cpp ****
I do not understand what is going on here. Good sign it should be documented.
NodeValue NodeValue::s_null;
Node Node::s_null(&NodeValue::s_null);
Node Node::null() {
return s_null;
}
Near L70, Node& Node::operator=(const Node& e) {
Does not assert that e.d_ev is not null. But it this may be referenced.
Should it?
Near L70, added parenthesis,
if((this != &e) && (d_ev != e.d_ev)) {
**** cvc4/src/expr/node_value.h ****
NodeValue::node_iterator needs documentation
No clue what is going on in computeHash
return ( (hash << 3) | ((hash & 0xE000000000000000ull) >> 61) ) ^ ev->getId();
We do a shift-rotate 3 on hash and xor the lower 8 bits with the Id?
Again the public functions need to be documented.
Why do inc() and dec() return NodeValue*?
NodeValue* inc();
NodeValue* dec();
How are reverse iterators going to be used? Documentation? These seem to be used in the exact same way except -1 from begin() and end()
iterator rbegin();
iterator rend();
*** cvc4/src/expr/expr_manager.h ***
Changed the documentation for
Expr mkExpr(Kind kind, const Expr& child1, const Expr& child2);
Not sure what this means:
"No will be deallocated at this point,"
*** cvc4/src/expr/node_manager.h ***
Currently makes nodes using "Node mkExpr(Kind kind);" Little odd.
No documentation!
Large chunks are commented out.
*** cvc4/src/expr/node_manager.cpp ***
Node NodeManager::lookup(uint64_t hash, NodeValue* ev);
Does not assert that (ev != NULL)
Comment: Node builder notation is freaking weird.
return NodeBuilder<>(this, kind);
*** cvc4/src/expr/node_builder.h/cpp ***
These are messes. I am going to skip these as they seem to be in draft form.
*** cvc4/src/expr/attr_type.h***
Class does not meet coding guidelines: class Type_attr
Where is this typedef used? Is it nessecary?
typedef Type value_type;//Node?
*** cvc4/src/expr/attr_var_name.h***
No clue what is going on in this class.
On 2010-01-19 17:32:38 -0800, Tim King wrote:
Comments and questions will be relevant to revision 96 of cvc4.
Friendly SmtEngine:
Why is SmtEngine a friend class to Expr, ExprManager, (maybe more)?
Garbage collection of Exprs, Nodes, and NodeValue:
- ~Expr() calls "delete d_node;".
- This invokes turn calls ~Node.
- This calls NodeValue::dec().
- dec() currently has no garbage collecting done, i.e. "// FIXME gc"
The expression manager is currently not involved with any of this explicitly.
From group discussions, it sounds like ExprManager will need to be informed of what is getting killed.
For most Node and NodeValue's grabbing currentNM() and deleting will be fine, but when this chain originates from an Expr the ExprManager will need to be specified somehow.
More documentation is needed near for public methods:
node_value.h::L122 "class node_iterator {..."
node_value.h::L158-L168
node_manager.h
node_builder.h
More documentation for s_null would be nice in node.cpp . I am a bit confused.
In node_manager.cpp the function
"NodeValue* NodeManager::lookupNoInsert(uint64_t hash, NodeValue* ev) {"
does a "return NULL;" near L76 and a "return 0;" near L103.
In node_manager.cpp's "lookup" and "lookupNoInsert" c2 appears to be used the same as c1 yet one is a const_ev_iterator and one is an ev_iterator. Is there a reason for this?
Test cases will be forthcoming.
On 2010-01-25 12:55:58 -0800, Tim King wrote:
Do we really want to have the following be part of Node? Seems like they are theory specific and not always well defined.
Node plusExpr(const Node& right) const;
Node uMinusExpr() const;
Node multExpr(const Node& right) const;
What are the advantages and disadvantages of including them here?
Needs to be documented. I am not sure the syntax for this is obvious.
Node iteExpr(const Node& thenpart, const Node& elsepart) const;
On 2010-01-25 15:35:19 -0800, Tim King wrote:
In order to black box test a good chunk of "class Node", NodeManager::currentNM() *MUST* be set. It is used implicitly by just about every function in this class.
I need a way to set the NodeManager. Directly setting NodeManager::s_current from NodeBlack is not possible because it is private. And making the black box unit tester a friend class to NodeManager feels icky.
Ideas?
On 2010-01-27 13:06:32 -0800, Tim King wrote:
The following do not appear to be defined in node.h or node.cpp:
Node plusExpr(const Node& right) const;
Node uMinusExpr() const;
Node multExpr(const Node& right) const;
I can't find there definition with grep either.
On 2010-02-01 14:30:04 -0800, Dejan Jovanovic wrote:
Am I missing something, or is the implementation of the hash table for expressions (NodeManager) completely unnecessary. What's wrong with using a standard STL hash_map?
On 2010-02-11 19:05:02 -0800, Dejan Jovanovic wrote:
Tim, I'm guessing you wrote the black-box tests for the expr package.
You are using debug assertions to check out of bounds indexing is caught. Unfortunately, this causes a segfault in optimized mode, since assertions are off. This particular assertion we don't want to have as always-assert, so you should either remove the case, or enclose it in some sort of IF_DEBUG block.
All the unit/regress tests should always pass both in debug and optimized mode.
On 2010-02-19 16:03:00 -0800, Tim King wrote:
Just a reminder that node_builder.h has large chunks explicitly commented out as well as a large chunk of code that is removed by the C preprocessor.
#if 0
....
#endif
On 2010-02-21 22:33:12 -0800, Morgan Deters wrote:
(In reply to comment # 9)
Tim, I'm guessing you wrote the black-box tests for the expr package.
You are using debug assertions to check out of bounds indexing is caught.
Unfortunately, this causes a segfault in optimized mode, since assertions are
off. This particular assertion we don't want to have as always-assert, so you
should either remove the case, or enclose it in some sort of IF_DEBUG block.
All the unit/regress tests should always pass both in debug and optimized mode.
I fixed this as part of my check-in from today (since I needed to push through other tests whose behavior is necessarily dependent on whether the code has assertions enabled or not).