Skip to content

Commit

Permalink
21079: Fixes issue with weave opcode uniqueness checks and adds more …
Browse files Browse the repository at this point in the history
…debugging (#202)
  • Loading branch information
howsohazard authored Jul 27, 2024
1 parent 189433c commit a89223c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Amalgam/AmalgamMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ PLATFORM_MAIN_CONSOLE

if(debug_internal_memory)
{
entity->VerifyEvaluableNodeIntegrityAndAllContainedEntities();

delete entity;

auto num_strings_used = string_intern_pool.GetNumDynamicStringsInUse();
Expand Down
7 changes: 7 additions & 0 deletions src/Amalgam/entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,3 +999,10 @@ void Entity::VerifyEvaluableNodeIntegrity()
for(auto &[en, _] : nr.nodesReferenced)
EvaluableNodeManager::ValidateEvaluableNodeTreeMemoryIntegrity(en);
}

void Entity::VerifyEvaluableNodeIntegrityAndAllContainedEntities()
{
VerifyEvaluableNodeIntegrity();
for(auto ce : GetContainedEntities())
ce->VerifyEvaluableNodeIntegrity();
}
3 changes: 3 additions & 0 deletions src/Amalgam/entity/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@ class Entity
//ensures that there are no reachable nodes that are deallocated
void VerifyEvaluableNodeIntegrity();

//like VerifyEvaluableNodeIntegrity but includes all contained
void VerifyEvaluableNodeIntegrityAndAllContainedEntities();

//this is an estimate of the number of nodes required to reconstruct the entity if it were flattened
// including amortization of all extra overhead
static inline size_t GetEntityCreationSizeInNodes()
Expand Down
4 changes: 4 additions & 0 deletions src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ void EvaluableNodeManager::FreeNodeTreeRecurse(EvaluableNode *tree)
}
}

#ifdef AMALGAM_FAST_MEMORY_INTEGRITY
assert(!tree->GetNeedCycleCheck());
#endif

tree->Invalidate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,18 +634,21 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_WEAVE(EvaluableNode *en, b
//find the largest of all the lists and the total number of elements
size_t maximum_list_size = 0;
size_t total_num_elements = 0;
bool all_lists_unique = true;
for(auto &list : lists)
{
if(list != nullptr)
{
size_t num_elements = list->GetOrderedChildNodes().size();
maximum_list_size = std::max(maximum_list_size, num_elements);
total_num_elements += num_elements;

all_lists_unique &= list.unique;
}
}

//the result
EvaluableNodeReference woven_list(evaluableNodeManager->AllocNode(ENT_LIST), true);
EvaluableNodeReference woven_list(evaluableNodeManager->AllocNode(ENT_LIST), all_lists_unique);

//just lists, interleave
if(EvaluableNode::IsNull(function))
Expand Down

0 comments on commit a89223c

Please sign in to comment.