diff --git a/src/Amalgam/interpreter/Interpreter.cpp b/src/Amalgam/interpreter/Interpreter.cpp index f183f744..d00e8e39 100644 --- a/src/Amalgam/interpreter/Interpreter.cpp +++ b/src/Amalgam/interpreter/Interpreter.cpp @@ -893,6 +893,8 @@ void Interpreter::PopulatePerformanceCounters(PerformanceConstraints *perf_const if(perf_constraints == nullptr) return; + perf_constraints->constraintsExceeded = false; + //handle execution steps if(performanceConstraints != nullptr && performanceConstraints->ConstrainedExecutionSteps()) { @@ -909,6 +911,7 @@ void Interpreter::PopulatePerformanceCounters(PerformanceConstraints *perf_const { perf_constraints->maxNumExecutionSteps = 1; perf_constraints->curExecutionStep = 1; + perf_constraints->constraintsExceeded = true; } } @@ -928,6 +931,7 @@ void Interpreter::PopulatePerformanceCounters(PerformanceConstraints *perf_const else //out of resources, ensure nothing will run (can't use 0 for maxNumAllocatedNodes) { perf_constraints->maxNumAllocatedNodes = 1; + perf_constraints->constraintsExceeded = true; } } @@ -958,6 +962,7 @@ void Interpreter::PopulatePerformanceCounters(PerformanceConstraints *perf_const else //out of resources, ensure nothing will run (can't use 0 for maxOpcodeExecutionDepth) { perf_constraints->maxOpcodeExecutionDepth = 1; + perf_constraints->constraintsExceeded = true; } } @@ -983,9 +988,14 @@ void Interpreter::PopulatePerformanceCounters(PerformanceConstraints *perf_const erbr.Clear(); if(container_total_entities >= performanceConstraints->maxContainedEntities) + { max_entities = 0; + perf_constraints->constraintsExceeded = true; + } else + { max_entities = performanceConstraints->maxContainedEntities - (container_total_entities - contained_total_entities); + } } perf_constraints->maxContainedEntities = std::min(perf_constraints->maxContainedEntities, max_entities); @@ -1007,10 +1017,15 @@ void Interpreter::PopulatePerformanceCounters(PerformanceConstraints *perf_const } if(cur_depth >= max_depth) + { perf_constraints->maxContainedEntityDepth = 0; + perf_constraints->constraintsExceeded = true; + } else + { perf_constraints->maxContainedEntityDepth = std::min(perf_constraints->maxContainedEntityDepth, max_depth - cur_depth); + } } if(performanceConstraints != nullptr && performanceConstraints->maxEntityIdLength > 0) diff --git a/src/Amalgam/interpreter/Interpreter.h b/src/Amalgam/interpreter/Interpreter.h index 9654d022..7a0b1fcd 100644 --- a/src/Amalgam/interpreter/Interpreter.h +++ b/src/Amalgam/interpreter/Interpreter.h @@ -129,6 +129,9 @@ class PerformanceConstraints //constrains the maximum length of an entity id (primarily to make sure it doesn't cause problems for file systems) //If 0, then unlimited size_t maxEntityIdLength; + + //flag set to true if constraints have been exceeded + bool constraintsExceeded; }; class Interpreter @@ -1021,23 +1024,33 @@ class Interpreter performanceConstraints->curExecutionStep++; if(performanceConstraints->curExecutionStep > performanceConstraints->maxNumExecutionSteps) + { + performanceConstraints->constraintsExceeded = true; return true; + } } if(performanceConstraints->ConstrainedAllocatedNodes()) { size_t cur_allocated_nodes = performanceConstraints->curNumAllocatedNodesAllocatedToEntities + evaluableNodeManager->GetNumberOfUsedNodes(); if(cur_allocated_nodes > performanceConstraints->maxNumAllocatedNodes) + { + performanceConstraints->constraintsExceeded = true; return true; + } } if(performanceConstraints->ConstrainedOpcodeExecutionDepth()) { if(opcodeStackNodes->size() > performanceConstraints->maxOpcodeExecutionDepth) + { + performanceConstraints->constraintsExceeded = true; return true; + } } - return false; + //return whether they have ever been exceeded + return performanceConstraints->constraintsExceeded; } //opcodes diff --git a/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp b/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp index 9794a273..ab634afc 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp @@ -569,9 +569,6 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CALL_SANDBOXED(EvaluableNo std::swap(memoryModificationLock, sandbox.memoryModificationLock); #endif - if(performanceConstraints != nullptr) - performanceConstraints->AccruePerformanceCounters(perf_constraints_ptr); - evaluableNodeManager->FreeNode(call_stack->GetOrderedChildNodesReference()[0]); evaluableNodeManager->FreeNode(call_stack); @@ -582,6 +579,12 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CALL_SANDBOXED(EvaluableNo if(_label_profiling_enabled && function->GetNumLabels() > 0) PerformanceProfiler::EndOperation(evaluableNodeManager->GetNumberOfUsedNodes()); + if(performanceConstraints != nullptr) + performanceConstraints->AccruePerformanceCounters(perf_constraints_ptr); + + if(perf_constraints_ptr != nullptr && perf_constraints_ptr->constraintsExceeded) + return EvaluableNodeReference::Null(); + return result; } diff --git a/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp b/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp index 6b49c866..2eeeda74 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp @@ -503,9 +503,6 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CALL_ENTITY_and_CALL_ENTIT #endif ); - if(performanceConstraints != nullptr) - performanceConstraints->AccruePerformanceCounters(perf_constraints_ptr); - ce_enm.FreeNode(call_stack->GetOrderedChildNodesReference()[0]); ce_enm.FreeNode(call_stack); @@ -546,6 +543,12 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CALL_ENTITY_and_CALL_ENTIT if(_label_profiling_enabled) PerformanceProfiler::EndOperation(evaluableNodeManager->GetNumberOfUsedNodes()); + if(performanceConstraints != nullptr) + performanceConstraints->AccruePerformanceCounters(perf_constraints_ptr); + + if(perf_constraints_ptr != nullptr && perf_constraints_ptr->constraintsExceeded) + return EvaluableNodeReference::Null(); + return result; } @@ -619,9 +622,6 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CALL_CONTAINER(EvaluableNo #endif ); - if(performanceConstraints != nullptr) - performanceConstraints->AccruePerformanceCounters(perf_constraints_ptr); - container->evaluableNodeManager.FreeNode(call_stack->GetOrderedChildNodesReference()[0]); container->evaluableNodeManager.FreeNode(call_stack); @@ -640,5 +640,11 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CALL_CONTAINER(EvaluableNo if(_label_profiling_enabled) PerformanceProfiler::EndOperation(evaluableNodeManager->GetNumberOfUsedNodes()); + if(performanceConstraints != nullptr) + performanceConstraints->AccruePerformanceCounters(perf_constraints_ptr); + + if(perf_constraints_ptr != nullptr && perf_constraints_ptr->constraintsExceeded) + return EvaluableNodeReference::Null(); + return copied_result; } diff --git a/src/Amalgam/out.txt b/src/Amalgam/out.txt index 1611ffcd..6e4e8f01 100644 --- a/src/Amalgam/out.txt +++ b/src/Amalgam/out.txt @@ -231,11 +231,11 @@ hello world: 12 and 2 (print "hello") [(null) (null) .infinity -.infinity] -{b 2 a 1 c ["alpha" "beta" "gamma"]} +{a 1 c ["alpha" "beta" "gamma"] b 2} { - b 2 a 1 c ["alpha" "beta" "gamma"] + b 2 } (apply "6") @@ -286,13 +286,11 @@ if 2 (null) 11 -(null) - +(null) 11 (null) 11 -(null) - +(null) (null) --while-- 1 @@ -635,7 +633,7 @@ abcdef 0.14384103622589045 --first-- 4 -2 +1 1 0 a @@ -651,18 +649,18 @@ a [1 2 3 4 5 6] [] { - a 1 + b 2 c 3 d 4 e 5 f 6 } -{d 4 f 6} +{b 2 d 4} { - a 1 + b 2 c 3 d 4 - f 6 + e 5 } { a 1 @@ -686,7 +684,7 @@ abcdef --last-- this -2 +1 1 0 c @@ -702,18 +700,18 @@ c [1 2 3 4 5 6] [] { - a 1 + b 2 c 3 d 4 e 5 f 6 } -{d 4 f 6} +{b 2 d 4} { - a 1 + b 2 c 3 d 4 - f 6 + e 5 } { a 1 @@ -1064,7 +1062,7 @@ abcdef [1 3] [9 5] --indices-- -["b" "4" "a" "c"] +["a" "c" "4" "b"] [ 0 1 @@ -1076,7 +1074,7 @@ abcdef 7 ] --values-- -[2 "d" 1 3] +[1 "d" 3 2] [ "a" 1 @@ -1097,7 +1095,7 @@ abcdef 4 "d" ] -[2 1 3 "d"] +[1 "d" 3 2] [ 1 2 @@ -1327,7 +1325,7 @@ current_index: 2 rmfile "del /s /q " rwww 1 slash "\\" - start_time 1729766223.550492 + start_time 1730137388.279071 www 1 x 12 zz 10 @@ -1373,7 +1371,7 @@ current_index: 2 rmfile "del /s /q " rwww 1 slash "\\" - start_time 1729766223.550492 + start_time 1730137388.279071 www 1 x 12 zz 10 @@ -1418,7 +1416,7 @@ current_index: 2 rmfile "del /s /q " rwww 1 slash "\\" - start_time 1729766223.550492 + start_time 1730137388.279071 www 1 x 12 zz 10 @@ -1551,22 +1549,22 @@ true --weighted_rand-- b -["b" "b" "b" "b"] +["a" "a" "a" "a"] b ["a" "b" @(get (target 2) 1) @(get (target 2) 1)] ["a" @(get (target 2) 0) @(get (target 2) 0) @(get (target 2) 0)] -infinity test c or d: ["c" "c" "c" "c"] +infinity test c or d: ["d" "d" "d" "d"] infinity test c or d: ["c" @(get (target 2) 0) @(get (target 2) 0) @(get (target 2) 0)] -{a 18 b 55 c 27} +{a 29 b 53 c 18} {a 25 b 50 c 25} -["1" "8" "3"] +["9" "3" "1"] --get_rand_seed-- ¶‡¨± ÎA)p1͉ÿ @@ -1612,8 +1610,8 @@ infinity test c or d: ["c" @(get (target 2) 0) @(get (target 2) 0) @(get (target string --set_type-- (- 3 4) -["b" 3 "a" 4] -["b" 3 "a" 4] +["a" 4 "b" 3] +["a" 4 "b" 3] {a 4 b 3} 8.7 (parallel @@ -1662,17 +1660,17 @@ string {a 3 b 4} {c "c"} ] -21: [{"b":4,"a":3},{"c":"c","d":null}] +21: [{"a":3,"b":4},{"c":"c","d":null}] 22: [{"a":3,"b":4},{"c":"c","d":null}] -23: b: 2 +23: a: 1 +c: 3 e: - a - b - - .inf -a: 1 -c: 3 d: 4 +b: 2 24: a: 1 b: 2 @@ -1685,7 +1683,7 @@ e: - .inf 25: {a 1} -current date-time in epoch: 2024-10-24-06.37.03.8694990 +current date-time in epoch: 2024-10-28-13.43.08.5455380 2020-06-07 00:22:59 1391230800 1391230800 @@ -1746,7 +1744,7 @@ domingo, jun. 07, 2020 ) } { - labelA #labelQ #labelA + labelA #labelA #labelQ (lambda #labelB (true) ) @@ -1760,7 +1758,7 @@ domingo, jun. 07, 2020 ) } { - labelA #labelQ #labelA + labelA #labelA #labelQ (lambda #labelB (true) ) @@ -2833,10 +2831,10 @@ MergeEntityChild1 (associate "x" 3 "y" 4) MergeEntityChild2 (associate "p" 3 "q" 4) -_1797215995 -(associate "e" 3 "f" 4) _2710920158 (associate "E" 3 "F" 4) +_1797215995 +(associate "e" 3 "f" 4) --union_entities-- (associate "b" 4 "a" 3 "c" 3) MergeEntityChild1 @@ -2854,26 +2852,26 @@ MergeEntityChild2 "w" 7 ) -_1797215995 +_2710920158 (associate - "e" + "E" 3 - "f" + "F" 4 - "g" + "G" 5 - "h" + "H" 6 ) -_2710920158 +_1797215995 (associate - "E" + "e" 3 - "F" + "f" 4 - "G" + "g" 5 - "H" + "h" 6 ) (parallel @@ -3453,8 +3451,14 @@ difference between DiffEntity2 and new_entity: [] (lambda { - E 3 - F 4 + E (get + (current_value 1) + "E" + ) + F (get + (current_value 1) + "F" + ) G 5 H 6 } @@ -3479,7 +3483,16 @@ difference between DiffEntity2 and new_entity: _ [] (lambda - {e 3 f 4} + { + e (get + (current_value 1) + "e" + ) + f (get + (current_value 1) + "f" + ) + } ) ) ) @@ -3505,7 +3518,89 @@ contained_entities new_entity: ["OnlyIn2" "_2860796594" "_2612373163" "DiffEntit difference between DiffContainer and DiffEntity2: (declare {_ (null) new_entity (null)} - (clone_entities _ new_entity) + (assign + "new_entity" + (first + (create_entities + new_entity + (call + (lambda + (declare + {_ (null)} + (replace _) + ) + ) + { + _ (retrieve_entity_root _) + } + ) + ) + ) + ) + (create_entities + (append new_entity "_2860796594") + (call + (lambda + (declare + {_ (null)} + (replace + _ + [] + (lambda + { + E (null) + F (null) + G (get + (current_value 1) + "G" + ) + H (get + (current_value 1) + "H" + ) + } + ) + ) + ) + ) + { + _ (retrieve_entity_root + (append _ "_2860796594") + ) + } + ) + ) + (create_entities + (append new_entity "_2612373163") + (call + (lambda + (declare + {_ (null)} + (replace + _ + [] + (lambda + {e (null) f (null)} + ) + ) + ) + ) + { + _ (retrieve_entity_root + (append _ "_2612373163") + ) + } + ) + ) + (clone_entities + (append _ "OnlyIn2") + (append new_entity "OnlyIn2") + ) + (clone_entities + (append _ "DiffEntityChild1") + (append new_entity "DiffEntityChild1") + ) + new_entity ) --mix_entities-- (associate "b" 4 "a" 3) @@ -3524,10 +3619,10 @@ MergeEntityChild2 "w" 7 ) -_1797215995 -(associate "e" 3 "f" 4 "h" 6) _2710920158 -(associate "E" 3 "F" 4 "G" 5) +(associate "E" 3 "F" 4 "H" 6) +_1797215995 +(associate "e" 3 "f" 4 "g" 5) --get_entity_comments-- Full test This is a suite of unit tests. @@ -3606,7 +3701,7 @@ deep sets --set_entity_root_permission-- RootTest -1729766224.040758 +1730137388.753984 (true) RootTest @@ -4445,14 +4540,14 @@ case conviction:{ } cyclic feature nearest neighbors: {cyclic1 1 cyclic5 0.5} cyclic test expected: 155, 200, 190 ... deg values of 0 8 and 12: -155: 0.1 (null - ##deg 0 +200: 0.05555555555555555 (null + ##deg 8 ) 190: 0.045454545454545456 (null ##deg 12 ) -200: 0.05555555555555555 (null - ##deg 8 +155: 0.1 (null + ##deg 0 ) --contains_label-- (true) @@ -4954,4 +5049,4 @@ rmdir /s /q amlg_code\persistent_tree_test_root del /s /q amlg_code\persist_module_test\psm.mdam del /s /q amlg_code\persist_module_test.mdam --total execution time-- -1.2825310230255127 +1.2715649604797363