summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher L. Conway <christopherleeconway@gmail.com>2010-10-28 20:05:32 +0000
committerChristopher L. Conway <christopherleeconway@gmail.com>2010-10-28 20:05:32 +0000
commitc39254b98c010397fa5b2da9513d7b3451d682d7 (patch)
tree010f3f640a621b51fc6b8739a17a88780e14ac19
parent61cff4d656a292c6138be5e08715cadd28e22b03 (diff)
Disabling bottom-up algorithm in NodeManager::getType() when type checking
is not requested or eager type checking is enabled
-rw-r--r--src/expr/node_manager.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp
index 2f5ba6824..5fc704cbc 100644
--- a/src/expr/node_manager.cpp
+++ b/src/expr/node_manager.cpp
@@ -424,23 +424,20 @@ TypeNode NodeManager::getType(TNode n, bool check)
bool needsCheck = check && !getAttribute(n, TypeCheckedAttr());
Debug("getType") << "getting type for " << n << std::endl;
- if(!hasType || needsCheck) {
- // TypeNode oldType = typeNode;
+ if(needsCheck && !d_earlyTypeChecking) {
+ /* Iterate and compute the children bottom up. This avoids stack
+ overflows in computeType() when the Node graph is really deep,
+ which should only affect us when we're type checking lazily. */
stack<TNode> worklist;
worklist.push(n);
- /* Iterate and compute the children bottom up. This avoids stack
- overflows in computeType() when the Node graph is really
- deep. */
while( !worklist.empty() ) {
TNode m = worklist.top();
bool readyToCompute = true;
- for( TNode::iterator it = m.begin(), end = m.end() ;
- it != end;
- ++it ) {
+ for( TNode::iterator it = m.begin(), end = m.end() ; it != end; ++it ) {
if( !hasAttribute(*it, TypeAttr())
|| (check && !getAttribute(*it, TypeCheckedAttr())) ) {
readyToCompute = false;
@@ -450,22 +447,24 @@ TypeNode NodeManager::getType(TNode n, bool check)
if( readyToCompute ) {
/* All the children have types, time to compute */
- computeType(m,check);
+ typeNode = computeType(m,check);
worklist.pop();
}
- }
-
- /* Retrieve the type computed in the loop */
- hasType = getAttribute(n, TypeAttr(), typeNode);
+ } // end while
+
+ /* Last type computed in loop should be the type of n */
+ Assert( typeNode == getAttribute(n,TypeAttr()) );
+ } else if( !hasType || needsCheck ) {
+ /* We can compute the type top-down, without worrying about
+ deep recursion. */
+ typeNode = computeType(n,check);
+ }
- /* Type should be there and the check should have happened if we
- asked for it. */
- Assert( hasType );
- Assert( !check || hasAttribute(n, TypeCheckedAttr()) );
+ /* The type should be have been computed and stored. */
+ Assert( hasAttribute(n, TypeAttr()) );
+ /* The check should have happened, if we asked for it. */
+ Assert( !check || hasAttribute(n, TypeCheckedAttr()) );
- // DebugAssert( !hasType || oldType == typeNode,
- // "Type re-computation yielded a different type" );
- }
Debug("getType") << "type of " << n << " is " << typeNode << std::endl;
return typeNode;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback