@@ -1319,12 +1319,12 @@ def evaluate(self, evaluation) -> typing.Union["Expression", "Symbol"]:
13191319 # of a branch. Once it is set to false, the result is not cached,
13201320 # and hence, not used.
13211321 if evaluation .cache_result :
1322- expr_hash = self .__hash__ ()
1322+ expr_hash = str ( self .__hash__ () )
13231323 else :
13241324 expr_hash = None
13251325
13261326 if expr_hash :
1327- cache_expr_result = evaluation .cache_eval .get (expr_hash , None )
1327+ cache_expr_result = evaluation .definitions . cache_eval .get (expr_hash , None )
13281328 if cache_expr_result is not None :
13291329 expr = cache_expr_result [0 ]
13301330 if not expr .has_changed (definitions ):
@@ -1342,7 +1342,6 @@ def evaluate(self, evaluation) -> typing.Union["Expression", "Symbol"]:
13421342
13431343 if hasattr (expr , "options" ) and expr .options :
13441344 evaluation .options = expr .options
1345-
13461345 expr , reevaluate = expr .evaluate_next (evaluation )
13471346 if not reevaluate :
13481347 break
@@ -1372,7 +1371,8 @@ def evaluate(self, evaluation) -> typing.Union["Expression", "Symbol"]:
13721371 evaluation .dec_recursion_depth ()
13731372
13741373 if evaluation .cache_result :
1375- evaluation .cache_eval [expr_hash ] = (self , expr )
1374+ self ._timestamp_cache (evaluation )
1375+ evaluation .definitions .cache_eval [expr_hash ] = (self , expr )
13761376 return expr
13771377
13781378 def evaluate_next (self , evaluation ) -> typing .Tuple ["Expression" , bool ]:
@@ -1426,7 +1426,6 @@ def eval_range(indices):
14261426 evaluation .cache_result = up_cache_result
14271427
14281428 # rest_range(range(0, 0))
1429-
14301429 new = Expression (head )
14311430 new ._leaves = tuple (leaves )
14321431
@@ -1497,7 +1496,7 @@ def rules():
14971496 for rule in rules ():
14981497 result = rule .apply (new , evaluation , fully = False )
14991498 if result is not None :
1500- evaluation .cache_result = cache_result
1499+ evaluation .cache_result = cache_result and evaluation . cache_result
15011500 if isinstance (result , BoxConstruct ):
15021501 return result , False
15031502 if result .sameQ (new ):
@@ -1522,6 +1521,7 @@ def rules():
15221521 new .unformatted = self .unformatted
15231522 new ._timestamp_cache (evaluation )
15241523 evaluation .cache_result = cache_result
1524+
15251525 return new , False
15261526
15271527 def evaluate_leaves (self , evaluation ) -> "Expression" :
@@ -1531,7 +1531,7 @@ def evaluate_leaves(self, evaluation) -> "Expression":
15311531 for leaf in self ._leaves :
15321532 leaves .append (leaf .evaluate (evaluation ))
15331533 cache_result = cache_result and evaluation .cache_result
1534- evaluation .cache_result = up_cache_result
1534+ evaluation .cache_result = up_cache_result
15351535 head = self ._head .evaluate_leaves (evaluation )
15361536 evaluation .cache_result = cache_result and evaluation .cache_result
15371537 return Expression (head , * leaves )
0 commit comments